Skip to content

Commit

Permalink
Modify interval determination approach (NASAWorldWind#199)
Browse files Browse the repository at this point in the history
- Refactor out interval calculation method
- Reduce interval factor to generate more intervals per shape
- See NASAWorldWind#18
  • Loading branch information
zglueck authored and pdavidc committed Jan 9, 2018
1 parent 9dd35fa commit 892c260
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions worldwind/src/main/java/gov/nasa/worldwind/shape/Ellipse.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import gov.nasa.worldwind.util.Logger;
import gov.nasa.worldwind.util.Pool;
import gov.nasa.worldwind.util.ShortArray;
import gov.nasa.worldwind.util.WWMath;

/**
* Ellipse shape defined by a geographic center position and radii for the semi-major and semi-minor axes.
Expand Down Expand Up @@ -88,6 +87,10 @@ public class Ellipse extends AbstractShape {
*/
protected int maximumIntervals = 64;

/**
* The number of intervals used for generating geometry. Clamped between MIN_INTERVALS and maximumIntervals and
* based on the circumference of the ellipse in planar geometry. Will always be even.
*/
protected int intervals;

protected FloatArray vertexArray = new FloatArray();
Expand Down Expand Up @@ -458,8 +461,7 @@ protected boolean mustAssembleGeometry(RenderContext rc) {

protected void assembleGeometry(RenderContext rc) {
// Determine the number of intervals to use based on the circumference of the ellipse
double circumference = Math.PI * (3 * (this.majorRadius + this.minorRadius) - Math.sqrt((3 * this.majorRadius + this.minorRadius) * (this.majorRadius + 3 * this.minorRadius)));
this.intervals = (int) WWMath.clamp(circumference / 50000.0, MIN_INTERVALS, this.maximumIntervals);
this.calculateIntervals();
if (this.intervals % 2 != 0) {
this.intervals--;
}
Expand Down Expand Up @@ -560,6 +562,24 @@ protected void addVertex(RenderContext rc, double latitude, double longitude, do
this.vertexArray.add(0);
}

protected void calculateIntervals() {
double circumference = this.calculateCircumference();
int intervals = (int) (circumference / 700.0); // In a circle, this would generate an interval every 700m
if (intervals < MIN_INTERVALS) {
this.intervals = MIN_INTERVALS;
} else if (intervals < this.maximumIntervals) {
this.intervals = intervals;
} else {
this.intervals = this.maximumIntervals;
}
}

private double calculateCircumference() {
double a = this.majorRadius;
double b = this.minorRadius;
return Math.PI * (3 * (a + b) - Math.sqrt((3 * a + b) * (a + 3 * b)));
}

@Override
protected void reset() {
this.vertexArray.clear();
Expand Down

0 comments on commit 892c260

Please sign in to comment.