Skip to content

Commit 6b27f2e

Browse files
committed
add box/polygon + polygon/box unit test
1 parent d71153d commit 6b27f2e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/test-intersection.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,37 @@ void test_intersection()
119119
}
120120
}
121121
}
122+
123+
// Box/Polygon + Polygon/Box
124+
//
125+
// A : POLYGON((0 0,100 0,100 100,0 100,0 0),(25 25,25 75,50 75,25 25),(35 25,60 75,75 75,75 25,35 25))
126+
// BOX : POLYGON((0 40,0 60,100 60,100 40,0 40))
127+
// A ∩ BOX == BOX ∩ A : POLYGON((0 60,0 40,25 40,25 60,0 60)) POLYGON((100 60,75 60,75 40,100 40,100 60)) POLYGON((42.5 60,32.5 40,42.5 40,52.5 60,42.5 60))
128+
{
129+
polygon<double> poly {
130+
{{ {0,0}, {100,0}, {100,100}, {0, 100}, {0,0}}},
131+
{{ {25,25}, {25,75}, {50,75}, {25,25} }},
132+
{{ {35,25}, {60,75}, {75,75}, {75,25}, {35,25} }}
133+
};
134+
135+
box<double> b{{0,40},{100,60}};
136+
137+
auto result1 = algorithms::intersection(b, poly);
138+
auto result2 = algorithms::intersection(poly, b);
139+
BOOST_CHECK(result1 == result2);
140+
BOOST_CHECK(result1.size() == 3);
141+
142+
polygon<double> p0{{{0,60},{0,40},{25,40},{25,60},{0,60}}};
143+
polygon<double> p1{{{100,60},{75,60},{75,40},{100,40},{100,60}}};
144+
polygon<double> p2{{{42.5,60},{32.5,40},{42.5,40},{52.5,60},{42.5,60}}};
145+
BOOST_CHECK(result1[0] == p0);
146+
BOOST_CHECK(result1[1] == p1);
147+
BOOST_CHECK(result1[2] == p2);
148+
BOOST_CHECK(result2[0] == p0);
149+
BOOST_CHECK(result2[1] == p1);
150+
BOOST_CHECK(result2[2] == p2);
151+
152+
}
122153
}
123154
}
124155

0 commit comments

Comments
 (0)