Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify interval determination approach #199

Merged
merged 1 commit into from
Jan 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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