use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class AbstractOverlay method newXorLine.
protected LineString newXorLine(final GeometryFactory geometryFactory, final Point c0, final Point p1) {
final Viewport2D viewport = getViewport();
final GeometryFactory viewportGeometryFactory = viewport.getGeometryFactory2dFloating();
final LineSegment line = viewportGeometryFactory.lineSegment(c0, p1);
final double length = line.getLength();
if (length > 0) {
final double cursorRadius = viewport.getModelUnitsPerViewUnit() * 6;
final Point newC1 = line.pointAlongOffset((length - cursorRadius) / length, 0);
return geometryFactory.lineString(c0, newC1);
} else {
return null;
}
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class EditRecordGeometryOverlay method getClosestPoint.
public Point getClosestPoint(final GeometryFactory geometryFactory, final LineSegment closestSegment, final Point point, final double maxDistance) {
final LineSegment segment = closestSegment.convertGeometry(geometryFactory);
final Point fromPoint = segment.getPoint(0);
final Point toPoint = segment.getPoint(1);
final double fromPointDistance = point.distancePoint(fromPoint);
final double toPointDistance = point.distancePoint(toPoint);
if (fromPointDistance < maxDistance) {
if (fromPointDistance <= toPointDistance) {
return fromPoint;
} else {
return toPoint;
}
} else if (toPointDistance <= maxDistance) {
return toPoint;
} else {
final Point pointOnLine = segment.project(point);
return geometryFactory.point(pointOnLine);
}
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class MapRulerBorder method paintVerticalRuler.
private <Q extends Quantity<Q>> void paintVerticalRuler(final Graphics2D g, final BoundingBox boundingBox, final Unit<Q> displayUnit, final List<Unit<Q>> steps, final int x, final int y, final int width, final int height, final boolean left) {
final AffineTransform transform = g.getTransform();
final Shape clip = g.getClip();
try {
int textX;
LineSegment line;
final double y1 = boundingBox.getMinY();
final double y2 = boundingBox.getMaxY();
double x0;
if (left) {
g.translate(0, -this.rulerSize);
textX = this.labelHeight;
x0 = boundingBox.getMinX();
} else {
g.translate(width - this.rulerSize, -this.rulerSize);
textX = this.rulerSize - 3;
x0 = boundingBox.getMaxX();
}
line = new LineSegmentDoubleGF(boundingBox.getGeometryFactory(), 2, x0, y1, x0, y2);
line = line.convertGeometry(this.rulerGeometryFactory);
g.setClip(0, this.rulerSize * 2, this.rulerSize, height - 2 * this.rulerSize);
final double mapSize = boundingBox.getHeight();
final double viewSize = this.viewport.getViewHeightPixels();
final double minY = line.getY(0);
double maxY = line.getY(1);
if (maxY > this.areaMaxY) {
maxY = this.areaMaxY;
}
if (mapSize > 0 && viewSize > 0) {
final Unit<Q> screenToModelUnit = this.viewport.getViewToModelUnit(this.baseUnit);
final Quantity<Q> modelUnitsPer6ViewUnits = Quantities.getQuantity(6, screenToModelUnit);
final int stepLevel = getStepLevel(steps, modelUnitsPer6ViewUnits);
final Unit<Q> stepUnit = steps.get(stepLevel);
final double step = toBaseUnit(Quantities.getQuantity(1, stepUnit));
final double pixelsPerUnit = viewSize / mapSize;
final long minIndex = (long) Math.ceil(this.areaMinY / step);
final long maxIndex = (long) Math.ceil(maxY / step);
long startIndex = (long) Math.floor(minY / step);
if (startIndex < minIndex) {
startIndex = minIndex;
}
for (long index = startIndex; index <= maxIndex; index++) {
final Quantity<Q> measureValue = Quantities.getQuantity(index, stepUnit);
final double value = toBaseUnit(measureValue);
final double displayValue = QuantityType.doubleValue(measureValue, displayUnit);
final int pixel = (int) ((value - minY) * pixelsPerUnit);
boolean found = false;
int barSize = 4;
g.setColor(Color.LIGHT_GRAY);
for (int i = 0; !found && i < stepLevel; i++) {
final Unit<Q> scaleUnit = steps.get(i);
final double stepValue = QuantityType.doubleValue(measureValue, scaleUnit);
if (Math.abs(stepValue - Math.round(stepValue)) < 0.000001) {
barSize = 4 + (int) ((this.rulerSize - 4) * (((double) stepLevel - i) / stepLevel));
found = true;
final AffineTransform transform2 = g.getTransform();
try {
g.translate(textX, height - pixel - 3);
g.rotate(-Math.PI / 2);
drawLabel(g, 0, 0, displayUnit, displayValue, scaleUnit);
} finally {
g.setTransform(transform2);
}
}
}
if (left) {
g.drawLine(this.rulerSize - 1 - barSize, height - pixel, this.rulerSize - 1, height - pixel);
} else {
g.drawLine(0, height - pixel, barSize, height - pixel);
}
}
}
} finally {
g.setTransform(transform);
g.setClip(clip);
}
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class MapRulerBorder method paintHorizontalRuler.
private <Q extends Quantity<Q>> void paintHorizontalRuler(final Graphics2D g, final BoundingBox boundingBox, final Unit<Q> displayUnit, final List<Unit<Q>> steps, final int x, final int y, final int width, final int height, final boolean top) {
final AffineTransform transform = g.getTransform();
final Shape clip = g.getClip();
try {
int textY;
LineSegment line;
final double x1 = boundingBox.getMinX();
final double x2 = boundingBox.getMaxX();
double y0;
if (top) {
g.translate(this.rulerSize, 0);
textY = this.labelHeight;
y0 = boundingBox.getMaxY();
} else {
g.translate(this.rulerSize, height - this.rulerSize);
textY = this.rulerSize - 3;
y0 = boundingBox.getMinY();
}
line = new LineSegmentDoubleGF(boundingBox.getGeometryFactory(), 2, x1, y0, x2, y0);
line = line.convertGeometry(this.rulerGeometryFactory);
g.setClip(0, 0, width - 2 * this.rulerSize, this.rulerSize);
final double mapSize = boundingBox.getWidth();
final double viewSize = this.viewport.getViewWidthPixels();
final double minX = line.getX(0);
double maxX = line.getX(1);
if (maxX > this.areaMaxX) {
maxX = this.areaMaxX;
}
if (mapSize > 0 && viewSize > 0) {
final Unit<Q> screenToModelUnit = this.viewport.getViewToModelUnit(this.baseUnit);
final Quantity<Q> modelUnitsPer6ViewUnits = Quantities.getQuantity(6, screenToModelUnit);
final int stepLevel = getStepLevel(steps, modelUnitsPer6ViewUnits);
final Unit<Q> stepUnit = steps.get(stepLevel);
final double step = toBaseUnit(Quantities.getQuantity(1, stepUnit));
final double pixelsPerUnit = viewSize / mapSize;
final long minIndex = (long) Math.floor(this.areaMinX / step);
final long maxIndex = (long) Math.floor(maxX / step);
long startIndex = (long) Math.floor(minX / step);
if (startIndex < minIndex) {
startIndex = minIndex;
}
for (long index = startIndex; index <= maxIndex; index++) {
final Quantity<Q> measureValue = Quantities.getQuantity(index, stepUnit);
final double value = toBaseUnit(measureValue);
final double displayValue = QuantityType.doubleValue(measureValue, displayUnit);
final int pixel = (int) ((value - minX) * pixelsPerUnit);
boolean found = false;
int barSize = 4;
g.setColor(Color.LIGHT_GRAY);
for (int i = 0; !found && i < stepLevel; i++) {
final Unit<Q> scaleUnit = steps.get(i);
final double stepValue = QuantityType.doubleValue(measureValue, scaleUnit);
if (Math.abs(stepValue - Math.round(stepValue)) < 0.000001) {
barSize = 4 + (int) ((this.rulerSize - 4) * (((double) stepLevel - i) / stepLevel));
found = true;
drawLabel(g, pixel + 3, textY, displayUnit, displayValue, scaleUnit);
}
}
if (top) {
g.drawLine(pixel, this.rulerSize - 1 - barSize, pixel, this.rulerSize - 1);
} else {
g.drawLine(pixel, 0, pixel, barSize);
}
}
}
} finally {
g.setTransform(transform);
g.setClip(clip);
}
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class TriangulatedIrregularNetwork method getElevation.
default double getElevation(Point point) {
point = convertGeometry(point);
final List<Triangle> triangles = getTriangles(point);
for (final Triangle triangle : triangles) {
final Point t0 = triangle.getP0();
if (t0.equals(point)) {
return t0.getZ();
}
final Point t1 = triangle.getP1();
if (t1.equals(point)) {
return t1.getZ();
}
final Point t2 = triangle.getP2();
if (t2.equals(point)) {
return t2.getZ();
}
Point closestCorner = t0;
LineSegment oppositeEdge = new LineSegmentDoubleGF(t1, t2);
double closestDistance = point.distancePoint(closestCorner);
final double t1Distance = point.distancePoint(t1);
if (closestDistance > t1Distance) {
closestCorner = t1;
oppositeEdge = new LineSegmentDoubleGF(t2, t0);
closestDistance = t1Distance;
}
if (closestDistance > point.distancePoint(t2)) {
closestCorner = t2;
oppositeEdge = new LineSegmentDoubleGF(t0, t1);
}
LineSegment segment = new LineSegmentDoubleGF(closestCorner, point).extend(0, t0.distancePoint(t1) + t1.distancePoint(t2) + t0.distancePoint(t2));
final Geometry intersectCoordinates = oppositeEdge.getIntersection(segment);
if (intersectCoordinates.getVertexCount() > 0) {
final Point intersectPoint = intersectCoordinates.getVertex(0);
final double z = oppositeEdge.getElevation(intersectPoint);
if (!Double.isNaN(z)) {
final double x = intersectPoint.getX();
final double y = intersectPoint.getY();
final Point end = new PointDoubleXYZ(x, y, z);
segment = new LineSegmentDoubleGF(t0, end);
return segment.getElevation(point);
}
}
}
return Double.NaN;
}
Aggregations