Skip to content

Commit 320fbea

Browse files
committed
Replace mutable z api with separate constructor
1 parent 6f8e47b commit 320fbea

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ usingz = ["clipper2c-sys/usingz"]
1919

2020
[dependencies]
2121
libc = "0.2"
22-
clipper2c-sys = "0.1.4"
22+
clipper2c-sys = { path = "../clipper2c-sys" }
2323
thiserror = "1.0.59"
2424
serde = { version = "1", features = ["derive"], optional = true }
2525

@@ -34,4 +34,4 @@ serde_json = "1"
3434
features = ["doc-images"]
3535

3636
[patch.crates-io]
37-
clipper2c-sys = { rev = "210878394637f94bcd3a476bdf24ddf4ba8a39fd", git = "https://github.com/tirithen/clipper2c-sys" }
37+
# clipper2c-sys = { rev = "210878394637f94bcd3a476bdf24ddf4ba8a39fd", git = "https://github.com/tirithen/clipper2c-sys" }

src/clipper.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<P: PointScaler> Clipper<NoSubjects, P> {
132132
///
133133
/// let mut clipper = Clipper::<NoSubjects, Centi>::new();
134134
/// clipper.set_z_callback(|_: Point<_>, _: Point<_>, _: Point<_>, _: Point<_>, p: &mut Point<_>| {
135-
/// p.set_z(1);
135+
/// *p = Point::new(p.x(), p.y(), 1);
136136
/// });
137137
/// ```
138138
pub fn set_z_callback(
@@ -460,7 +460,7 @@ mod test {
460460
_e2bot: Point<_>,
461461
_e2top: Point<_>,
462462
p: &mut Point<_>| {
463-
p.set_z(1);
463+
*p = Point::new_with_z(p.x(), p.y(), 1);
464464
success.set(true);
465465
},
466466
);

src/point.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ impl<P: PointScaler> Point<P> {
159159
)
160160
}
161161

162+
#[cfg(feature = "usingz")]
163+
/// Create a new point with user data.
164+
pub fn new_with_z(x: f64, y: f64, z: i64) -> Self {
165+
Self(
166+
ClipperPoint64 {
167+
x: P::scale(x) as i64,
168+
y: P::scale(y) as i64,
169+
z,
170+
},
171+
PhantomData,
172+
)
173+
}
174+
162175
/// Create a new point from scaled values, this means that point is
163176
/// constructed as is without applying the scaling multiplier.
164177
pub fn from_scaled(x: i64, y: i64) -> Self {
@@ -201,12 +214,6 @@ impl<P: PointScaler> Point<P> {
201214
pub fn z(&self) -> i64 {
202215
self.0.z
203216
}
204-
205-
#[cfg(feature = "usingz")]
206-
/// Sets the user data of the point.
207-
pub fn set_z(&mut self, z: i64) {
208-
self.0.z = z;
209-
}
210217
}
211218

212219
impl<P: PointScaler> Default for Point<P> {

0 commit comments

Comments
 (0)