GeometryConvexHullCommand implements CommandHasRequest<GeometryConvexHullRequest, GeometryConvexHullResponse> { @Override public void execute(GeometryConvexHullRequest request, GeometryConvexHullResponse response) throws Exception { List<org.geomajas.geometry.Geometry> clientGeometries = request.getGeometries(); if (clientGeometries == null || clientGeometries.size() == 0) { throw new GeomajasException(ExceptionCode.PARAMETER_MISSING, "request"); } List<org.geomajas.geometry.Geometry> result = new ArrayList<org.geomajas.geometry.Geometry>(); for (Geometry clientGeometry : clientGeometries) { result.add(converter.toDto(new ConvexHull(converter.toInternal(clientGeometry)).getConvexHull())); } response.setGeometries(result); }  @Override GeometryConvexHullRequest getEmptyCommandRequest(); @Override GeometryConvexHullResponse getEmptyCommandResponse(); @Override void execute(GeometryConvexHullRequest request, GeometryConvexHullResponse response);  }
@Test public void doesConvexTest() throws GeomajasException { List<Geometry> geometries = new ArrayList<Geometry>(); geometries.add(createComplexPoly()); geometries.add(createThreePointsLine()); GeometryConvexHullRequest request = new GeometryConvexHullRequest(); request.setGeometries(geometries); GeometryConvexHullResponse response = (GeometryConvexHullResponse) dispatcher.execute( GeometryConvexHullRequest.COMMAND, request, null, "en"); List<Geometry> result = response.getGeometries(); Assert.assertEquals(2, result.size()); Assert.assertEquals(geometries.get(0).getGeometries()[0].getCoordinates().length, result.get(0).getGeometries()[0].getCoordinates().length + 1); Assert.assertEquals(geometries.get(1).getCoordinates().length, result.get(1).getGeometries()[0].getCoordinates().length - 1); }
@Test public void doesntConvexTest() throws GeomajasException { List<Geometry> geometries = new ArrayList<Geometry>(); geometries.add(createSimplePoly()); geometries.add(createTwoPointsLine()); geometries.add(createPoint()); GeometryConvexHullRequest request = new GeometryConvexHullRequest(); request.setGeometries(geometries); GeometryConvexHullResponse response = (GeometryConvexHullResponse) dispatcher.execute( GeometryConvexHullRequest.COMMAND, request, null, "en"); List<Geometry> result = response.getGeometries(); Assert.assertEquals(3, result.size()); Assert.assertEquals(geometries.get(0).getGeometries()[0].getCoordinates().length, result.get(0).getGeometries()[0].getCoordinates().length); Assert.assertEquals(geometries.get(1).getCoordinates().length, result.get(1).getCoordinates().length); Assert.assertEquals(geometries.get(2).getCoordinates().length, result.get(2).getCoordinates().length); }