/** * Get the index of the closest downsample factor from an array of available factors. * * The array is assumed to be sorted in ascending order. * * @param preferredDownsamples * @param downsampleFactor * @return */ public static int getClosestDownsampleIndex(double[] preferredDownsamples, double downsampleFactor) { downsampleFactor = Math.max(downsampleFactor, 1.0); int bestDownsampleSeries = -1; double bestDownsampleDiff = Double.POSITIVE_INFINITY; for (int i = 0; i < preferredDownsamples.length; i++) { double downsampleDiff = downsampleFactor - preferredDownsamples[i]; if (!Double.isNaN(downsampleDiff) && (downsampleDiff >= 0 || GeneralTools.almostTheSame(downsampleFactor, preferredDownsamples[i], 0.01)) && downsampleDiff < bestDownsampleDiff) { bestDownsampleSeries = i; bestDownsampleDiff = Math.abs(downsampleDiff); } } return bestDownsampleSeries; }
@Override public boolean validateSquarePixels() { return GeneralTools.almostTheSame(getPixelWidthMicrons(), getPixelHeightMicrons(), 0.0001); }
public boolean isCircle(double pixelWidth, double pixelHeight) { return GeneralTools.almostTheSame(getBoundsWidth() * pixelWidth, getBoundsHeight() * pixelHeight, 0.00001); }
@Override public double getScaledPerimeter(double pixelWidth, double pixelHeight) { if (GeneralTools.almostTheSame(pixelWidth, pixelHeight, 0.0001)) return getPerimeter() * (pixelWidth + pixelHeight) * .5; // TODO: Need to confirm this is not a performance bottleneck in practice (speed vs. memory issue) return new ClosedShapeStatistics(shape, pixelWidth, pixelHeight).getPerimeter(); }
@Override public double getScaledArea(double pixelWidth, double pixelHeight) { if (GeneralTools.almostTheSame(pixelWidth, pixelHeight, 0.0001)) return getArea() * pixelWidth * pixelHeight; // TODO: Need to confirm this is not a performance bottleneck in practice (speed vs. memory issue) return new ClosedShapeStatistics(vertices, pixelWidth, pixelHeight).getArea(); }
@Override public double getScaledPerimeter(double pixelWidth, double pixelHeight) { if (GeneralTools.almostTheSame(pixelWidth, pixelHeight, 0.0001)) return getPerimeter() * (pixelWidth + pixelHeight) * .5; // TODO: Need to confirm this is not a performance bottleneck in practice (speed vs. memory issue) return new ClosedShapeStatistics(vertices, pixelWidth, pixelHeight).getPerimeter(); }
@Override public double getScaledArea(double pixelWidth, double pixelHeight) { if (GeneralTools.almostTheSame(pixelWidth, pixelHeight, 0.0001)) return getArea() * pixelWidth * pixelHeight; // TODO: Need to confirm this is not a performance bottleneck in practice (speed vs. memory issue) return new ClosedShapeStatistics(vertices, pixelWidth, pixelHeight).getArea(); }
@Override public double getScaledPerimeter(double pixelWidth, double pixelHeight) { if (GeneralTools.almostTheSame(pixelWidth, pixelHeight, 0.0001)) return getPerimeter() * (pixelWidth + pixelHeight) * .5; // TODO: Need to confirm this is not a performance bottleneck in practice (speed vs. memory issue) return new ClosedShapeStatistics(vertices, pixelWidth, pixelHeight).getPerimeter(); }
@Override public double getScaledArea(double pixelWidth, double pixelHeight) { if (GeneralTools.almostTheSame(pixelWidth, pixelHeight, 0.0001)) return getArea() * pixelWidth * pixelHeight; // TODO: Need to confirm this is not a performance bottleneck in practice (speed vs. memory issue) return new ClosedShapeStatistics(shape, pixelWidth, pixelHeight).getArea(); }
if (GeneralTools.almostTheSame(downsamplePreferred, (int)(downsamplePreferred + .5), 0.001)) { tileWidthForLevel = (int)(tileWidth * (int)(downsamplePreferred + .5) + .5); tileHeightForLevel = (int)(tileHeight * (int)(downsamplePreferred + .5) + .5);
if (GeneralTools.almostTheSame(downsamplePreferred, (int)(downsamplePreferred + .5), 0.001)) { tileWidthForLevel = (int)(tileWidth * (int)(downsamplePreferred + .5) + .5); tileHeightForLevel = (int)(tileHeight * (int)(downsamplePreferred + .5) + .5);