From 4761a5e7321beb419181031af724fe6b321ceaf2 Mon Sep 17 00:00:00 2001 From: Zach Glueckert Date: Mon, 8 Jan 2018 17:00:38 -0600 Subject: [PATCH] Modify interval determination approach - Refactor out interval calculation method - Reduce interval factor to generate more intervals per shape - See #18 --- .../gov/nasa/worldwind/shape/Ellipse.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/worldwind/src/main/java/gov/nasa/worldwind/shape/Ellipse.java b/worldwind/src/main/java/gov/nasa/worldwind/shape/Ellipse.java index 77f4490ce..e587fa6bb 100644 --- a/worldwind/src/main/java/gov/nasa/worldwind/shape/Ellipse.java +++ b/worldwind/src/main/java/gov/nasa/worldwind/shape/Ellipse.java @@ -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. @@ -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(); @@ -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--; } @@ -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();