Skip to content

Commit

Permalink
add test to reproduce issue #27
Browse files Browse the repository at this point in the history
  • Loading branch information
lelongg committed Feb 8, 2025
1 parent cf30367 commit a0c5e85
Showing 1 changed file with 73 additions and 6 deletions.
79 changes: 73 additions & 6 deletions src/visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,9 @@ where
mod tests {
use super::*;
use data_uri_utils::svg_str_to_data_uri;
use geo::{Coord, Line};
use geo_rand::{GeoRand, GeoRandParameters};
use geo_svg::ToSvg;
use geo_svg::{Color, ToSvg};

fn test_visibility(
[origin_x, origin_y]: [f64; 2],
Expand All @@ -208,10 +209,7 @@ mod tests {
let lines: Vec<_> = segments
.iter()
.map(|[[x1, y1], [x2, y2]]| {
geo::Line::new(
geo::Coord { x: *x1, y: *y1 },
geo::Coord { x: *x2, y: *y2 },
)
geo::Line::new(geo::Coord { x: *x1, y: *y1 }, geo::Coord { x: *x2, y: *y2 })
})
.collect();

Expand Down Expand Up @@ -395,7 +393,7 @@ mod tests {
);
let polygons = dbg!(geo::Polygon::from(rect).difference(&holes, 1000.0));
println!("{}", svg_str_to_data_uri(polygons.to_svg().to_string(),));
let polygon = polygons.0.get(0).unwrap().clone();
let polygon = polygons.0.first().unwrap().clone();
let point = geo::Point::new(rect.width() / 2.0, rect.height() / 2.0);
let visibility_polygon = point.visibility(&polygon);

Expand Down Expand Up @@ -486,4 +484,73 @@ mod tests {

assert_eq!(events, result);
}

#[test]
fn issue_27() {
let point = geo::Point::new(1.53, -0.4);
let lines = vec![
Line {
start: Coord { x: 0.0, y: 0.5 },
end: Coord { x: 1.5, y: 0.5 },
},
Line {
start: Coord { x: 0.0, y: 0.0 },
end: Coord { x: 0.0, y: 1.0 },
},
Line {
start: Coord { x: 1.5, y: 0.5 },
end: Coord { x: 1.5, y: 1.5 },
},
Line {
start: Coord { x: 0.5, y: -0.5 },
end: Coord { x: 0.5, y: 0.5 },
},
Line {
start: Coord { x: -25.0, y: -25.0 },
end: Coord { x: 25.0, y: -25.0 },
},
Line {
start: Coord { x: 25.0, y: -25.0 },
end: Coord { x: 25.0, y: 25.0 },
},
Line {
start: Coord { x: 25.0, y: 25.0 },
end: Coord { x: -25.0, y: 25.0 },
},
Line {
start: Coord { x: -25.0, y: 25.0 },
end: Coord { x: -25.0, y: -25.0 },
},
];
let vis = point.visibility(lines.as_slice());
println!(
"{}",
svg_str_to_data_uri(
vis.to_svg()
.with_color(Color::Named("green"))
.with_stroke_width(0.0)
.and(
lines
.to_svg()
.with_color(Color::Named("red"))
.with_stroke_width(0.1)
)
.and(
point
.to_svg()
.with_color(Color::Named("blue"))
.with_radius(0.1)
.with_stroke_width(0.0)
)
.and(
Coord { x: 0.0, y: 1.0 }
.to_svg()
.with_color(Color::Named("orange"))
.with_radius(0.1)
.with_stroke_width(0.0)
)
.to_string(),
)
);
}
}

0 comments on commit a0c5e85

Please sign in to comment.