A zero distance buffer call on a Polygon with a self-intersection gives different results from an identical case in the Java library. For example, the following Junit case for the Java API runs successfully:
`public void testInvalidPolygon(){
try {
WKTReader rdr = new WKTReader();
Geometry geom = rdr.read("POLYGON ((21.32686 47.78723, 21.31486 47.81023, "
+ "21.32786 47.81123, 21.33986 47.80223, 21.32586 47.82723, "
+ "21.32786 47.82323, 21.33886 47.82623, 21.34186 47.82123, "
+ "21.40686 47.81723, 21.32686 47.78723))"); //Self-Intersecting
IsValidOp op = new IsValidOp(geom);
if(!op.isValid()){
System.out.println(op.getValidationError().getMessage());
Geometry geomFixed = geom.buffer(0.0);
Geometry expected = rdr.read("POLYGON ((21.32686 47.78723, 21.31486 47.81023, "
+ "21.32786 47.81123, 21.33986 47.80223, 21.328068201892744 47.823286782334385, "
+ "21.33886 47.82623, 21.34186 47.82123, 21.40686 47.81723, 21.32686 47.78723))");
checkEqual(geomFixed,expected);
}
} catch (ParseException ex) {
Logger.getLogger(InvalidPolygonTest.class.getName()).log(Level.SEVERE, null, ex);
}
}`
while the following equivalent dart test fails:
`test('testInvalidPolygon', () {
WKTReader rdr = WKTReader();
Geometry? geom = rdr.read(
'POLYGON ((21.32686 47.78723, 21.31486 47.81023,21.32786 47.81123, '
'21.33986 47.80223, 21.32586 47.82723,21.32786 47.82323, 21.33886 47.82623, '
'21.34186 47.82123,21.40686 47.81723, 21.32686 47.78723))'); //Self-Intersecting
IsValidOp op = IsValidOp(geom!);
if (!op.isValid()) {
print(op.getValidationError()!.getMessage());
Geometry geomFixed = geom.buffer(0.0);
Geometry? expected = rdr.read('POLYGON ((21.32686 47.78723, 21.31486 47.81023, ' +
'21.32786 47.81123, 21.33986 47.80223, 21.328068201892744 47.823286782334385, ' +
'21.33886 47.82623, 21.34186 47.82123, 21.40686 47.81723, 21.32686 47.78723))');
checkEqualMsg('Geometries are not equal',expected!,geomFixed);
}
});`
The dart case produces the following output:
Self-intersection
FAIL - Geometries are not equal: Expected = POLYGON ((21.3148599999999995 47.8102299999999971, 21.3278600000000012 47.8112300000000019, 21.3398600000000016 47.8022300000000016, 21.3280682018927444 47.8232867823343852, 21.3388600000000004 47.8262300000000025, 21.3418600000000005 47.8212299999999999, 21.4068600000000018 47.8172300000000021, 21.32686 47.787230000000001, 21.3148599999999995 47.8102299999999971)) -- Actual = POLYGON ((21.3258599999999987 47.8272300000000001, 21.3280682018927444 47.8232867823343852, 21.3278600000000012 47.8232300000000023, 21.3258599999999987 47.8272300000000001))
package:matcher expect
test/invalid_polygon_test.dart 12:5 main.checkEqualMsg
test/invalid_polygon_test.dart 28:7 main.
Expected:
Actual: