Skip to content

Commit

Permalink
Fix dependency version for derived crates
Browse files Browse the repository at this point in the history
    - Add nodejs tests
    - Remove bench tests
  • Loading branch information
dmarteau committed Oct 14, 2024
1 parent 4fdc72f commit 6ab1f4f
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 85 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
members = [
"proj4rs",
"proj4rs-clib",
"proj4rs-php",
"proj4rs-php",
]
resolver = "2"

Expand All @@ -23,6 +23,6 @@ strip = "debuginfo"

[patch.crates-io]
# Use local crates
proj4rs = { path = "proj4rs" }
proj4rs = { path = "./proj4rs" }


2 changes: 1 addition & 1 deletion js/.docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# syntax=docker/dockerfile:1
FROM node:19-bullseye-slim
FROM node:22-bookworm-slim

3 changes: 3 additions & 0 deletions js/tests/nodejs/proj4rs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Statements to load wasm module in nodejs REPL
let Proj
import("../../pkg-node/proj4rs.js").then(module => { Proj = module });
Empty file added js/tests/nodejs/run_tests.js
Empty file.
23 changes: 23 additions & 0 deletions js/tests/nodejs/test_core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
let Proj = await import("../../pkg-node/proj4rs.js");

function test_core() {
//EPSG:3006
var sweref99tm = '+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs';
// EPSG:3021
var rt90 = '+lon_0=15.808277777799999 +lat_0=0.0 +k=1.0 +x_0=1500000.0 +y_0=0.0 +proj=tmerc +ellps=bessel +units=m +towgs84=414.1,41.3,603.1,-0.855,2.141,-7.023,0 +no_defs';
let from = new Proj.Projection(sweref99tm);
let to = new Proj.Projection(rt90);
let point = new Proj.Point(319180, 6399862, 0.0);
Proj.transform(from, to, point);
console.log(`=> ${point.x} ${point.y}`);

var epsg2154 = '+proj=lcc +lat_0=46.5 +lon_0=3 +lat_1=49 +lat_2=44 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +type=crs';
var epsg3857 = '+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs +type=crs';
from = new Proj.Projection(epsg2154);
to = new Proj.Projection(epsg3857);
point = new Proj.Point(489353.59, 6587552.2, 0.0);
Proj.transform(from, to, point);
console.log(`=> ${point.x} ${point.y}`);
}

test_core();
2 changes: 1 addition & 1 deletion proj4rs-clib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ name = "proj4rs_c"
crate-type = ["cdylib"]

[dependencies]
proj4rs = "*"
proj4rs = "~0.1"
libc = { version = "0.2" }

[features]
Expand Down
4 changes: 2 additions & 2 deletions proj4rs-php/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ name = "proj4rs_php"
crate-type = ["cdylib"]

[dependencies]
proj4rs = "*"
ext-php-rs = "*"
proj4rs = "~0.1"
ext-php-rs = "0.12"
log = { version = "0.4", optional = true }

[features]
Expand Down
7 changes: 1 addition & 6 deletions proj4rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "proj4rs"
version = "0.1.5"
version = "0.1.6"
edition = "2021"
description = "Rust adaptation of Proj4"
readme = "../README.md"
Expand Down Expand Up @@ -31,7 +31,6 @@ log = { version = "0.4", optional = true }
[dev-dependencies]
approx = "0.5"
clap = { version = "4", features = ["derive"] }
criterion = { version = "0.5" }
env_logger = "0.11"
log = "0.4"

Expand Down Expand Up @@ -60,10 +59,6 @@ js-sys = "0.3"
web-sys = { version = "0.3", features = ["console"] }
console_log = "1.0"

[[bench]]
name = "bench_proj"
harness = false

[[example]]
name = "rsproj"

Expand Down
14 changes: 14 additions & 0 deletions proj4rs/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,17 @@ args = [
"--features=proj4js-compat",
]

[tasks.wasm_node]
description = "Build wasm package as nodejs bundle"
command = "wasm-pack"
args = [
"build",
"--out-dir=../js/pkg-node",
"--release",
"--target=nodejs",
"--no-default-features",
"--features=logging",
"--features=proj4js-compat",
"--features=with-wasm-entrypoint",
]

38 changes: 0 additions & 38 deletions proj4rs/benches/bench_proj.rs

This file was deleted.

43 changes: 8 additions & 35 deletions proj4rs/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//!
mod nadgrids;

use crate::{errors, proj, transform};
use crate::{errors, proj, transform, transform::TransformClosure};
use wasm_bindgen::prelude::*;

use crate::log;
Expand All @@ -14,6 +14,8 @@ use crate::log;
pub fn main() {
#[cfg(feature = "logging")]
console_log::init_with_level(log::Level::Trace).unwrap();

log::info!("Initialized proj4rs wasm module.")
}

// ----------------------------
Expand Down Expand Up @@ -74,9 +76,9 @@ impl Projection {
// ---------------------------
#[wasm_bindgen]
pub struct Point {
x: f64,
y: f64,
z: f64,
pub x: f64,
pub y: f64,
pub z: f64,
}

#[wasm_bindgen]
Expand All @@ -85,41 +87,14 @@ impl Point {
pub fn new(x: f64, y: f64, z: f64) -> Point {
Self { x, y, z }
}

#[wasm_bindgen(getter)]
pub fn x(&self) -> f64 {
self.x
}
#[wasm_bindgen(setter)]
pub fn set_x(&mut self, x: f64) {
self.x = x;
}
#[wasm_bindgen(getter)]
pub fn y(&self) -> f64 {
self.y
}
#[wasm_bindgen(setter)]
pub fn set_y(&mut self, y: f64) {
self.y = y;
}
#[wasm_bindgen(getter)]
pub fn z(&self) -> f64 {
self.z
}
#[wasm_bindgen(setter)]
pub fn set_z(&mut self, z: f64) {
self.z = z;
}
}

impl transform::Transform for Point {
/// Strict mode: return exception
/// as soon as with have invalid coordinates or
/// that the reprojection failed
#[cfg(feature = "wasm-strict")]
fn transform_coordinates<F>(&mut self, f: &mut F) -> errors::Result<()>
where
F: FnMut(f64, f64, f64) -> errors::Result<(f64, f64, f64)>,
fn transform_coordinates<F: TransformClosure>(&mut self, f: &mut F) -> errors::Result<()>
{
f(self.x, self.y, self.z).map(|(x, y, z)| {
self.x = x;
Expand All @@ -131,9 +106,7 @@ impl transform::Transform for Point {
/// of projection failure
/// Note: this is what is expected mostly from js app (at least OpenLayer)
#[cfg(not(feature = "wasm-strict"))]
fn transform_coordinates<F>(&mut self, f: &mut F) -> errors::Result<()>
where
F: FnMut(f64, f64, f64) -> errors::Result<(f64, f64, f64)>,
fn transform_coordinates<F: TransformClosure>(&mut self, f: &mut F) -> errors::Result<()>
{
f(self.x, self.y, self.z)
.map(|(x, y, z)| {
Expand Down

0 comments on commit 6ab1f4f

Please sign in to comment.