33import static java .lang .Math .sqrt ;
44import static java .util .Arrays .asList ;
55import static org .junit .Assert .*;
6- import static org .osm2world .math .shapes .SimplePolygonXZ .isSelfIntersecting ;
76import static org .osm2world .math .VectorXZ .NULL_VECTOR ;
7+ import static org .osm2world .math .shapes .SimplePolygonXZ .isSelfIntersecting ;
88import static org .osm2world .test .TestUtil .assertAlmostEquals ;
99import static org .osm2world .test .TestUtil .assertSameCyclicOrder ;
1010
1818
1919public class SimplePolygonXZTest {
2020
21- private SimplePolygonXZ p1 = new SimplePolygonXZ (asList (
21+ private final SimplePolygonXZ p1 = new SimplePolygonXZ (asList (
2222 new VectorXZ (-1 , -1 ),
2323 new VectorXZ (-1 , 0 ),
2424 new VectorXZ (-1 , +1 ),
2525 new VectorXZ (+1 , +1 ),
2626 new VectorXZ (+1 , -1 ),
2727 new VectorXZ (-1 , -1 )));
2828
29- private SimplePolygonXZ p2 = new SimplePolygonXZ (asList (
29+ private final SimplePolygonXZ p2 = new SimplePolygonXZ (asList (
3030 new VectorXZ (-0.5 , -0.5 ),
3131 new VectorXZ (-0.5 , +1.5 ),
3232 new VectorXZ (+1.5 , +1.5 ),
@@ -127,7 +127,7 @@ public void testIsClockwise1() {
127127
128128 assertTrue (new SimplePolygonXZ (outlineA ).isClockwise ());
129129
130- List <VectorXZ > outlineAInv = new ArrayList <VectorXZ >(outlineA );
130+ List <VectorXZ > outlineAInv = new ArrayList <>(outlineA );
131131 Collections .reverse (outlineAInv );
132132 assertFalse (new SimplePolygonXZ (outlineAInv ).isClockwise ());
133133
@@ -138,11 +138,33 @@ public void testIsClockwise2() {
138138
139139 assertTrue (new SimplePolygonXZ (outlineB ).isClockwise ());
140140
141- List <VectorXZ > outlineBInv = new ArrayList <VectorXZ >(outlineB );
141+ List <VectorXZ > outlineBInv = new ArrayList <>(outlineB );
142142 Collections .reverse (outlineBInv );
143143 assertFalse (new SimplePolygonXZ (outlineBInv ).isClockwise ());
144144 }
145145
146+ @ Test
147+ public void testMakeCounterclockwise () {
148+
149+ for (List <VectorXZ > outline : List .of (outlineA , outlineB )) {
150+
151+ var poly = new SimplePolygonXZ (outline );
152+ assertTrue (poly .isClockwise ());
153+
154+ var polyCCW = poly .makeCounterclockwise ();
155+ assertFalse (polyCCW .isClockwise ());
156+ assertEquals (poly .getArea (), polyCCW .getArea (), 1e-3 );
157+
158+ var polyInv = poly .reverse ();
159+ assertFalse (polyInv .isClockwise ());
160+ assertEquals (polyCCW , polyInv );
161+
162+ assertEquals (poly , polyInv .reverse ());
163+
164+ }
165+
166+ }
167+
146168 @ Test
147169 public void testIsClockwise3 () {
148170
0 commit comments