Skip to content

Commit a4ec23f

Browse files
committed
Polyline deprecation fixes
1 parent 0f308c1 commit a4ec23f

File tree

3 files changed

+126
-205
lines changed

3 files changed

+126
-205
lines changed

src/gov/nasa/worldwind/render/Path.java

Lines changed: 20 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -143,27 +143,6 @@ public static interface PositionColors {
143143
Color getColor(Position position, int ordinal);
144144
}
145145

146-
/**
147-
* Provides a concrete implementation of PositionColors that specifies a single color per position. Provided
148-
* primarily to ease migration from {@link Polyline}.
149-
*/
150-
public class OneColorPositionColors implements PositionColors {
151-
152-
Color color;
153-
154-
OneColorPositionColors(Color color) {
155-
this.color = color;
156-
}
157-
158-
/**
159-
* {@inheritDoc}
160-
*/
161-
@Override
162-
public Color getColor(Position position, int ordinal) {
163-
return color;
164-
}
165-
}
166-
167146
/**
168147
* Maintains globe-dependent computed data such as Cartesian vertices and extents. One entry exists for each
169148
* distinct globe that this shape encounters in calls to {@link AbstractShape#render(DrawContext)}. See {@link
@@ -769,7 +748,7 @@ public Path(Position posA, Position posB) {
769748
throw new IllegalArgumentException(message);
770749
}
771750

772-
List<Position> endPoints = new ArrayList<Position>(2);
751+
List<Position> endPoints = new ArrayList<>(2);
773752
endPoints.add(posA);
774753
endPoints.add(posB);
775754
this.setPositions(endPoints);
@@ -825,6 +804,7 @@ public void setPositions(Iterable<? extends Position> positions) {
825804
this.positions = positions;
826805
this.computePositionCount();
827806
this.positionsSpanDateline = LatLon.locationsCrossDateLine(this.positions);
807+
this.measurer.setPositions(this.positions);
828808

829809
this.reset();
830810
}
@@ -955,11 +935,11 @@ public void setNumSubsegments(int numSubsegments) {
955935
* @return the path's length in meters.
956936
*/
957937
public double getLength() {
958-
Object foo = this.getCurrentPathData().getEntries(); //.iterator();
959-
System.out.println(foo);
960-
// this.getCurrentPathData().getEntries()
961-
// Iterator<Position> infos = this.positions.values().iterator();
962-
return 0; // infos.hasNext() ? this.measurer.getLength(infos.next().globe) : 0;
938+
PathData data = this.getCurrentPathData();
939+
if (data != null && data.getGlobeStateKey() != null) {
940+
return this.measurer.getLength(data.getGlobeStateKey().getGlobe());
941+
}
942+
return 0;
963943
}
964944

