本文整理汇总了Java中com.vividsolutions.jts.math.MathUtil类的典型用法代码示例。如果您正苦于以下问题:Java MathUtil类的具体用法?Java MathUtil怎么用?Java MathUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MathUtil类属于com.vividsolutions.jts.math包,在下文中一共展示了MathUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: precisionScaleFactor
import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
* Compute a scale factor to limit the precision of
* a given combination of Geometry and buffer distance.
* The scale factor is determined by
* the number of digits of precision in the (geometry + buffer distance),
* limited by the supplied <code>maxPrecisionDigits</code> value.
* <p>
* The scale factor is based on the absolute magnitude of the (geometry + buffer distance).
* since this determines the number of digits of precision which must be handled.
*
* @param g the Geometry being buffered
* @param distance the buffer distance
* @param maxPrecisionDigits the max # of digits that should be allowed by
* the precision determined by the computed scale factor
* @return a scale factor for the buffer computation
*/
private static double precisionScaleFactor(Geometry g,
double distance,
int maxPrecisionDigits) {
Envelope env = g.getEnvelopeInternal();
double envMax = MathUtil.max(
Math.abs(env.getMaxX()),
Math.abs(env.getMaxY()),
Math.abs(env.getMinX()),
Math.abs(env.getMinY())
);
double expandByDistance = distance > 0.0 ? distance : 0.0;
double bufEnvMax = envMax + 2 * expandByDistance;
// the smallest power of 10 greater than the buffer envelope
int bufEnvPrecisionDigits = (int) (Math.log(bufEnvMax) / Math.log(10) + 1.0);
int minUnitLog10 = maxPrecisionDigits - bufEnvPrecisionDigits;
double scaleFactor = Math.pow(10.0, minUnitLog10);
return scaleFactor;
}
示例2: precisionScaleFactor
import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
* Compute a scale factor to limit the precision of
* a given combination of Geometry and buffer distance.
* The scale factor is determined by
* the number of digits of precision in the (geometry + buffer distance),
* limited by the supplied <code>maxPrecisionDigits</code> value.
* <p/>
* The scale factor is based on the absolute magnitude of the (geometry + buffer distance).
* since this determines the number of digits of precision which must be handled.
*
* @param g the Geometry being buffered
* @param distance the buffer distance
* @param maxPrecisionDigits the max # of digits that should be allowed by
* the precision determined by the computed scale factor
* @return a scale factor for the buffer computation
*/
private static double precisionScaleFactor(Geometry g,
double distance,
int maxPrecisionDigits) {
Envelope env = g.getEnvelopeInternal();
double envMax = MathUtil.max(
Math.abs(env.getMaxX()),
Math.abs(env.getMaxY()),
Math.abs(env.getMinX()),
Math.abs(env.getMinY())
);
double expandByDistance = distance > 0.0 ? distance : 0.0;
double bufEnvMax = envMax + 2 * expandByDistance;
// the smallest power of 10 greater than the buffer envelope
int bufEnvPrecisionDigits = (int) (Math.log(bufEnvMax) / Math.log(10) + 1.0);
int minUnitLog10 = maxPrecisionDigits - bufEnvPrecisionDigits;
double scaleFactor = Math.pow(10.0, minUnitLog10);
return scaleFactor;
}
示例3: extract
import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
* Extracts a subsequence of the input {@link Coordinate} array
* from indices <code>start</code> to
* <code>end</code> (inclusive).
* The input indices are clamped to the array size;
* If the end index is less than the start index,
* the extracted array will be empty.
*
* @param pts the input array
* @param start the index of the start of the subsequence to extract
* @param end the index of the end of the subsequence to extract
* @return a subsequence of the input array
*/
public static Coordinate[] extract(Coordinate[] pts, int start, int end) {
start = MathUtil.clamp(start, 0, pts.length);
end = MathUtil.clamp(end, -1, pts.length);
int npts = end - start + 1;
if (end < 0) npts = 0;
if (start >= pts.length) npts = 0;
if (end < start) npts = 0;
Coordinate[] extractPts = new Coordinate[npts];
if (npts == 0) return extractPts;
int iPts = 0;
for (int i = start; i <= end; i++) {
extractPts[iPts++] = pts[i];
}
return extractPts;
}
示例4: precisionScaleFactor
import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
* Compute a scale factor to limit the precision of
* a given combination of Geometry and buffer distance.
* The scale factor is determined by
* the number of digits of precision in the (geometry + buffer distance),
* limited by the supplied <code>maxPrecisionDigits</code> value.
* <p>
* The scale factor is based on the absolute magnitude of the (geometry + buffer distance).
* since this determines the number of digits of precision which must be handled.
*
* @param g the Geometry being buffered
* @param distance the buffer distance
* @param maxPrecisionDigits the max # of digits that should be allowed by
* the precision determined by the computed scale factor
*
* @return a scale factor for the buffer computation
*/
private static double precisionScaleFactor(Geometry g,
double distance,
int maxPrecisionDigits)
{
Envelope env = g.getEnvelopeInternal();
double envMax = MathUtil.max(
Math.abs(env.getMaxX()),
Math.abs(env.getMaxY()),
Math.abs(env.getMinX()),
Math.abs(env.getMinY())
);
double expandByDistance = distance > 0.0 ? distance : 0.0;
double bufEnvMax = envMax + 2 * expandByDistance;
// the smallest power of 10 greater than the buffer envelope
int bufEnvPrecisionDigits = (int) (Math.log(bufEnvMax) / Math.log(10) + 1.0);
int minUnitLog10 = maxPrecisionDigits - bufEnvPrecisionDigits;
double scaleFactor = Math.pow(10.0, minUnitLog10);
return scaleFactor;
}
示例5: extract
import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
* Extracts a subsequence of the input {@link Coordinate} array
* from indices <code>start</code> to
* <code>end</code> (inclusive).
* The input indices are clamped to the array size;
* If the end index is less than the start index,
* the extracted array will be empty.
*
* @param pts the input array
* @param start the index of the start of the subsequence to extract
* @param end the index of the end of the subsequence to extract
* @return a subsequence of the input array
*/
public static Coordinate[] extract(Coordinate[] pts, int start, int end)
{
start = MathUtil.clamp(start, 0, pts.length);
end = MathUtil.clamp(end, -1, pts.length);
int npts = end - start + 1;
if (end < 0) npts = 0;
if (start >= pts.length) npts = 0;
if (end < start) npts = 0;
Coordinate[] extractPts = new Coordinate[npts];
if (npts == 0) return extractPts;
int iPts = 0;
for (int i = start; i <= end; i++) {
extractPts[iPts++] = pts[i];
}
return extractPts;
}
示例6: snapScaleTo_10_2_5
import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
* Not used - scaling to multiples of 10,5,2 is too coarse.
*
*
* @param scaleRaw
* @return
*/
private static double snapScaleTo_10_2_5(double scaleRaw)
{
// if the rounding error is not nudged, snapping can "stick" at some values
double pow10 = Math.floor(MathUtil.log10(scaleRaw) + ROUND_ERROR_REMOVAL);
double scaleRoundedToPow10 = Math.pow(10, pow10);
double scale = scaleRoundedToPow10;
// rounding to a power of 10 is too coarse, so allow some finer gradations
//*
if (3.5 * scaleRoundedToPow10 <= scaleRaw)
scale = 5 * scaleRoundedToPow10;
else if (2 * scaleRoundedToPow10 <= scaleRaw)
scale = 2 * scaleRoundedToPow10;
//*/
//System.out.println("requested scale = " + scaleRaw + " scale = " + scale + " Pow10 = " + pow10);
return scale;
}
示例7: gridMagnitudeModel
import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
* Gets the magnitude (power of 10)
* for the basic grid size.
*
* @return
*/
public int gridMagnitudeModel()
{
double pixelSizeModel = toModel(1);
double pixelSizeModelLog = MathUtil.log10(pixelSizeModel);
int gridMag = (int) Math.ceil(pixelSizeModelLog);
/**
* Check if grid size is too small and if so increase it one magnitude
*/
double gridSizeModel = Math.pow(10, gridMag);
double gridSizeView = toView(gridSizeModel);
// System.out.println("\ncand gridSizeView= " + gridSizeView);
if (gridSizeView <= MIN_GRID_RESOLUTION_PIXELS )
gridMag += 1;
// System.out.println("pixelSize= " + pixelSize + " pixelLog10= " + pixelSizeLog);
return gridMag;
}
示例8: extract
import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
* Extracts a subsequence of the input {@link Coordinate} array
* from indices <code>start</code> to
* <code>end</code> (inclusive).
* The input indices are clamped to the array size;
* If the end index is less than the start index,
* the extracted array will be empty.
*
* @param pts the input array
* @param start the index of the start of the subsequence to extract
* @param end the index of the end of the subsequence to extract
* @return a subsequence of the input array
*/
public static Coordinate[] extract(Coordinate[] pts, int start, int end) {
start = MathUtil.clamp(start, 0, pts.length);
end = MathUtil.clamp(end, -1, pts.length);
int npts = end - start + 1;
if (end < 0) {
npts = 0;
}
if (start >= pts.length) {
npts = 0;
}
if (end < start) {
npts = 0;
}
Coordinate[] extractPts = new Coordinate[npts];
if (npts == 0) {
return extractPts;
}
int iPts = 0;
for (int i = start; i <= end; i++) {
extractPts[iPts++] = pts[i];
}
return extractPts;
}
示例9: getGeometry
import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
* Gets the {@link MultiPoint} containing the generated point
*
* @return a MultiPoint
*/
@Override
public Geometry getGeometry() {
int nCells = (int) Math.sqrt(this.numPts);
// ensure that at least numPts points are generated
if (nCells * nCells < this.numPts) {
nCells += 1;
}
double gridDX = this.getExtent().getWidth() / nCells;
double gridDY = this.getExtent().getHeight() / nCells;
double gutterFrac = MathUtil.clamp(this.gutterFraction, 0.0, 1.0);
double gutterOffsetX = gridDX * gutterFrac / 2;
double gutterOffsetY = gridDY * gutterFrac / 2;
double cellFrac = 1.0 - gutterFrac;
double cellDX = cellFrac * gridDX;
double cellDY = cellFrac * gridDY;
Coordinate[] pts = new Coordinate[nCells * nCells];
int index = 0;
for (int i = 0; i < nCells; i++) {
for (int j = 0; j < nCells; j++) {
double orgX = this.getExtent().getMinX() + i * gridDX + gutterOffsetX;
double orgY = this.getExtent().getMinY() + j * gridDY + gutterOffsetY;
pts[index++] = this.randomPointInCell(orgX, orgY, cellDX, cellDY);
}
}
return this.geomFactory.createMultiPoint(pts);
}
示例10: getGeometry
import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
* Gets the {@link MultiPoint} containing the generated point
*
* @return a MultiPoint
*/
public Geometry getGeometry() {
int nCells = (int) Math.sqrt(numPts);
// ensure that at least numPts points are generated
if (nCells * nCells < numPts)
nCells += 1;
double gridDX = getExtent().getWidth() / nCells;
double gridDY = getExtent().getHeight() / nCells;
double gutterFrac = MathUtil.clamp(gutterFraction, 0.0, 1.0);
double gutterOffsetX = gridDX * gutterFrac / 2;
double gutterOffsetY = gridDY * gutterFrac / 2;
double cellFrac = 1.0 - gutterFrac;
double cellDX = cellFrac * gridDX;
double cellDY = cellFrac * gridDY;
Coordinate[] pts = new Coordinate[nCells * nCells];
int index = 0;
for (int i = 0; i < nCells; i++) {
for (int j = 0; j < nCells; j++) {
double orgX = getExtent().getMinX() + i * gridDX + gutterOffsetX;
double orgY = getExtent().getMinY() + j * gridDY + gutterOffsetY;
pts[index++] = randomPointInCell(orgX, orgY, cellDX, cellDY);
}
}
return geomFactory.createMultiPoint(pts);
}
示例11: getGeometry
import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
/**
* Gets the {@link MultiPoint} containing the generated point
*
* @return a MultiPoint
*/
public Geometry getGeometry()
{
int nCells = (int) Math.sqrt(numPts);
// ensure that at least numPts points are generated
if (nCells * nCells < numPts)
nCells += 1;
double gridDX = getExtent().getWidth() / nCells;
double gridDY = getExtent().getHeight() / nCells;
double gutterFrac = MathUtil.clamp(gutterFraction, 0.0, 1.0);
double gutterOffsetX = gridDX * gutterFrac/2;
double gutterOffsetY = gridDY * gutterFrac/2;
double cellFrac = 1.0 - gutterFrac;
double cellDX = cellFrac * gridDX;
double cellDY = cellFrac * gridDY;
Coordinate[] pts = new Coordinate[nCells * nCells];
int index = 0;
for (int i = 0; i < nCells; i++) {
for (int j = 0; j < nCells; j++) {
double orgX = getExtent().getMinX() + i * gridDX + gutterOffsetX;
double orgY = getExtent().getMinY() + j * gridDY + gutterOffsetY;
pts[index++] = randomPointInCell(orgX, orgY, cellDX, cellDY);
}
}
return geomFactory.createMultiPoint(pts);
}
示例12: temperature
import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
public static Color temperature(double fraction) {
fraction = MathUtil.clamp(fraction, 0, 1);
int n = temperatureCols.length;
double index = fraction * (n - 1);
int low = (int) Math.floor(index);
int high = (int) Math.ceil(index);
double ifrac = index - low;
Color l = temperatureCols[low];
Color h = temperatureCols[high];
Color ret = new Color(lerp(l.getRed(), h.getRed(), ifrac), lerp(l.getGreen(), h.getGreen(), ifrac), lerp(l.getBlue(), h.getBlue(), ifrac));
return ret;
}
示例13: getRenderColour
import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
public static Color getRenderColour(DrawableObject pnt, boolean isSelected) {
if(isSelected){
return SELECTION_COLOUR;
}
Color col = getNoAlphaColour(pnt.getColour(), pnt.getColourKey());
double opaque = pnt.getOpaque();
opaque = MathUtil.clamp(opaque, 0, 1);
col = Colours.setAlpha(col, (int) Math.round((255 * opaque)));
return col;
}
示例14: saturate
import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
public static Color saturate(Color clr, double saturation)
{
float[] hsb = new float[3];
Color.RGBtoHSB(clr.getRed(), clr.getGreen(), clr.getBlue(), hsb);
hsb[1] = (float) MathUtil.clamp(saturation, 0, 1);;
return Color.getHSBColor(hsb[0], hsb[1], hsb[2]);
}
示例15: maxVisibleMagnitude
import com.vividsolutions.jts.math.MathUtil; //导入依赖的package包/类
private int maxVisibleMagnitude()
{
double visibleExtentModel = viewport.getModelEnv().maxExtent();
// if input is bogus then just return something reasonable
if (visibleExtentModel <= 0.0)
return 1;
double log10 = MathUtil.log10(visibleExtentModel);
return (int) log10;
}