/** * @param numGeoms number of expected geometries * @param numShellPoints expected number of points in shells of each geometry * @param numHoles expected number of holes of each geometry * @param numHolesPoints expected number of points in all holes of each geometry */ private void assertPixMapState( EditBlackboard map, int numGeoms, int numShellPoints, int numHoles, int numHolesPoints) { assertEquals("numGeoms", numGeoms, map.getGeoms().size()); // $NON-NLS-1$ for (EditGeom geom : map.getGeoms()) { assertEquals("numShellPoints", numShellPoints, geom.getShell().getNumPoints()); // $NON-NLS-1$ assertEquals("numHoles", numHoles, geom.getHoles().size()); // $NON-NLS-1$ for (PrimitiveShape hole : geom.getHoles()) { assertEquals( "numHolesPoints ", numHolesPoints, hole.getNumPoints()); // $NON-NLS-1$ } } }
@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)); } }
/* * Test method for 'net.refractions.udig.tools.edit.support.PrimitiveShape.getNumPoints()' */ @Test public void testGetNumPoints() { assertEquals(5, shell.getNumPoints()); }