49{
51 typedef Space::Point
Point;
52 typedef Space::Vector
Vector;
54
55 GIVEN(
"A triangle P at (0,0), (5/2,0), (0,7/2)" ) {
59 Polytope P {
Point(2,2), a, b, c };
60 THEN( "It contains more than 3 integer points" ) {
62 }
63 THEN( "It contains more points than its area" ) {
65 }
66 THEN( "It satisfies #In(P) <= #Int(P) + #Bd(P)" ) {
67 auto nb = P.count();
68 auto nb_int = P.countInterior();
69 auto nb_bd = P.countBoundary();
73 REQUIRE( nb <= nb_int + nb_bd );
74 }
75 WHEN( "Cut by some half-space" ) {
76 Polytope Q = P;
77 Q.cut(
Vector( -1, 1 ), 3 );
78 THEN( "It contains less points" ) {
79 REQUIRE( Q.count() < P.count() );
80 }
81 }
82 WHEN( "Multiplied by 4 as Q = 4 * P, it becomes a lattice polytope" ) {
83 Polytope Q = 4 * P;
84 THEN( "It satisfies Pick's formula, ie 2*Area(P) = 2*#Int(P) + #Bd(P) - 2" ) {
85 Polytope IntQ = Q.interiorPolytope();
86 auto nb_int = IntQ.count();
87 auto nb_bd = Q.count() - IntQ.count();
88 auto area2 = (5*2)*(7*2);
93 REQUIRE( area2 == 2*nb_int + nb_bd - 2 );
94 }
95 }
96 }
97 GIVEN(
"A closed segment S at (4/2,0/2), (-8/2,-4/2)" ) {
100 Polytope P {
Point(2,2), a, b };
101 THEN( "Its interior is empty #Int(P) == 0" ) {
102 auto nb_int = P.countInterior();
104 }
105 THEN( "It satisfies #In(P) == #Int(P) + #Bd(P) == #Bd(P) == 3" ) {
106 auto nb = P.count();
107 auto nb_int = P.countInterior();
108 auto nb_bd = P.countBoundary();
112 std::vector<Point> Ppts;
113 P.getPoints( Ppts );
117 REQUIRE( nb == nb_int + nb_bd );
118 }
119 }
120 GIVEN(
"A thin triangle P at (4/4,2/4), (2/4,4/4), (9/4,9/4)" ) {
124 Polytope P {
Point(4,4), a, b, c };
125 THEN( "It contains 2 integer points" ) {
127 }
128 THEN( "Its boundary is empty" ) {
129 REQUIRE( P.countBoundary() == 0 );
130 }
131 WHEN( "Multiplied by 4 as Q = 4 * P, it becomes a lattice polytope" ) {
132 Polytope Q = 4 * P;
133 THEN( "It satisfies Pick's formula, ie 2*Area(P) = 2*#Int(P) + #Bd(P) - 2" ) {
134 Polytope IntQ = Q.interiorPolytope();
135 auto nb_int = IntQ.count();
136 auto nb_bd = Q.count() - IntQ.count();
137 auto area2 = 24;
142 REQUIRE( area2 == 2*nb_int + nb_bd - 2 );
143 }
144 }
145 WHEN( "Multiplied by 10/3 as Q = 10/3 * P, it is a rational polytope" ) {
146 Polytope Q = Polytope::Rational( 10, 3 ) * P;
147 THEN( "It has a denominator 3 * gcd(4,10) == 6" ) {
148 REQUIRE( Q.denominator() == 6 );
149 }
150 THEN( "#( 3P Cap Z2 ) <= #( Q Cap Z2 ) < #( 4P Cap Z2 )" ) {
152 Polytope S = 4 * P;
153 auto nbQ = Q.count();
154 auto nbR =
R.count();
155 auto nbS = S.count();
161 }
162 THEN( "6/5*Q is a polytope equal to 4*P." ) {
163 Polytope
R = Polytope::Rational( 6, 5 ) * Q;
164 Polytope S = 4 * P;
165 std::vector<Point> Rpts, Spts;
167 S.getPoints( Spts );
170 REQUIRE( std::equal( Rpts.cbegin(), Rpts.cend(), Spts.cbegin() ) );
171 }
172 }
173 }
174}
Aim: Represents an nD rational polytope, i.e. a convex polyhedron bounded by vertices with rational c...
DigitalPlane::Point Vector
GIVEN("A cubical complex with random 3-cells")
REQUIRE(domain.isInside(aPoint))