use of com.revolsys.geometry.operation.valid.IsValidOp in project com.revolsys.open by revolsys.
the class PolygonGenerator method newGeometry.
/**
* As the user increases the number of points, the probability of creating a random valid polygon decreases.
* Please take not of this when selecting the generation style, and the number of points.
*
* May return null if a geometry could not be created.
*
* @see #getNumberPoints()
* @see #setNumberPoints(int)
* @see #getGenerationAlgorithm()
* @see #setGenerationAlgorithm(int)
*
* @see #BOX
* @see #ARC
*
* @see com.revolsys.geometry.testold.generator.GeometryGenerator#newIterator()
*
* @throws IllegalStateException When the alg is not valid or the number of points is invalid
* @throws NullPointerException when either the Geometry Factory, or the Bounding Box are undefined.
*/
@Override
public Geometry newGeometry() {
if (this.geometryFactory == null) {
throw new NullPointerException("GeometryFactoryI is not declared");
}
if (this.boundingBox == null || this.boundingBox.isEmpty()) {
throw new NullPointerException("Bounding Box is not declared");
}
if (this.numberPoints < 4) {
throw new IllegalStateException("Too few points");
}
// base x
final double x = this.boundingBox.getMinX();
final double dx = this.boundingBox.getMaxX() - x;
// base y
final double y = this.boundingBox.getMinY();
final double dy = this.boundingBox.getMaxY() - y;
Polygon p = null;
for (int i = 0; i < RUNS; i++) {
switch(getGenerationAlgorithm()) {
case BOX:
p = newBox(x, dx, y, dy, this.numberHoles, this.numberPoints, this.geometryFactory);
break;
case ARC:
p = newArc(x, dx, y, dy, this.numberHoles, this.numberPoints, this.geometryFactory);
break;
default:
throw new IllegalStateException("Invalid Alg. Specified");
}
final IsValidOp valid = new IsValidOp(p);
if (valid.isValid()) {
return p;
}
}
return null;
}
use of com.revolsys.geometry.operation.valid.IsValidOp in project com.revolsys.open by revolsys.
the class IsValidTest method testNaNCoordinate.
public void testNaNCoordinate() throws Exception {
final Point badCoord = new PointDoubleXY(1.0, Double.NaN);
final Point[] pts = { new PointDoubleXY(0.0, 0.0), badCoord };
final Geometry line = this.geometryFactory.lineString(pts);
final IsValidOp isValidOp = new IsValidOp(line);
final boolean valid = isValidOp.isValid();
final GeometryValidationError err = isValidOp.getValidationError();
final Point errCoord = err.getErrorPoint();
assertTrue(err instanceof CoordinateNaNError);
assertTrue(Double.isNaN(errCoord.getY()));
assertEquals(false, valid);
}
use of com.revolsys.geometry.operation.valid.IsValidOp in project com.revolsys.open by revolsys.
the class ValidSelfTouchingRingFormingHoleTest method checkIsValidSTR.
private void checkIsValidSTR(final String wkt, final boolean expected) {
final Geometry geom = fromWKT(wkt);
final IsValidOp validator = new IsValidOp(geom);
validator.setSelfTouchingRingFormingHoleValid(true);
final boolean isValid = validator.isValid();
assertTrue(isValid == expected);
}
use of com.revolsys.geometry.operation.valid.IsValidOp in project com.revolsys.open by revolsys.
the class ValidSelfTouchingRingFormingHoleTest method checkIsValidDefault.
private void checkIsValidDefault(final String wkt, final boolean expected) {
final Geometry geom = fromWKT(wkt);
final IsValidOp validator = new IsValidOp(geom);
final boolean isValid = validator.isValid();
assertTrue(isValid == expected);
}
use of com.revolsys.geometry.operation.valid.IsValidOp in project com.revolsys.open by revolsys.
the class LineStringGenerator method newGeometry.
/**
* As the user increases the number of points, the probability of creating a random valid linestring decreases.
* Please take not of this when selecting the generation style, and the number of points.
*
* May return null if a geometry could not be created.
*
* @see #getNumberPoints()
* @see #setNumberPoints(int)
* @see #getGenerationAlgorithm()
* @see #setGenerationAlgorithm(int)
*
* @see #VERT
* @see #HORZ
* @see #ARC
*
* @see com.revolsys.geometry.testold.generator.GeometryGenerator#newIterator()
*
* @throws IllegalStateException When the alg is not valid or the number of points is invalid
* @throws NullPointerException when either the Geometry Factory, or the Bounding Box are undefined.
*/
@Override
public Geometry newGeometry() {
if (this.geometryFactory == null) {
throw new NullPointerException("GeometryFactoryI is not declared");
}
if (this.boundingBox == null || this.boundingBox.isEmpty()) {
throw new NullPointerException("Bounding Box is not declared");
}
if (this.numberPoints < 2) {
throw new IllegalStateException("Too few points");
}
final Point[] coords = new Point[this.numberPoints];
// base x
final double x = this.boundingBox.getMinX();
final double dx = this.boundingBox.getMaxX() - x;
// base y
final double y = this.boundingBox.getMinY();
final double dy = this.boundingBox.getMaxY() - y;
for (int i = 0; i < RUNS; i++) {
switch(getGenerationAlgorithm()) {
case VERT:
fillVert(x, dx, y, dy, coords, this.geometryFactory);
break;
case HORZ:
fillHorz(x, dx, y, dy, coords, this.geometryFactory);
break;
case ARC:
fillArc(x, dx, y, dy, coords, this.geometryFactory);
break;
default:
throw new IllegalStateException("Invalid Alg. Specified");
}
final LineString ls = this.geometryFactory.lineString(coords);
final IsValidOp valid = new IsValidOp(ls);
if (valid.isValid()) {
return ls;
}
}
return null;
}
Aggregations