#![warn(missing_docs)]
#![warn(clippy::all)]
#![deny(clippy::unwrap_used)]
#![allow(clippy::module_name_repetitions)]
mod algorithms;
mod async_ops;
mod buffer;
mod error;
mod raster;
mod vector;
use napi_derive::napi;
#[napi]
pub fn version() -> String {
oxigdal_core::VERSION.to_string()
}
#[napi]
pub fn name() -> String {
"OxiGDAL Node.js Bindings".to_string()
}
#[napi(object)]
pub struct ModuleInfo {
pub version: String,
pub name: String,
pub build_info: String,
pub formats: Vec<String>,
}
#[napi]
pub fn get_info() -> ModuleInfo {
ModuleInfo {
version: oxigdal_core::VERSION.to_string(),
name: "OxiGDAL Node.js Bindings".to_string(),
build_info: format!(
"Built with Rust {} on {}",
env!("CARGO_PKG_RUST_VERSION"),
std::env::consts::OS
),
formats: vec![
"GeoTIFF".to_string(),
"COG".to_string(),
"GeoJSON".to_string(),
],
}
}
#[napi(object)]
pub struct DataTypes {
pub uint8: String,
pub int16: String,
pub uint16: String,
pub int32: String,
pub uint32: String,
pub float32: String,
pub float64: String,
}
#[napi]
pub fn get_data_types() -> DataTypes {
DataTypes {
uint8: "uint8".to_string(),
int16: "int16".to_string(),
uint16: "uint16".to_string(),
int32: "int32".to_string(),
uint32: "uint32".to_string(),
float32: "float32".to_string(),
float64: "float64".to_string(),
}
}
#[napi(object)]
pub struct ResamplingMethods {
pub nearest_neighbor: String,
pub bilinear: String,
pub bicubic: String,
pub lanczos: String,
}
#[napi]
pub fn get_resampling_methods() -> ResamplingMethods {
ResamplingMethods {
nearest_neighbor: "NearestNeighbor".to_string(),
bilinear: "Bilinear".to_string(),
bicubic: "Bicubic".to_string(),
lanczos: "Lanczos".to_string(),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_version() {
let ver = version();
assert!(!ver.is_empty());
}
#[test]
fn test_info() {
let info = get_info();
assert!(!info.version.is_empty());
assert!(!info.formats.is_empty());
}
#[test]
fn test_data_types() {
let types = get_data_types();
assert_eq!(types.uint8, "uint8");
assert_eq!(types.float32, "float32");
}
#[test]
fn test_data_types_all_fields() {
let types = get_data_types();
assert_eq!(types.uint8, "uint8");
assert_eq!(types.int16, "int16");
assert_eq!(types.uint16, "uint16");
assert_eq!(types.int32, "int32");
assert_eq!(types.uint32, "uint32");
assert_eq!(types.float32, "float32");
assert_eq!(types.float64, "float64");
}
#[test]
fn test_resampling_methods() {
let methods = get_resampling_methods();
assert_eq!(methods.nearest_neighbor, "NearestNeighbor");
assert_eq!(methods.bilinear, "Bilinear");
assert_eq!(methods.bicubic, "Bicubic");
assert_eq!(methods.lanczos, "Lanczos");
}
#[test]
fn test_module_info_name() {
let info = get_info();
assert!(info.name.contains("OxiGDAL"));
}
#[test]
fn test_module_info_formats_contain_geotiff() {
let info = get_info();
assert!(
info.formats
.iter()
.any(|f| f.contains("GeoTIFF") || f.contains("tiff") || f.contains("TIFF"))
);
}
#[test]
fn test_module_info_build_info_not_empty() {
let info = get_info();
assert!(!info.build_info.is_empty());
}
#[test]
fn test_name_function() {
let n = name();
assert!(!n.is_empty());
assert!(n.contains("OxiGDAL") || n.contains("Node"));
}
}