use of com.revolsys.geometry.model.segment.LineSegmentDouble in project com.revolsys.open by revolsys.
the class GeometricShapeBuilder method getSquareBaseLine.
public LineSegment getSquareBaseLine() {
final double radius = getRadius();
final Point centre = getCentre();
final double x1 = centre.getX() - radius;
final double y1 = centre.getY() - radius;
final double x2 = centre.getX() + radius;
return new LineSegmentDouble(2, x1, y1, x2, y1);
}
use of com.revolsys.geometry.model.segment.LineSegmentDouble in project com.revolsys.open by revolsys.
the class TaggedLineStringSimplifier method flatten.
/**
* Flattens a section of the taggedLine between
* indexes <code>start</code> and <code>end</code>,
* replacing them with a taggedLine between the endpoints.
* The input and output indexes are updated
* to reflect this.
*
* @param start the start index of the flattened section
* @param end the end index of the flattened section
* @return the new segment created
*/
private LineSegment flatten(final int start, final int end) {
// make a new segment for the simplified geometry
final Point p0 = this.line.getVertex(start);
final Point p1 = this.line.getVertex(end);
final LineSegment newSeg = new LineSegmentDouble(p0, p1);
// update the indexes
remove(this.taggedLine, start, end);
this.outputIndex.add(newSeg);
return newSeg;
}
use of com.revolsys.geometry.model.segment.LineSegmentDouble in project com.revolsys.open by revolsys.
the class LineSegmentTest method testDistancePointLinePerpendicular.
public void testDistancePointLinePerpendicular() {
final LineSegmentDouble segment = new LineSegmentDouble(2, 0.0, 0, 1.0, 0);
Assert.assertEquals(0.5, segment.distancePerpendicular(new PointDoubleXY(0.5, 0.5)), 0.000001);
Assert.assertEquals(0.5, segment.distancePerpendicular(new PointDoubleXY(3.5, 0.5)), 0.000001);
Assert.assertEquals(0.707106, segment.distancePerpendicular(new PointDoubleXY(1.0, 0)), 0.000001);
}
use of com.revolsys.geometry.model.segment.LineSegmentDouble in project com.revolsys.open by revolsys.
the class Polygon method getPointWithin.
@Override
default Point getPointWithin() {
if (isEmpty()) {
final GeometryFactory geometryFactory = getGeometryFactory();
return geometryFactory.point();
} else {
Point centroid = null;
try {
centroid = getCentroid();
if (centroid.within(this)) {
return centroid;
}
} catch (final TopologyException e) {
}
if (centroid != null) {
final BoundingBox boundingBox = getBoundingBox();
final double x1 = centroid.getX();
final double y1 = centroid.getY();
for (final double x2 : new double[] { boundingBox.getMinX(), boundingBox.getMaxX() }) {
for (final double y2 : new double[] { boundingBox.getMinY(), boundingBox.getMaxY() }) {
final LineSegment line = new LineSegmentDouble(2, x1, y1, x2, y2);
try {
final Geometry intersection = intersection(line);
if (!intersection.isEmpty()) {
return intersection.getPointWithin();
}
} catch (final TopologyException e) {
}
}
}
}
return getPoint();
}
}
use of com.revolsys.geometry.model.segment.LineSegmentDouble in project com.revolsys.open by revolsys.
the class SegmentPointComparatorFullTest method checkSegment.
private void checkSegment(final double x, final double y) {
final Point seg0 = new PointDoubleXY(0, 0);
final Point seg1 = new PointDoubleXY(x, y);
final LineSegment seg = new LineSegmentDouble(seg0, seg1);
for (int i = 0; i < 4; i++) {
final double dist = i;
final double gridSize = 1;
checkPointsAtDistance(seg, dist, dist + 1.0 * gridSize);
checkPointsAtDistance(seg, dist, dist + 2.0 * gridSize);
checkPointsAtDistance(seg, dist, dist + 3.0 * gridSize);
checkPointsAtDistance(seg, dist, dist + 4.0 * gridSize);
}
}
Aggregations