Class HotPixel

java.lang.Object
org.locationtech.jts.noding.snapround.HotPixel

public class HotPixel extends Object
Implements 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 Details

    • 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:
  • Constructor Details

    • 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 pixel
      scaleFactor - the scaleFactor determining the pixel size. Must be > 0
      li - the intersector to use for testing intersection with line segments
  • Method Details

    • 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 test
      p1 - 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 segment
      p1 - the end point of a line segment
      Returns:
      true if 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