/* * Test method for 'net.refractions.udig.tools.edit.support.PrimitiveShape.getCoord(int)' */ @Test public void testGetCoord() { assertEquals(bb.toCoord(Point.valueOf(10, 10)), shell.getCoord(0)); assertEquals(bb.toCoord(Point.valueOf(11, 10)), shell.getCoord(1)); assertEquals(bb.toCoord(Point.valueOf(10, 10)), shell.getCoord(2)); assertEquals(bb.toCoord(Point.valueOf(2, 20)), shell.getCoord(3)); assertEquals(bb.toCoord(Point.valueOf(2, 20)), shell.getCoord(4)); assertEquals(bb.toCoord(Point.valueOf(4000, 8000)), shell.getCoord(5)); assertEquals(bb.toCoord(Point.valueOf(4000, 8000)), shell.getCoord(6)); }
@Test public void testRemoveCoordinate() throws Exception { bb.removeCoordinate(4, shell.getCoord(6), shell); assertEquals(bb.toCoord(Point.valueOf(10, 10)), shell.getCoord(0)); assertEquals(bb.toCoord(Point.valueOf(11, 10)), shell.getCoord(1)); assertEquals(bb.toCoord(Point.valueOf(10, 10)), shell.getCoord(2)); assertEquals(bb.toCoord(Point.valueOf(2, 20)), shell.getCoord(3)); assertEquals(bb.toCoord(Point.valueOf(2, 20)), shell.getCoord(4)); assertEquals(bb.toCoord(Point.valueOf(4000, 8000)), shell.getCoord(5)); }
@Test public void testLakeDrawingCase() throws Exception { URL url = TestsPlugin.getDefault().getBundle().getResource("data/lake.gml"); // $NON-NLS-1$ InputStream in = url.openConnection().getInputStream(); InputStreamReader filereader = new InputStreamReader(in); InputSource input = new InputSource(filereader); DefaultFeatureCollection collection = new DefaultFeatureCollection(); GMLReceiver receiver = new GMLReceiver(collection); GMLFilterFeature filterFeature = new GMLFilterFeature(receiver); GMLFilterGeometry filterGeometry = new GMLFilterGeometry(filterFeature); GMLFilterDocument filterDocument = new GMLFilterDocument(filterGeometry); try { // parse xml XMLReader reader = XMLReaderFactory.createXMLReader(); reader.setContentHandler(filterDocument); reader.parse(input); } catch (Exception e) { throw new RuntimeException(e); } SimpleFeature feature = collection.features().next(); ReferencedEnvelope bounds = new ReferencedEnvelope(feature.getBounds()); bounds = new ReferencedEnvelope( bounds.getMinX() - (bounds.getWidth() / 8), bounds.getMaxX() + (bounds.getWidth() / 8), bounds.getMinY() - (bounds.getHeight() / 4), bounds.getMaxY() + (bounds.getHeight() / 4), DefaultGeographicCRS.WGS84); EditBlackboard map = new EditBlackboard( SCREEN.x, SCREEN.y, ScaleUtils.worldToScreenTransform(bounds, new Dimension(100, 100)), layerToWorld); map.setGeometries((Geometry) feature.getDefaultGeometry(), null); Polygon poly = (Polygon) ((MultiPolygon) feature.getDefaultGeometry()).getGeometryN(0); PrimitiveShape shell = map.getGeoms().get(0).getShell(); assertEquals(poly.getExteriorRing().getCoordinates().length, shell.getNumCoords()); for (int i = 0; i < shell.getNumCoords(); i++) { assertEquals( "i=" + i, poly.getExteriorRing().getCoordinateN(i), shell.getCoord(i)); // $NON-NLS-1$ } assertEquals(shell.getCoord(0), shell.getCoord(shell.getNumCoords() - 1)); assertEquals(shell.getPoint(0), shell.getPoint(shell.getNumPoints() - 1)); List<PrimitiveShape> holes = map.getGeoms().get(0).getHoles(); for (int j = 0; j < holes.size(); j++) { PrimitiveShape hole = holes.get(j); for (int i = 0; i < hole.getNumCoords(); i++) { assertEquals( "hole=" + j + "i=" + i, poly.getInteriorRingN(j).getCoordinateN(i), hole.getCoord(i)); // $NON-NLS-1$ //$NON-NLS-2$ } assertEquals(hole.getCoord(0), hole.getCoord(hole.getNumCoords() - 1)); assertEquals(hole.getPoint(0), hole.getPoint(hole.getNumPoints() - 1)); } }