Skip to content

Commit

Permalink
Improve HotPixel memory usage by dropping some fields (#604)
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
  • Loading branch information
dr-jts committed Sep 27, 2020
1 parent a238257 commit 02f0a25
Showing 1 changed file with 32 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,47 +44,45 @@ public class HotPixel
// testing only
// public static int nTests = 0;

private static double TOLERANCE = 0.5;
private static final double TOLERANCE = 0.5;

private Coordinate ptHot;
private Coordinate originalPt;
private double scaleFactor;

/**
* The scaled ordinates of the hot pixel point
*/
private double hpx;
private double hpy;

/**
* Indicates if this hot pixel must be a node in the output
* Indicates if this hot pixel must be a node in the output.
*/
private boolean isNode = false;

private double scaleFactor;

private double minx;
private double maxx;
private double miny;
private double maxy;

/**
* Creates a new hot pixel, using a given scale factor.
* Creates a new hot pixel centered on a rounded point, using a given scale factor.
* The scale factor must be strictly positive (non-zero).
*
* @param pt the coordinate at the centre of the pixel
* @param pt the coordinate at the centre of the pixel (already rounded)
* @param scaleFactor the scaleFactor determining the pixel size. Must be &gt; 0
* @param li the intersector to use for testing intersection with line segments
*
*/
public HotPixel(Coordinate pt, double scaleFactor) {
originalPt = pt;
this.ptHot = pt;
this.scaleFactor = scaleFactor;

if (scaleFactor <= 0)
throw new IllegalArgumentException("Scale factor must be non-zero");
if (scaleFactor != 1.0) {
this.ptHot = scaleRound(pt);
hpx = scaleRound(pt.getX());
hpy = scaleRound(pt.getY());
}
else {
hpx = pt.getX();
hpy = pt.getY();
}

// extreme values for pixel
minx = ptHot.x - TOLERANCE;
maxx = ptHot.x + TOLERANCE;
miny = ptHot.y - TOLERANCE;
maxy = ptHot.y + TOLERANCE;
}

/**
Expand Down Expand Up @@ -163,13 +161,13 @@ private double scale(double val)
public boolean intersects(Coordinate p) {
double x = scale(p.x);
double y = scale(p.y);
if (x >= maxx) return false;
if (x >= hpx + TOLERANCE) return false;
// check Left side
if (x < minx) return false;
if (x < hpx - TOLERANCE) return false;
// check Top side
if (y >= maxy) return false;
if (y >= hpy + TOLERANCE) return false;
// check Bottom side
if (y < miny) return false;
if (y < hpy - TOLERANCE) return false;
return true;
}

Expand Down Expand Up @@ -212,15 +210,19 @@ private boolean intersectsScaled(double p0x, double p0y,
* are open (not part of the pixel).
*/
// check Right side
double maxx = hpx + TOLERANCE;
double segMinx = Math.min(px, qx);
if (segMinx >= maxx) return false;
// check Left side
double minx = hpx - TOLERANCE;
double segMaxx = Math.max(px, qx);
if (segMaxx < minx) return false;
// check Top side
double maxy = hpy + TOLERANCE;
double segMiny = Math.min(py, qy);
if (segMiny >= maxy) return false;
// check Bottom side
double miny = hpy - TOLERANCE;
double segMaxy = Math.max(py, qy);
if (segMaxy < miny) return false;

Expand Down Expand Up @@ -314,6 +316,11 @@ private boolean intersectsScaled(double p0x, double p0y,
*/
private boolean intersectsPixelClosure(Coordinate p0, Coordinate p1)
{
double minx = hpx - TOLERANCE;
double maxx = hpx + TOLERANCE;
double miny = hpy - TOLERANCE;
double maxy = hpy + TOLERANCE;

Coordinate[] corner = new Coordinate[4];
corner[UPPER_RIGHT] = new Coordinate(maxx, maxy);
corner[UPPER_LEFT] = new Coordinate(minx, maxy);
Expand All @@ -334,7 +341,7 @@ private boolean intersectsPixelClosure(Coordinate p0, Coordinate p1)
}

public String toString() {
return "HP(" + WKTWriter.format(ptHot) + ")";
return "HP(" + WKTWriter.format(originalPt) + ")";
}

}

0 comments on commit 02f0a25

Please sign in to comment.