Skip to content

Commit

Permalink
Replace mutable z api with separate constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
msvbg committed Aug 28, 2024
1 parent 6f8e47b commit 4e4f71a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ usingz = ["clipper2c-sys/usingz"]

[dependencies]
libc = "0.2"
clipper2c-sys = "0.1.4"
clipper2c-sys = { path = "../clipper2c-sys" }
thiserror = "1.0.59"
serde = { version = "1", features = ["derive"], optional = true }

Expand All @@ -34,4 +34,4 @@ serde_json = "1"
features = ["doc-images"]

[patch.crates-io]
clipper2c-sys = { rev = "210878394637f94bcd3a476bdf24ddf4ba8a39fd", git = "https://github.com/tirithen/clipper2c-sys" }
# clipper2c-sys = { rev = "210878394637f94bcd3a476bdf24ddf4ba8a39fd", git = "https://github.com/tirithen/clipper2c-sys" }
19 changes: 13 additions & 6 deletions src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ impl<P: PointScaler> Point<P> {
)
}

#[cfg(feature = "usingz")]
/// Create a new point with user data.
pub fn new_with_z(x: f64, y: f64, z: i64) -> Self {
Self(
ClipperPoint64 {
x: P::scale(x) as i64,
y: P::scale(y) as i64,
z,
},
PhantomData,
)
}

/// Create a new point from scaled values, this means that point is
/// constructed as is without applying the scaling multiplier.
pub fn from_scaled(x: i64, y: i64) -> Self {
Expand Down Expand Up @@ -201,12 +214,6 @@ impl<P: PointScaler> Point<P> {
pub fn z(&self) -> i64 {
self.0.z
}

#[cfg(feature = "usingz")]
/// Sets the user data of the point.
pub fn set_z(&mut self, z: i64) {
self.0.z = z;
}
}

impl<P: PointScaler> Default for Point<P> {
Expand Down

0 comments on commit 4e4f71a

Please sign in to comment.