PackedCoordinateSequence$Double calls getOrdinate(2) or getOrdinate(3) on the coordinates and that throws an exception in CoordinateXY.
Polygon polygonA = new GeometryFactory(
new PackedCoordinateSequenceFactory()).createPolygon(
new Coordinate[] {
new CoordinateXY(0, 0),
new CoordinateXY(10, 0),
new CoordinateXY(10, 10),
new CoordinateXY(0, 10),
new CoordinateXY(0, 0)
}
);
Polygon polygonB = new GeometryFactory().createPolygon(
new Coordinate[] {
new CoordinateXY(5, 5),
new CoordinateXY(15, 5),
new CoordinateXY(15, 15),
new CoordinateXY(5, 15),
new CoordinateXY(5, 5)
}
);
polygonB.intersection(polygonA);
polygonA.intersection(polygonB);
In the above example, the first intersection does not throw an exception while the second does.
PackedCoordinateSequence$Float does this differently by calling getZ() on the coordinates. So possibly the solution is to call getZ() from getOrdinate() in CoordinateXY.