Skip to content

Commit 26ad337

Browse files
committed
Add some tests for isolines
1 parent 49ecee0 commit 26ad337

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

src/lib.rs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub use crate::contour::{contour_rings, Contour, ContourBuilder};
5656
#[cfg(test)]
5757
mod tests {
5858
use crate::ContourBuilder;
59-
use geo_types::{polygon, MultiPolygon};
59+
use geo_types::{line_string, polygon, MultiLineString, MultiPolygon};
6060

6161
#[test]
6262
fn test_empty_polygons() {
@@ -77,6 +77,25 @@ mod tests {
7777
assert!(res[0].geometry().0.is_empty());
7878
}
7979

80+
#[test]
81+
fn test_empty_isoline() {
82+
let c = ContourBuilder::new(10, 10, true);
83+
#[rustfmt::skip]
84+
let res = c.lines(&[
85+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
86+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
87+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
88+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
89+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
90+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
91+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
92+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
93+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
94+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
95+
], &[0.5]).unwrap();
96+
assert!(res[0].geometry().0.is_empty());
97+
}
98+
8099
#[test]
81100
fn test_simple_polygon() {
82101
let c = ContourBuilder::new(10, 10, true);
@@ -117,6 +136,46 @@ mod tests {
117136
);
118137
}
119138

139+
#[test]
140+
fn test_simple_isoline() {
141+
let c = ContourBuilder::new(10, 10, true);
142+
#[rustfmt::skip]
143+
let res = c.lines(&[
144+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
145+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
146+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
147+
0., 0., 0., 1., 1., 1., 0., 0., 0., 0.,
148+
0., 0., 0., 1., 1., 1., 0., 0., 0., 0.,
149+
0., 0., 0., 1., 1., 1., 0., 0., 0., 0.,
150+
0., 0., 0., 1., 1., 1., 0., 0., 0., 0.,
151+
0., 0., 0., 1., 1., 1., 0., 0., 0., 0.,
152+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
153+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.
154+
], &[0.5]).unwrap();
155+
assert_eq!(
156+
res[0].geometry(),
157+
&MultiLineString(vec![line_string![
158+
(x: 6., y: 7.5),
159+
(x: 6., y: 6.5),
160+
(x: 6., y: 5.5),
161+
(x: 6., y: 4.5),
162+
(x: 6., y: 3.5),
163+
(x: 5.5, y: 3.),
164+
(x: 4.5, y: 3.),
165+
(x: 3.5, y: 3.),
166+
(x: 3., y: 3.5),
167+
(x: 3., y: 4.5),
168+
(x: 3., y: 5.5),
169+
(x: 3., y: 6.5),
170+
(x: 3., y: 7.5),
171+
(x: 3.5, y: 8.),
172+
(x: 4.5, y: 8.),
173+
(x: 5.5, y: 8.),
174+
(x: 6., y: 7.5)
175+
]])
176+
);
177+
}
178+
120179
#[test]
121180
fn test_polygon_with_hole() {
122181
let c = ContourBuilder::new(10, 10, true);

0 commit comments

Comments
 (0)