GMLReader implements ParserReader { protected static Coordinate findCentre(List<Coordinate> coordinates) { if (coordinates.size() < 3) { throw new DatatypeFormatException("GML posList does not contain 3 coordinates: " + coordinates); } double x1 = coordinates.get(0).x; double y1 = coordinates.get(0).y; double x2 = coordinates.get(1).x; double y2 = coordinates.get(1).y; double x3 = coordinates.get(2).x; double y3 = coordinates.get(2).y; double A = (x1 * (y2 - y3)) - (y1 * (x2 - x3)) + (x2 * y3) - (x3 * y2); double B = (((x1 * x1) + (y1 * y1)) * (y3 - y2)) + (((x2 * x2) + (y2 * y2)) * (y1 - y3)) + (((x3 * x3) + (y3 * y3)) * (y2 - y1)); double C = (((x1 * x1) + (y1 * y1)) * (x2 - x3)) + (((x2 * x2) + (y2 * y2)) * (x3 - x1)) + (((x3 * x3) + (y3 * y3)) * (x1 - x2)); double x = -(B / (2 * A)); double y = -(C / (2 * A)); Coordinate centre = new Coordinate(x, y); return centre; } protected  GMLReader(Element gmlElement); protected  GMLReader(Geometry geometry, int srsDimension, String srsURI); protected  GMLReader(Geometry geometry, int srsDimension); @Override Geometry getGeometry(); @Override String getSrsURI(); @Override CoordinateSequenceDimensions getDimensions(); @Override DimensionInfo getDimensionInfo(); static GMLReader extract(String gmlText); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testFindCentre() { List<Coordinate> coordinates = Arrays.asList(new Coordinate(-3, 4), new Coordinate(4, 5), new Coordinate(1, -4)); Coordinate expResult = new Coordinate(1, 1); Coordinate result = GMLReader.findCentre(coordinates); assertEquals(expResult, result); }