use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class MeasureOverlay method modeMeasureClick.
protected boolean modeMeasureClick(final MouseEvent event) {
final int modifiers = event.getModifiersEx();
if (modifiers == 0 && event.getButton() == MouseEvent.BUTTON1) {
if (isOverlayAction(MEASURE)) {
final int clickCount = event.getClickCount();
Point point = getSnapPoint();
if (point == null) {
point = getPoint(event);
}
if (clickCount == 1) {
final Geometry measureGeometry = getMeasureGeometry();
final GeometryFactory geometryFactory = getGeometryFactory2d();
if (measureGeometry.isEmpty()) {
setMeasureGeometry(point);
} else if (measureGeometry instanceof Point) {
final Point from = (Point) measureGeometry;
if (!from.equals(point)) {
final LineString line = geometryFactory.lineString(from, point);
setMeasureGeometry(line);
}
} else if (this.measureDataType == DataTypes.LINE_STRING) {
if (measureGeometry instanceof LineString) {
LineString line = (LineString) measureGeometry;
final Point to = line.getToPoint();
if (!to.equals(point)) {
final Point newPoint = point;
line = line.editLine(editor -> editor.appendVertex(newPoint));
setMeasureGeometry(line);
}
}
} else {
if (measureGeometry instanceof LineString) {
LineString line = (LineString) measureGeometry;
final Point from = line.getToVertex(0);
if (!from.equals(point)) {
final Point newPoint = point;
line = line.editLine(editor -> editor.appendVertex(newPoint));
setMeasureGeometry(line);
}
if (line.getVertexCount() > 2) {
if (!line.isClosed()) {
final Vertex firstPoint = line.getVertex(0);
line = line.editLine(editor -> editor.appendVertex(firstPoint));
}
setMeasureGeometry(geometryFactory.polygon(line));
}
} else if (measureGeometry instanceof Polygon) {
final Polygon polygon = (Polygon) measureGeometry;
final Point newPoint = point;
setMeasureGeometry(polygon.edit(editor -> editor.appendVertex(new int[] { 0 }, newPoint)));
}
}
event.consume();
repaint();
return true;
}
}
}
return false;
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class SierpinskiCarpetBuilder method getGeometry.
@Override
public Geometry getGeometry() {
final int level = recursionLevelForSize(this.numPts);
final LineSegment baseLine = getSquareBaseLine();
final Point origin = baseLine.getPoint(0);
final List<LinearRing> rings = new ArrayList<>();
final LinearRing shell = ((Polygon) getSquareExtent().toGeometry()).getShell();
rings.add(shell);
addHoles(level, origin.getX(), origin.getY(), getDiameter(), rings);
return this.geometryFactory.polygon(shell);
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class DistanceWithLocation method computeContainmentDistance.
private void computeContainmentDistance(final int polyGeomIndex, final GeometryLocation[] locPtPoly) {
Geometry geometry1;
Geometry geometry2;
if (polyGeomIndex == 0) {
geometry1 = this.geometry1;
geometry2 = this.geometry2;
} else {
geometry1 = this.geometry2;
geometry2 = this.geometry1;
}
final boolean flip = polyGeomIndex == 0;
final List<Polygon> polys = geometry1.getGeometries(Polygon.class);
if (polys.size() > 0) {
final List<GeometryLocation> insideLocs = ConnectedElementLocationFilter.getLocations(geometry2);
computeContainmentDistance(insideLocs, polys, locPtPoly);
if (this.minDistance <= this.terminateDistance) {
// this assignment is determined by the order of the args in the
// computeInside call above
setMinDistanceLocations(locPtPoly[0], locPtPoly[1], flip);
return;
}
}
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class GeometryTransformer method transformMultiPolygon.
protected Geometry transformMultiPolygon(final Polygonal polygonal, final Geometry parent) {
final List<Geometry> transGeomList = new ArrayList<>();
for (final Polygon polygon : polygonal.polygons()) {
final Geometry transformGeom = transformPolygon(polygon, polygonal);
if (transformGeom == null) {
continue;
}
if (transformGeom.isEmpty()) {
continue;
}
transGeomList.add(transformGeom);
}
return this.factory.buildGeometry(transGeomList);
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class SineStarFactory method newSineStar.
/**
* Generates the geometry for the sine star
*
* @return the geometry representing the sine star
*/
public Geometry newSineStar() {
final BoundingBox env = this.dim.getEnvelope();
final double radius = env.getWidth() / 2.0;
double armRatio = this.armLengthRatio;
if (armRatio < 0.0) {
armRatio = 0.0;
}
if (armRatio > 1.0) {
armRatio = 1.0;
}
final double armMaxLen = armRatio * radius;
final double insideRadius = (1 - armRatio) * radius;
final double centreX = env.getMinX() + radius;
final double centreY = env.getMinY() + radius;
final double[] coordinates = new double[(this.vertexCount + 1) * 2];
int coordinateIndex = 0;
for (int i = 0; i < this.vertexCount; i++) {
// the fraction of the way thru the current arm - in [0,1]
final double ptArcFrac = i / (double) this.vertexCount * this.numArms;
final double armAngFrac = ptArcFrac - Math.floor(ptArcFrac);
// the angle for the current arm - in [0,2Pi]
// (each arm is a complete sine wave cycle)
final double armAng = 2 * Math.PI * armAngFrac;
// the current length of the arm
final double armLenFrac = (Math.cos(armAng) + 1.0) / 2.0;
// the current radius of the curve (core + arm)
final double curveRadius = insideRadius + armMaxLen * armLenFrac;
// the current angle of the curve
final double ang = i * (2 * Math.PI / this.vertexCount);
final double x = curveRadius * Math.cos(ang) + centreX;
final double y = curveRadius * Math.sin(ang) + centreY;
coordinates[coordinateIndex++] = this.geomFact.makeXyPrecise(x);
coordinates[coordinateIndex++] = this.geomFact.makeXyPrecise(y);
}
final LinearRing ring = this.geomFact.linearRing(2, coordinates);
final Polygon poly = this.geomFact.polygon(ring);
return poly;
}
Aggregations