use of com.revolsys.geometry.model.segment.LineSegmentDoubleGF 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.LineSegmentDoubleGF 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.LineSegmentDoubleGF 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;
}
use of com.revolsys.geometry.model.segment.LineSegmentDoubleGF in project com.revolsys.open by revolsys.
the class GeometryGraph method addEdge.
public void addEdge(final Node<LineSegment> fromNode, final Node<LineSegment> toNode) {
final LineSegment lineSegment = new LineSegmentDoubleGF(fromNode, toNode);
addEdge(lineSegment, fromNode, toNode);
}
use of com.revolsys.geometry.model.segment.LineSegmentDoubleGF in project com.revolsys.open by revolsys.
the class GeometryGraph method intersects.
public boolean intersects(final LineString line) {
BoundingBox boundingBox = line.getBoundingBox();
final double scaleXY = getGeometryFactory().getScaleXY();
double maxDistance = 0;
if (scaleXY > 0) {
maxDistance = 1 / scaleXY;
}
boundingBox = boundingBox.expand(maxDistance);
if (boundingBox.intersects(this.boundingBox)) {
final LineString points = line;
final int numPoints = points.getVertexCount();
final Point fromPoint = points.getPoint(0);
final Point toPoint = points.getPoint(numPoints - 1);
Point previousPoint = fromPoint;
for (int i = 1; i < numPoints; i++) {
final Point nextPoint = points.getPoint(i);
final LineSegment line1 = new LineSegmentDoubleGF(previousPoint, nextPoint);
final List<Edge<LineSegment>> edges = EdgeLessThanDistance.getEdges(this, line1, maxDistance);
for (final Edge<LineSegment> edge2 : edges) {
final LineSegment line2 = edge2.getObject();
final Geometry intersections = line1.getIntersection(line2);
for (final Point intersection : intersections.vertices()) {
if (intersection.equals(fromPoint) || intersection.equals(toPoint)) {
// Point intersection, make sure it's not at the start
final Node<LineSegment> node = findNode(intersection);
final int degree = node.getDegree();
if (isStartPoint(node)) {
if (degree > 2) {
// into account loops
return true;
}
} else if (degree > 1) {
// Intersection not at the start/end of the other line
return true;
}
} else {
// Intersection not at the start/end of the line
return true;
}
}
for (final Point point : line1.vertices()) {
if (line2.distancePoint(point) < maxDistance) {
if (point.equals(fromPoint) || point.equals(toPoint)) {
// Point intersection, make sure it's not at the start
final double maxDistance1 = maxDistance;
for (final Node<LineSegment> node : this.getNodes(point, maxDistance1)) {
final int degree = node.getDegree();
if (isStartPoint(node)) {
if (degree > 2) {
// into account loops
return true;
}
} else if (degree > 1) {
// Intersection not at the start/end of the other line
return true;
}
}
} else {
// Intersection not at the start/end of the line
return true;
}
}
}
}
previousPoint = nextPoint;
}
}
return false;
}
Aggregations