2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
7 package gov
.nasa
.worldwind
.geom
;
10 import java
.awt
.geom
.*;
11 import java
.awt
.image
.*;
16 * @version $Id: SurfacePolygon.java 1688 2007-05-02 22:03:39Z tgaskins $
18 public class SurfacePolygon
extends SurfaceShape
21 public SurfacePolygon(Iterable
<LatLon
> positions
, Color color
, Color borderColor
)
23 super(positions
, color
, borderColor
);
26 public SurfacePolygon(Iterable
<LatLon
> positions
)
28 super(positions
, null, null);
31 protected final BufferedImage
drawShape(BufferedImage image
)
33 double minLat
= this.getSector().getMinLatitude().getDegrees();
34 double minLon
= this.getSector().getMinLongitude().getDegrees();
35 double dLat
= this.getSector().getDeltaLatDegrees();
36 double dLon
= this.getSector().getDeltaLonDegrees();
38 double latScale
= dLat
> 0 ? image
.getHeight() / dLat
: 0;
39 double lonScale
= dLon
> 0 ? image
.getWidth() / dLon
: 0;
41 GeneralPath path
= new GeneralPath();
43 Iterator
<LatLon
> positions
= this.getPositions().iterator();
44 if (!positions
.hasNext())
47 LatLon pos
= positions
.next();
49 (float) Math
.min(lonScale
* (pos
.getLongitude().getDegrees() - minLon
), image
.getWidth() - 1),
50 (float) Math
.min(latScale
* (pos
.getLatitude().getDegrees() - minLat
), image
.getHeight() - 1));
52 double delta
= 1d
/ this.getNumEdgeIntervals();
53 while (positions
.hasNext())
55 LatLon posNext
= positions
.next();
56 for (int i
= 0; i
< this.getNumEdgeIntervals(); i
++)
58 LatLon p
= LatLon
.interpolate(i
* delta
, pos
, posNext
);
60 (float) Math
.min(lonScale
* (p
.getLongitude().getDegrees() - minLon
), image
.getWidth() - 1),
61 (float) Math
.min(latScale
* (p
.getLatitude().getDegrees() - minLat
), image
.getHeight() - 1));
64 // Set the last point directly to terminate any round-off error in the iteration above.
66 (float) Math
.min(lonScale
* (posNext
.getLongitude().getDegrees() - minLon
), image
.getWidth() - 1),
67 (float) Math
.min(latScale
* (posNext
.getLatitude().getDegrees() - minLat
), image
.getHeight() - 1));
72 Graphics2D g2
= image
.createGraphics();
74 if (this.isAntiAlias())
75 g2
.setRenderingHint(RenderingHints
.KEY_ANTIALIASING
, RenderingHints
.VALUE_ANTIALIAS_ON
);
77 if (this.isDrawInterior())
79 g2
.setPaint(this.getPaint());
83 if (this.isDrawBorder())
85 g2
.setPaint(this.getBorderColor());
86 g2
.setStroke(this.getStroke());