28
28
import org .elasticsearch .geometry .Point ;
29
29
import org .elasticsearch .geometry .Polygon ;
30
30
import org .elasticsearch .geometry .ShapeType ;
31
+ import org .elasticsearch .geometry .utils .GeographyValidator ;
32
+ import org .elasticsearch .geometry .utils .WellKnownText ;
31
33
import org .elasticsearch .test .ESTestCase ;
32
34
33
35
import java .util .Arrays ;
39
41
import static org .elasticsearch .common .geo .DimensionalShapeType .POINT ;
40
42
import static org .elasticsearch .common .geo .DimensionalShapeType .POLYGON ;
41
43
import static org .hamcrest .Matchers .anyOf ;
44
+ import static org .hamcrest .Matchers .closeTo ;
42
45
import static org .hamcrest .Matchers .equalTo ;
43
46
44
47
public class CentroidCalculatorTests extends ESTestCase {
@@ -53,6 +56,36 @@ public void testPoint() {
53
56
assertThat (calculator .getDimensionalShapeType (), equalTo (POINT ));
54
57
}
55
58
59
+ public void testPolygonWithSmallTrianglesOfZeroWeight () throws Exception {
60
+ Geometry geometry = new WellKnownText (false , new GeographyValidator (true ))
61
+ .fromWKT ("POLYGON((-4.385064 55.2259599,-4.385056 55.2259224,-4.3850466 55.2258994,-4.3849755 55.2258574," +
62
+ "-4.3849339 55.2258589,-4.3847033 55.2258742,-4.3846805 55.2258818,-4.3846282 55.2259132,-4.3846215 55.2259247," +
63
+ "-4.3846121 55.2259683,-4.3846147 55.2259798,-4.3846369 55.2260157,-4.3846472 55.2260241," +
64
+ "-4.3846697 55.2260409,-4.3846952 55.2260562,-4.384765 55.22608,-4.3848199 55.2260861,-4.3848481 55.2260845," +
65
+ "-4.3849245 55.2260761,-4.3849393 55.22607,-4.3849996 55.2260432,-4.3850131 55.2260364,-4.3850426 55.2259989," +
66
+ "-4.385064 55.2259599),(-4.3850104 55.2259583,-4.385005 55.2259752,-4.384997 55.2259892,-4.3849339 55.2259981," +
67
+ "-4.3849272 55.2259308,-4.3850016 55.2259262,-4.385005 55.2259377,-4.3850104 55.2259583)," +
68
+ "(-4.3849996 55.2259193,-4.3847502 55.2259331,-4.3847548 55.2258921,-4.3848012 55.2258895," +
69
+ "-4.3849219 55.2258811,-4.3849514 55.2258818,-4.3849728 55.2258933,-4.3849996 55.2259193)," +
70
+ "(-4.3849917 55.2259984,-4.3849849 55.2260103,-4.3849771 55.2260192,-4.3849701 55.2260019,-4.3849917 55.2259984)," +
71
+ "(-4.3846608 55.2259374,-4.384663 55.2259316,-4.3846711 55.2259201,-4.3846992 55.225904," +
72
+ "-4.384718 55.2258941,-4.3847434 55.2258927,-4.3847314 55.2259407,-4.3849098 55.2259316,-4.3849098 55.2259492," +
73
+ "-4.3848843 55.2259515,-4.3849017 55.2260119,-4.3849567 55.226005,-4.3849701 55.2260272,-4.3849299 55.2260486," +
74
+ "-4.3849192 55.2260295,-4.384883 55.2260188,-4.3848776 55.2260119,-4.3848441 55.2260149,-4.3848441 55.2260226," +
75
+ "-4.3847864 55.2260241,-4.384722 55.2259652,-4.3847053 55.2259706,-4.384683 55.225954,-4.3846608 55.2259374)," +
76
+ "(-4.3846541 55.2259549,-4.384698 55.2259883,-4.3847173 55.2259828,-4.3847743 55.2260333,-4.3847891 55.2260356," +
77
+ "-4.3848146 55.226031,-4.3848199 55.2260409,-4.3848387 55.2260417,-4.3848494 55.2260593,-4.3848092 55.2260616," +
78
+ "-4.3847623 55.2260539,-4.3847341 55.2260432,-4.3847046 55.2260279,-4.3846738 55.2260062,-4.3846496 55.2259844," +
79
+ "-4.3846429 55.2259737,-4.3846523 55.2259714,-4.384651 55.2259629,-4.3846541 55.2259549)," +
80
+ "(-4.3846608 55.2259374,-4.3846559 55.2259502,-4.3846541 55.2259549,-4.3846608 55.2259374))" );
81
+ CentroidCalculator calculator = new CentroidCalculator (geometry );
82
+ assertThat (calculator .getX (), closeTo ( -4.3848 , 1e-4 ));
83
+ assertThat (calculator .getY (), closeTo (55.22595 , 1e-4 ));
84
+ assertThat (calculator .sumWeight (), closeTo (0 , 1e-5 ));
85
+ assertThat (calculator .getDimensionalShapeType (), equalTo (POLYGON ));
86
+ }
87
+
88
+
56
89
public void testLine () {
57
90
double [] y = new double [] { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 };
58
91
double [] x = new double [] { 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 , 100 };
0 commit comments