965945
public double getLength(Globe globe) {
@@ -1102,6 +1082,7 @@ public void setShowPositionsThreshold(double showPositionsThreshold) {
11021082
this.showPositionsThreshold = showPositionsThreshold;
11031083
}
11041084

1085+
@Override
11051086
public Sector getSector() {
11061087
if (this.sector == null && this.positions != null) {
11071088
this.sector = Sector.boundingSector(this.positions);
@@ -1563,6 +1544,7 @@ protected void prepareToDrawPoints(DrawContext dc) {
15631544
*
15641545
* @param dc the current draw context.
15651546
*/
1547+
@Override
15661548
protected void doDrawInterior(DrawContext dc) {
15671549
if (this.shouldUseVBOs(dc)) {
15681550
int[] vboIds = this.getVboIds(dc);
@@ -1867,8 +1849,8 @@ protected void makeTessellatedPositions(DrawContext dc, PathData pathData) {
18671849

18681850
if (pathData.tessellatedPositions == null || pathData.tessellatedPositions.size() < this.numPositions) {
18691851
int size = (this.numSubsegments * (this.numPositions - 1) + 1) * (this.isExtrude() ? 2 : 1);
1870-
pathData.tessellatedPositions = new ArrayList<Position>(size);
1871-
pathData.tessellatedColors = (this.positionColors != null) ? new ArrayList<Color>(size) : null;
1852+
pathData.tessellatedPositions = new ArrayList<>(size);
1853+
pathData.tessellatedColors = (this.positionColors != null) ? new ArrayList<>(size) : null;
18721854
} else {
18731855
pathData.tessellatedPositions.clear();
18741856

@@ -1964,7 +1946,7 @@ protected void makePositions(DrawContext dc, PathData pathData) {
19641946

19651947
// Mark where the split position is so a new line is started there during rendering.
19661948
if (pathData.splitPositions == null) {
1967-
pathData.splitPositions = new ArrayList<Integer>(1);
1949+
pathData.splitPositions = new ArrayList<>(1);
19681950
}
19691951
pathData.splitPositions.add(pathData.tessellatedPositions.size());
19701952

@@ -2347,6 +2329,7 @@ protected Extent computeExtent(PathData current) {
23472329
return box;
23482330
}
23492331

2332+
@Override
23502333
public Extent getExtent(Globe globe, double verticalExaggeration) {
23512334
// See if we've cached an extent associated with the globe.
23522335
Extent extent = super.getExtent(globe, verticalExaggeration);
@@ -2375,10 +2358,12 @@ public Extent getExtent(Globe globe, double verticalExaggeration) {
23752358
*
23762359
* @return the computed reference position.
23772360
*/
2361+
@Override
23782362
public Position getReferencePosition() {
23792363
return this.numPositions < 1 ? null : this.positions.iterator().next(); // use the first position
23802364
}
23812365

2366+
@Override
23822367
protected void fillVBO(DrawContext dc) {
23832368
PathData pathData = this.getCurrentPathData();
23842369
int numIds = this.isShowPositions() ? 3 : pathData.hasExtrusionPoints && this.isDrawVerticals() ? 2 : 1;
@@ -2433,6 +2418,7 @@ public List<Intersection> intersect(Line line, Terrain terrain) throws Interrupt
24332418
return null;
24342419
}
24352420

2421+
@Override
24362422
public void move(Position delta) {
24372423
if (delta == null) {
24382424
String msg = Logging.getMessage("nullValue.PositionIsNull");
@@ -2452,6 +2438,7 @@ public void move(Position delta) {
24522438
this.moveTo(refPos.add(delta));
24532439
}
24542440

2441+
@Override
24552442
public void moveTo(Position position) {
24562443
if (position == null) {
24572444
String msg = Logging.getMessage("nullValue.PositionIsNull");
@@ -2546,83 +2533,13 @@ protected void doExportAsKML(XMLStreamWriter xmlWriter) throws IOException, XMLS
25462533
}
25472534

25482535
/**
2549-
* Provided to ease the transition from Polyline
2550-
*
2551-
* @param color
2552-
*/
2553-
public void setColor(Color color) {
2554-
if (color == null) {
2555-
String msg = Logging.getMessage("nullValue.ColorIsNull");
2556-
Logging.logger().severe(msg);
2557-
throw new IllegalArgumentException(msg);
2558-
}
2559-
2560-
setPositionColors(new OneColorPositionColors(color));
2561-
if (this.surfaceShape != null) {
2562-
ShapeAttributes attrs = this.surfaceShape.getAttributes();
2563-
attrs.setOutlineMaterial(new Material(color));
2564-
attrs.setOutlineOpacity(color.getAlpha() / 255.0);
2565-
attrs.setInteriorMaterial(attrs.getOutlineMaterial());
2566-
attrs.setInteriorOpacity(attrs.getOutlineOpacity());
2567-
}
2568-
2569-
}
2570-
2571-
/**
2572-
* Provided to ease the transition from Polyline
2573-
*
2574-
* @param lineWidth
2575-
*/
2576-
public void setLineWidth(double lineWidth) {
2577-
2578-
this.activeAttributes.setOutlineWidth(lineWidth);
2579-
this.reset();
2580-
if (this.surfaceShape != null) {
2581-
this.surfaceShape.getAttributes().setOutlineWidth(this.activeAttributes.getOutlineWidth());
2582-
}
2583-
}
2584-
2585-
/**
2586-
* Specifies an offset, in meters, to add to the path points when the path's follow-terrain attribute is true. See
2587-
* {@link #setFollowTerrain(boolean)}. Provided to ease the transition from Polyline
2536+
* Specifies an offset, in meters, to add to the path points when the path's altitude mode is
2537+
* {@link WorldWind.CLAMP_TO_GROUND}. See {@link #setAltitudeMode(int) }.
25882538
*
25892539
* @param offset the path offset in meters.
25902540
*/
25912541
public void setOffset(double offset) {
2592-
this.offset=offset;
2542+
this.offset = offset;
25932543
this.reset();
25942544
}
2595-
2596-
/**
2597-
* Sets the stipple pattern for specifying line types other than solid. See the OpenGL specification or programming
2598-
* guides for a description of this parameter. Stipple is also affected by the path's stipple factor, {@link
2599-
* #setStippleFactor(int)}.
2600-
*
2601-
* @param stipplePattern the stipple pattern.
2602-
*/
2603-
public void setStipplePattern(short stipplePattern) {
2604-
System.out.println("foo");
2605-
2606-
// this.stipplePattern = stipplePattern;
2607-
// if (this.surfaceShape != null) {
2608-
// this.surfaceShape.getAttributes().setOutlineStipplePattern(this.stipplePattern);
2609-
// }
2610-
}
2611-
2612-
/**
2613-
* Sets the stipple factor for specifying line types other than solid. See the OpenGL specification or programming
2614-
* guides for a description of this parameter. Stipple is also affected by the path's stipple pattern, {@link
2615-
* #setStipplePattern(short)}.
2616-
*
2617-
* @param stippleFactor the stipple factor.
2618-
*/
2619-
public void setStippleFactor(int stippleFactor) {
2620-
System.out.println("foo");
2621-
// this.stippleFactor = stippleFactor;
2622-
//
2623-
// if (this.surfaceShape != null) {
2624-
// this.surfaceShape.getAttributes().setOutlineStippleFactor(this.stippleFactor);
2625-
// }
2626-
}
2627-
26282545
}

src/gov/nasa/worldwind/util/measure/LengthMeasurer.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,28 @@ public void setPositions(ArrayList<? extends LatLon> positions, double elevation
7070
throw new IllegalArgumentException(message);
7171
}
7272

73-
ArrayList<Position> newPositions = new ArrayList<Position>();
73+
ArrayList<Position> newPositions = new ArrayList<>();
7474
for (LatLon pos : positions) {
7575
newPositions.add(new Position(pos, elevation));
7676
}
7777

7878
setPositions(newPositions);
7979
}
8080

81+
public void setPositions(Iterable<? extends Position> positions) {
82+
if (positions == null) {
83+
String message = Logging.getMessage("nullValue.PositionsListIsNull");
84+
Logging.logger().severe(message);
85+
throw new IllegalArgumentException(message);
86+
}
87+
88+
ArrayList<Position> newPositions = new ArrayList<>();
89+
for (Position p:positions) {
90+
newPositions.add(p);
91+
}
92+
setPositions(newPositions);
93+
}
94+
8195
public void setPositions(ArrayList<? extends Position> positions) {
8296
if (positions == null) {
8397
String message = Logging.getMessage("nullValue.PositionsListIsNull");
@@ -170,7 +184,7 @@ public void setPathType(int pathType) {
170184
* @param pathType the type of path to measure.
171185
*/
172186
public void setPathType(String pathType) {
173-
if (this.pathType != pathType) {
187+
if (!this.pathType.equals(pathType)) {
174188
this.pathType = pathType;
175189
clearCachedValues();
176190
}
@@ -262,6 +276,7 @@ public void setLengthTerrainSamplingSteps(double steps) {
262276
*
263277
* @return the current path length or -1 if the position list is too short.
264278
*/
279+
@Override
265280
public double getLength(Globe globe) {
266281
if (globe == null) {
267282
String message = Logging.getMessage("nullValue.GlobeIsNull");
@@ -308,20 +323,6 @@ protected double computeLength(Globe globe, boolean followTerrain) {
308323
return length;
309324
}
310325

311-
// // This tries not to use the globe.computePointFromPosition so as to report accurate length on flat globes
312-
// // However, it shows significant deviations for east-west measurements.
313-
// private double computeSegmentLengthLinearApprox(Globe globe, Position pos1, Position pos2)
314-
// {
315-
// // Cartesian distance approximation for short segments - only needs globe radius
316-
// LatLon midPoint = LatLon.interpolate(.5, pos1, pos2);
317-
// double radius = globe.getRadiusAt(midPoint);
318-
// double cosLat = Math.cos(midPoint.getLatitude().radians);
319-
// return new Vec4(
320-
// (pos2.getLongitude().radians - pos1.getLongitude().radians) * radius * cosLat,
321-
// (pos2.getLatitude().radians - pos1.getLatitude().radians) * radius,
322-
// pos2.getElevation() - pos1.getElevation()
323-
// ).getLength3(); // Meters
324-
// }
325326
/**
326327
* Subdivide a list of positions so that no segment is longer then the provided maxLength.
327328
* <p>
@@ -333,7 +334,7 @@ protected double computeLength(Globe globe, boolean followTerrain) {
333334
* @param positions the original position list
334335
* @param maxLength the maximum length for one segment.
335336
* @param followTerrain true if the positions should be on the terrain surface.
336-
* @param pathType the type of path to use in between two positions.
337+
* @param avkeyPathType the type of path to use in between two positions.
337338
*
338339
* @return a list of positions with no segment longer then maxLength and elevations following terrain or not.
339340
*/
@@ -369,7 +370,7 @@ protected static ArrayList<? extends Position> subdividePositions(Globe globe,
369370
return positions;
370371
}
371372

372-
ArrayList<Position> newPositions = new ArrayList<Position>();
373+
ArrayList<Position> newPositions = new ArrayList<>();
373374
// Add first position
374375
Position pos1 = positions.get(start);
375376
if (followTerrain) {

0 commit comments

Comments
 (0)