149{
153
154 GIVEN(
"A twisted simplex P at (0,0,0), (1,0,0), (0,1,0), (1,1,z)" ) {
159 Polytope P { a, b, c, d };
160 THEN( "Its domain contains its vertices" ) {
161 REQUIRE( P.isDomainPointInside( a ) );
162 REQUIRE( P.isDomainPointInside( b ) );
163 REQUIRE( P.isDomainPointInside( c ) );
164 REQUIRE( P.isDomainPointInside( d ) );
165 }
166 THEN( "Its vertices lie on its boundary" ) {
171 REQUIRE( ! P.isInterior( a ) );
172 REQUIRE( ! P.isInterior( b ) );
173 REQUIRE( ! P.isInterior( c ) );
174 REQUIRE( ! P.isInterior( d ) );
175 }
176 THEN( "It satisfies #In(P) <= #Int(P) + #Bd(P)" ) {
177 auto nb = P.count();
178 auto nb_int = P.countInterior();
179 auto nb_bd = P.countBoundary();
183 REQUIRE( nb <= nb_int + nb_bd );
184 }
185 THEN( "It contains only 4 integer points" ) {
187 }
188
189 }
190
191 GIVEN(
"A closed arbitrary simplex P at (0,0,0), (6,3,0), (0,5,10), (6,4,8)" ) {
196 Polytope P { a, b, c, d };
197
198 THEN( "It satisfies #In(P) == #Int(P) + #Bd(P)" ) {
199 auto nb = P.count();
200 auto nb_int = P.countInterior();
201 auto nb_bd = P.countBoundary();
205 REQUIRE( nb == nb_int + nb_bd );
206 }
207 THEN( "Its boundary points and interior points are its inside points (closed polytope)" ) {
208 std::vector<Point> inside;
209 std::vector<Point> interior;
210 std::vector<Point> boundary;
211 std::vector<Point> all;
212 P.getPoints( inside );
213 P.getInteriorPoints( interior );
214 P.getBoundaryPoints( boundary );
215 std::sort( inside.begin(), inside.end() );
216 std::sort( interior.begin(), interior.end() );
217 std::sort( boundary.begin(), boundary.end() );
221 std::set_union( interior.cbegin(), interior.cend(), boundary.cbegin(), boundary.cend(),
222 std::back_inserter( all ) );
223 REQUIRE( std::equal( inside.cbegin(), inside.cend(), all.cbegin() ) );
224 }
225 WHEN( "Cut by some axis aligned half-space (1,0,0).x <= 3" ) {
226 Polytope Q = P;
227 Q.cut( 0, true, 3 );
228 THEN( "It contains less points" ) {
233 auto Pnb = P.count();
234 auto Pnb_int = P.countInterior();
235 auto Pnb_bd = P.countBoundary();
239 auto Qnb = Q.count();
240 auto Qnb_int = Q.countInterior();
241 auto Qnb_bd = Q.countBoundary();
245 std::vector<Point> Qpts;
246 Q.getPoints( Qpts );
248 REQUIRE( Q.count() < P.count() );
249 }
250 }
251 }
252 GIVEN(
"A closed triangle P at (0,0,0), (6,3,0), (2,5,10)" ) {
256 Polytope P { a, b, c };
257 THEN( "Its interior is empty #Int(P) == 0" ) {
258 auto nb_int = P.countInterior();
260 }
261 THEN( "It satisfies #In(P) == #Int(P) + #Bd(P)" ) {
262 auto nb = P.count();
263 auto nb_int = P.countInterior();
264 auto nb_bd = P.countBoundary();
268 std::vector<Point> Ppts;
269 P.getPoints( Ppts );
271 REQUIRE( nb == nb_int + nb_bd );
272 }
273 }
274 GIVEN(
"A closed triangle P with relatively prime coordinates (3,0,0), (0,4,0), (0,0,5)" ) {
278 Polytope P { a, b, c };
279 THEN( "Its interior is empty #Int(P) == 0" ) {
280 auto nb_int = P.countInterior();
282 }
283 THEN( "It satisfies #In(P) == #Int(P) + #Bd(P) == #Bd(P) == 3" ) {
284 auto nb = P.count();
285 auto nb_int = P.countInterior();
286 auto nb_bd = P.countBoundary();
290 std::vector<Point> Ppts;
291 P.getPoints( Ppts );
294 REQUIRE( nb == nb_int + nb_bd );
295 }
296 }
297 GIVEN(
"A closed segment S at (0,0,0), (8,-4,2)" ) {
300 Polytope P { a, b };
301 THEN( "Its interior is empty #Int(P) == 0" ) {
302 auto nb_int = P.countInterior();
304 }
305 THEN( "It satisfies #In(P) == #Int(P) + #Bd(P) == #Bd(P) == 3" ) {
306 auto nb = P.count();
307 auto nb_int = P.countInterior();
308 auto nb_bd = P.countBoundary();
312 std::vector<Point> Ppts;
313 P.getPoints( Ppts );
316 REQUIRE( nb == nb_int + nb_bd );
317 }
318 }
319}