Class HotPixel
- java.lang.Object
-
- org.locationtech.jts.noding.snapround.HotPixel
-
public class HotPixel extends java.lang.ObjectImplements a "hot pixel" as used in the Snap Rounding algorithm. A hot pixel contains the interior of the tolerance square and the boundary minus the top and right segments.The hot pixel operations are all computed in the integer domain to avoid rounding problems.
- Version:
- 1.7
-
-
Field Summary
Fields Modifier and Type Field Description private Coordinate[]cornerThe corners of the hot pixel, in the order: 10 23private LineIntersectorliprivate doublemaxxprivate doublemaxyprivate doubleminxprivate doubleminyprivate CoordinateoriginalPtprivate Coordinatep0Scaledprivate Coordinatep1Scaledprivate Coordinateptprivate CoordinateptScaledprivate static doubleSAFE_ENV_EXPANSION_FACTORprivate EnvelopesafeEnvprivate doublescaleFactor
-
Constructor Summary
Constructors Constructor Description HotPixel(Coordinate pt, double scaleFactor, LineIntersector li)Creates a new hot pixel, using a given scale factor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddSnappedNode(NodedSegmentString segStr, int segIndex)Adds a new node (equal to the snap pt) to the specified segment if the segment passes through the hot pixelprivate voidcopyScaled(Coordinate p, Coordinate pScaled)CoordinategetCoordinate()Gets the coordinate this hot pixel is based at.EnvelopegetSafeEnvelope()Returns a "safe" envelope that is guaranteed to contain the hot pixel.private voidinitCorners(Coordinate pt)booleanintersects(Coordinate p0, Coordinate p1)Tests whether the line segment (p0-p1) intersects this hot pixel.private booleanintersectsPixelClosure(Coordinate p0, Coordinate p1)Test whether the given segment intersects the closure of this hot pixel.private booleanintersectsScaled(Coordinate p0, Coordinate p1)private booleanintersectsToleranceSquare(Coordinate p0, Coordinate p1)Tests whether the segment p0-p1 intersects the hot pixel tolerance square.private doublescale(double val)
-
-
-
Field Detail
-
li
private LineIntersector li
-
pt
private Coordinate pt
-
originalPt
private Coordinate originalPt
-
ptScaled
private Coordinate ptScaled
-
p0Scaled
private Coordinate p0Scaled
-
p1Scaled
private Coordinate p1Scaled
-
scaleFactor
private double scaleFactor
-
minx
private double minx
-
maxx
private double maxx
-
miny
private double miny
-
maxy
private double maxy
-
corner
private Coordinate[] corner
The corners of the hot pixel, in the order: 10 23
-
safeEnv
private Envelope safeEnv
-
SAFE_ENV_EXPANSION_FACTOR
private static final double SAFE_ENV_EXPANSION_FACTOR
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HotPixel
public HotPixel(Coordinate pt, double scaleFactor, LineIntersector li)
Creates a new hot pixel, using a given scale factor. The scale factor must be strictly positive (non-zero).- Parameters:
pt- the coordinate at the centre of the pixelscaleFactor- the scaleFactor determining the pixel size. Must be > 0li- the intersector to use for testing intersection with line segments
-
-
Method Detail
-
getCoordinate
public Coordinate getCoordinate()
Gets the coordinate this hot pixel is based at.- Returns:
- the coordinate of the pixel
-
getSafeEnvelope
public Envelope getSafeEnvelope()
Returns a "safe" envelope that is guaranteed to contain the hot pixel. The envelope returned will be larger than the exact envelope of the pixel.- Returns:
- an envelope which contains the hot pixel
-
initCorners
private void initCorners(Coordinate pt)
-
scale
private double scale(double val)
-
intersects
public boolean intersects(Coordinate p0, Coordinate p1)
Tests whether the line segment (p0-p1) intersects this hot pixel.- Parameters:
p0- the first coordinate of the line segment to testp1- the second coordinate of the line segment to test- Returns:
- true if the line segment intersects this hot pixel
-
copyScaled
private void copyScaled(Coordinate p, Coordinate pScaled)
-
intersectsScaled
private boolean intersectsScaled(Coordinate p0, Coordinate p1)
-
intersectsToleranceSquare
private boolean intersectsToleranceSquare(Coordinate p0, Coordinate p1)
Tests whether the segment p0-p1 intersects the hot pixel tolerance square. Because the tolerance square point set is partially open (along the top and right) the test needs to be more sophisticated than simply checking for any intersection. However, it can take advantage of the fact that the hot pixel edges do not lie on the coordinate grid. It is sufficient to check if any of the following occur:- a proper intersection between the segment and any hot pixel edge
- an intersection between the segment and both the left and bottom hot pixel edges (which detects the case where the segment intersects the bottom left hot pixel corner)
- an intersection between a segment endpoint and the hot pixel coordinate
- Parameters:
p0-p1-- Returns:
-
intersectsPixelClosure
private boolean intersectsPixelClosure(Coordinate p0, Coordinate p1)
Test whether the given segment intersects the closure of this hot pixel. This is NOT the test used in the standard snap-rounding algorithm, which uses the partially closed tolerance square instead. This routine is provided for testing purposes only.- Parameters:
p0- the start point of a line segmentp1- the end point of a line segment- Returns:
trueif the segment intersects the closure of the pixel's tolerance square
-
addSnappedNode
public boolean addSnappedNode(NodedSegmentString segStr, int segIndex)
Adds a new node (equal to the snap pt) to the specified segment if the segment passes through the hot pixel- Parameters:
segStr-segIndex-- Returns:
- true if a node was added to the segment
-
-