use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class GeometricShapeFactory method newRectangle.
/**
* Creates a rectangular {@link Polygon}.
*
* @return a rectangular Polygon
*/
public Polygon newRectangle() {
int i;
int ipt = 0;
int nSide = this.vertexCount / 4;
if (nSide < 1) {
nSide = 1;
}
final double XsegLen = this.dim.getEnvelope().getWidth() / nSide;
final double YsegLen = this.dim.getEnvelope().getHeight() / nSide;
final Point[] pts = new Point[4 * nSide + 1];
final BoundingBox env = this.dim.getEnvelope();
for (i = 0; i < nSide; i++) {
final double x = env.getMinX() + i * XsegLen;
final double y = env.getMinY();
pts[ipt++] = newPoint(x, y);
}
for (i = 0; i < nSide; i++) {
final double x = env.getMaxX();
final double y = env.getMinY() + i * YsegLen;
pts[ipt++] = newPoint(x, y);
}
for (i = 0; i < nSide; i++) {
final double x = env.getMaxX() - i * XsegLen;
final double y = env.getMaxY();
pts[ipt++] = newPoint(x, y);
}
for (i = 0; i < nSide; i++) {
final double x = env.getMinX();
final double y = env.getMaxY() - i * YsegLen;
pts[ipt++] = newPoint(x, y);
}
pts[ipt++] = pts[0];
final LinearRing ring = this.geomFact.linearRing(pts);
final Polygon poly = this.geomFact.polygon(ring);
return poly;
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class GeometricShapeFactory method newArcPolygon.
/**
* Creates an elliptical arc polygon.
* The polygon is formed from the specified arc of an ellipse
* and the two radii connecting the endpoints to the centre of the ellipse.
*
* @param startAng start angle in radians
* @param angExtent size of angle in radians
* @return an elliptical arc polygon
*/
public Polygon newArcPolygon(final double startAng, final double angExtent) {
final BoundingBox env = this.dim.getEnvelope();
final double xRadius = env.getWidth() / 2.0;
final double yRadius = env.getHeight() / 2.0;
final double centreX = env.getMinX() + xRadius;
final double centreY = env.getMinY() + yRadius;
double angSize = angExtent;
if (angSize <= 0.0 || angSize > 2 * Math.PI) {
angSize = 2 * Math.PI;
}
final double angInc = angSize / (this.vertexCount - 1);
// double check = angInc * nPts;
// double checkEndAng = startAng + check;
final Point[] pts = new Point[this.vertexCount + 2];
int iPt = 0;
pts[iPt++] = newPoint(centreX, centreY);
for (int i = 0; i < this.vertexCount; i++) {
final double ang = startAng + angInc * i;
final double x = xRadius * Math.cos(ang) + centreX;
final double y = yRadius * Math.sin(ang) + centreY;
pts[iPt++] = newPoint(x, y);
}
pts[iPt++] = newPoint(centreX, centreY);
final LinearRing ring = this.geomFact.linearRing(pts);
final Polygon poly = this.geomFact.polygon(ring);
return poly;
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class GeometricShapeFactory method newSupercircle.
/**
* Creates a supercircular {@link Polygon}
* of a given positive power.
*
* @return a supercircle
*/
public Polygon newSupercircle(final double power) {
final double recipPow = 1.0 / power;
final double radius = this.dim.getMinSize() / 2;
final Point centre = this.dim.getCentre();
final double r4 = Math.pow(radius, power);
final double y0 = radius;
final double xyInt = Math.pow(r4 / 2, recipPow);
final int nSegsInOct = this.vertexCount / 8;
final int totPts = nSegsInOct * 8 + 1;
final Point[] pts = new Point[totPts];
final double xInc = xyInt / nSegsInOct;
for (int i = 0; i <= nSegsInOct; i++) {
double x = 0.0;
double y = y0;
if (i != 0) {
x = xInc * i;
final double x4 = Math.pow(x, power);
y = Math.pow(r4 - x4, recipPow);
}
pts[i] = coordTrans(x, y, centre);
pts[2 * nSegsInOct - i] = coordTrans(y, x, centre);
pts[2 * nSegsInOct + i] = coordTrans(y, -x, centre);
pts[4 * nSegsInOct - i] = coordTrans(x, -y, centre);
pts[4 * nSegsInOct + i] = coordTrans(-x, -y, centre);
pts[6 * nSegsInOct - i] = coordTrans(-y, -x, centre);
pts[6 * nSegsInOct + i] = coordTrans(-y, x, centre);
pts[8 * nSegsInOct - i] = coordTrans(-x, y, centre);
}
pts[pts.length - 1] = pts[0];
final LinearRing ring = this.geomFact.linearRing(pts);
final Polygon poly = this.geomFact.polygon(ring);
return poly;
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class IsValidOp method checkShellsNotNested.
/**
* Tests that no element polygon is wholly in the interior of another element polygon.
* <p>
* Preconditions:
* <ul>
* <li>shells do not partially overlap
* <li>shells do not touch along an edge
* <li>no duplicate rings exist
* </ul>
* This routine relies on the fact that while polygon shells may touch at one or
* more vertices, they cannot touch at ALL vertices.
*/
private boolean checkShellsNotNested(final Polygonal polygonal, final GeometryGraph graph) {
boolean valid = true;
final List<Polygon> polygons = polygonal.getPolygons();
final int polygonCount = polygons.size();
for (int i = 0; i < polygonCount; i++) {
final Polygon polygon1 = polygons.get(i);
final LinearRing shell = polygon1.getShell();
for (int j = 0; j < polygonCount; j++) {
if (i != j) {
final Polygon polygon2 = polygons.get(j);
valid &= checkShellNotNested(shell, polygon2, graph);
if (isErrorReturn()) {
return false;
}
}
}
}
return valid;
}
use of com.revolsys.geometry.model.Polygon in project com.revolsys.open by revolsys.
the class IsValidOp method checkValidMultiPolygon.
private boolean checkValidMultiPolygon(final Polygonal polygonal) {
boolean valid = true;
for (final Polygon polygon : polygonal.polygons()) {
valid &= checkClosedRings(polygon);
if (isErrorReturn()) {
return false;
}
}
final GeometryGraph graph = new GeometryGraph(0, polygonal);
valid &= checkTooFewPoints(graph);
if (isErrorReturn()) {
return false;
}
valid &= checkConsistentArea(graph);
if (isErrorReturn()) {
return false;
}
if (!this.isSelfTouchingRingFormingHoleValid) {
valid &= checkNoSelfIntersectingRings(graph);
if (isErrorReturn()) {
return false;
}
}
for (final Polygon polygon : polygonal.getPolygons()) {
valid &= checkHolesInShell(polygon, graph);
if (isErrorReturn()) {
return false;
}
}
for (final Polygon polygon : polygonal.getPolygons()) {
valid &= checkHolesNotNested(polygon, graph);
if (isErrorReturn()) {
return false;
}
}
valid &= checkShellsNotNested(polygonal, graph);
if (isErrorReturn()) {
return false;
}
valid &= checkConnectedInteriors(graph);
return valid;
}
Aggregations