Skip to content

Commit 47c5a6a

Browse files
improving tests for Offset trait
1 parent c542dd9 commit 47c5a6a

File tree

3 files changed

+23
-29
lines changed

3 files changed

+23
-29
lines changed

geo/src/algorithm/offset/cross_product.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ mod test {
6969
// expect swapping will result in negative
7070
assert_eq!(cross_product_2d(ab, ac), -1f64);
7171

72-
// Add skew
72+
// Add skew; results should be the same
7373
let a = Coord { x: 0f64, y: 0f64 };
7474
let b = Coord { x: 0f64, y: 1f64 };
7575
let c = Coord { x: 1f64, y: 1f64 };

geo/src/algorithm/offset/line_intersection.rs

+10-25
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ mod test {
213213
FalseIntersectionPointType, LineIntersectionWithParameterResult,
214214
LineSegmentIntersectionType,
215215
};
216-
use crate::Coord;
216+
use crate::{Coord, coord};
217217
use FalseIntersectionPointType::{AfterEnd, BeforeStart};
218218
use LineSegmentIntersectionType::{FalseIntersectionPoint, TrueIntersectionPoint};
219219

@@ -269,6 +269,12 @@ mod test {
269269
let b = Coord { x: 2f64, y: 3f64 };
270270
let c = Coord { x: 0f64, y: 2f64 };
271271
let d = Coord { x: -2f64, y: 6f64 };
272+
273+
fn check_intersection(intersection:Coord<f64>){
274+
let diff = intersection - Coord { x: 1f64 / 3f64, y: 4f64 / 3f64 };
275+
assert!(diff.x * diff.x + diff.y * diff.y < 0.00000000001f64);
276+
}
277+
272278
if let Some(LineIntersectionWithParameterResult {
273279
ab,
274280
cd,
@@ -277,14 +283,7 @@ mod test {
277283
{
278284
assert_eq!(ab, FalseIntersectionPoint(BeforeStart));
279285
assert_eq!(cd, FalseIntersectionPoint(BeforeStart));
280-
println!("{intersection:?}");
281-
let diff = intersection
282-
- Coord {
283-
x: 1.0 / 3.0f64,
284-
y: 4.0 / 3.0f64,
285-
};
286-
println!("{diff:?}");
287-
assert!(diff.x * diff.x + diff.y * diff.y < 0.00000000001f64);
286+
check_intersection(intersection);
288287
} else {
289288
assert!(false);
290289
}
@@ -297,14 +296,7 @@ mod test {
297296
{
298297
assert_eq!(ab, FalseIntersectionPoint(AfterEnd));
299298
assert_eq!(cd, FalseIntersectionPoint(BeforeStart));
300-
println!("{intersection:?}");
301-
let diff = intersection
302-
- Coord {
303-
x: 1.0 / 3.0f64,
304-
y: 4.0 / 3.0f64,
305-
};
306-
println!("{diff:?}");
307-
assert!(diff.x * diff.x + diff.y * diff.y < 0.00000000001f64);
299+
check_intersection(intersection);
308300
} else {
309301
assert!(false);
310302
}
@@ -317,14 +309,7 @@ mod test {
317309
{
318310
assert_eq!(ab, FalseIntersectionPoint(BeforeStart));
319311
assert_eq!(cd, FalseIntersectionPoint(AfterEnd));
320-
println!("{intersection:?}");
321-
let diff = intersection
322-
- Coord {
323-
x: 1.0 / 3.0f64,
324-
y: 4.0 / 3.0f64,
325-
};
326-
println!("{diff:?}");
327-
assert!(diff.x * diff.x + diff.y * diff.y < 0.00000000001f64);
312+
check_intersection(intersection);
328313
} else {
329314
assert!(false);
330315
}

geo/src/algorithm/offset/offset_trait.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,28 @@ where
115115
// we are potentially creating a redundant point in the
116116
// output here. Colinear segments should maybe get
117117
// removed before or after this algorithm
118+
//println!("CASE 0 - colinear");
118119
vec![*b]
119120
},
120121
Some(LineIntersectionWithParameterResult {
121122
ab,
122123
cd,
123124
intersection,
124125
}) => match (ab, cd) {
125-
(TrueIntersectionPoint, TrueIntersectionPoint) => vec![intersection],
126+
(TrueIntersectionPoint, TrueIntersectionPoint) => {
127+
//println!("CASE 1 - extend");
128+
vec![intersection]
129+
},
126130
(FalseIntersectionPoint(AfterEnd), FalseIntersectionPoint(_)) => {
127131
// TODO: Mitre limit logic goes here
132+
//println!("CASE 2 - extend");
128133
vec![intersection]
129134
}
130-
_ => vec![*b, *c],
135+
_ => {
136+
println!("CASE 3 - bridge");
137+
vec![*b, *c]
138+
},
139+
131140
},
132141
}
133142
},
@@ -282,7 +291,7 @@ mod test {
282291
x: 5.279039119779313f64,
283292
y: 2.516847170273373f64
284293
},
285-
Coord { x: 5f64, y: 2f64 },
294+
Coord { x: 5.20f64, y: 2.36f64 },
286295
Coord {
287296
x: 3.2388869474813826f64,
288297
y: 4.489952088082639f64

0 commit comments

Comments
 (0)