Skip to content

Commit

Permalink
improving tests for Offset trait
Browse files Browse the repository at this point in the history
  • Loading branch information
thehappycheese committed Nov 18, 2022
1 parent c542dd9 commit 47c5a6a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
2 changes: 1 addition & 1 deletion geo/src/algorithm/offset/cross_product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ mod test {
// expect swapping will result in negative
assert_eq!(cross_product_2d(ab, ac), -1f64);

// Add skew
// Add skew; results should be the same
let a = Coord { x: 0f64, y: 0f64 };
let b = Coord { x: 0f64, y: 1f64 };
let c = Coord { x: 1f64, y: 1f64 };
Expand Down
35 changes: 10 additions & 25 deletions geo/src/algorithm/offset/line_intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ mod test {
FalseIntersectionPointType, LineIntersectionWithParameterResult,
LineSegmentIntersectionType,
};
use crate::Coord;
use crate::{Coord, coord};
use FalseIntersectionPointType::{AfterEnd, BeforeStart};
use LineSegmentIntersectionType::{FalseIntersectionPoint, TrueIntersectionPoint};

Expand Down Expand Up @@ -269,6 +269,12 @@ mod test {
let b = Coord { x: 2f64, y: 3f64 };
let c = Coord { x: 0f64, y: 2f64 };
let d = Coord { x: -2f64, y: 6f64 };

fn check_intersection(intersection:Coord<f64>){
let diff = intersection - Coord { x: 1f64 / 3f64, y: 4f64 / 3f64 };
assert!(diff.x * diff.x + diff.y * diff.y < 0.00000000001f64);
}

if let Some(LineIntersectionWithParameterResult {
ab,
cd,
Expand All @@ -277,14 +283,7 @@ mod test {
{
assert_eq!(ab, FalseIntersectionPoint(BeforeStart));
assert_eq!(cd, FalseIntersectionPoint(BeforeStart));
println!("{intersection:?}");
let diff = intersection
- Coord {
x: 1.0 / 3.0f64,
y: 4.0 / 3.0f64,
};
println!("{diff:?}");
assert!(diff.x * diff.x + diff.y * diff.y < 0.00000000001f64);
check_intersection(intersection);
} else {
assert!(false);
}
Expand All @@ -297,14 +296,7 @@ mod test {
{
assert_eq!(ab, FalseIntersectionPoint(AfterEnd));
assert_eq!(cd, FalseIntersectionPoint(BeforeStart));
println!("{intersection:?}");
let diff = intersection
- Coord {
x: 1.0 / 3.0f64,
y: 4.0 / 3.0f64,
};
println!("{diff:?}");
assert!(diff.x * diff.x + diff.y * diff.y < 0.00000000001f64);
check_intersection(intersection);
} else {
assert!(false);
}
Expand All @@ -317,14 +309,7 @@ mod test {
{
assert_eq!(ab, FalseIntersectionPoint(BeforeStart));
assert_eq!(cd, FalseIntersectionPoint(AfterEnd));
println!("{intersection:?}");
let diff = intersection
- Coord {
x: 1.0 / 3.0f64,
y: 4.0 / 3.0f64,
};
println!("{diff:?}");
assert!(diff.x * diff.x + diff.y * diff.y < 0.00000000001f64);
check_intersection(intersection);
} else {
assert!(false);
}
Expand Down
15 changes: 12 additions & 3 deletions geo/src/algorithm/offset/offset_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,28 @@ where
// we are potentially creating a redundant point in the
// output here. Colinear segments should maybe get
// removed before or after this algorithm
//println!("CASE 0 - colinear");
vec![*b]
},
Some(LineIntersectionWithParameterResult {
ab,
cd,
intersection,
}) => match (ab, cd) {
(TrueIntersectionPoint, TrueIntersectionPoint) => vec![intersection],
(TrueIntersectionPoint, TrueIntersectionPoint) => {
//println!("CASE 1 - extend");
vec![intersection]
},
(FalseIntersectionPoint(AfterEnd), FalseIntersectionPoint(_)) => {
// TODO: Mitre limit logic goes here
//println!("CASE 2 - extend");
vec![intersection]
}
_ => vec![*b, *c],
_ => {
println!("CASE 3 - bridge");
vec![*b, *c]
},

},
}
},
Expand Down Expand Up @@ -282,7 +291,7 @@ mod test {
x: 5.279039119779313f64,
y: 2.516847170273373f64
},
Coord { x: 5f64, y: 2f64 },
Coord { x: 5.20f64, y: 2.36f64 },
Coord {
x: 3.2388869474813826f64,
y: 4.489952088082639f64
Expand Down

0 comments on commit 47c5a6a

Please sign in to comment.