Updated to worldwind release 20070817
[worldwind-tracker.git] / gov / nasa / worldwind / geom / Sector.java
blob54ac579e88a1c1260474763f3c1ea246c5489d9c
1 /*
2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
5 All Rights Reserved.
6 */
7 package gov.nasa.worldwind.geom;
9 import gov.nasa.worldwind.cache.Cacheable;
10 import gov.nasa.worldwind.globes.Globe;
11 import gov.nasa.worldwind.tracks.TrackPoint;
12 import gov.nasa.worldwind.util.Logging;
14 /**
15 * <code>Sector</code> represents a rectangular reqion of latitude and longitude. The region is defined by four angles:
16 * its minimum and maximum latitude, its minimum and maximum longitude. The angles are assumed to be normalized to +/-
17 * 90 degrees latitude and +/- 180 degrees longitude. The minimums and maximums are relative to these ranges, e.g., -80
18 * is less than 20. Behavior of the class is undefined for angles outside these ranges. Normalization is not performed
19 * on the angles by this class, nor is it verifed by the class' methods. See {@link Angle} for a description of
20 * specifying angles.
21 * <p/>
22 * <code>Sector</code> instances are immutable. </p>
24 * @author Tom Gaskins
25 * @version $Id: Sector.java 2516 2007-08-07 01:40:17Z tgaskins $
26 * @see Angle
28 public class Sector implements Cacheable, Comparable<Sector>
30 /**
31 * A <code>Sector</code> of latitude [-90 degrees, + 90 degrees] and longitude [-180 degrees, + 180 degrees].
33 public static final Sector FULL_SPHERE = new Sector(Angle.NEG90, Angle.POS90, Angle.NEG180, Angle.POS180);
34 public static final Sector EMPTY_SECTOR = new Sector(Angle.ZERO, Angle.ZERO, Angle.ZERO, Angle.ZERO);
36 private final Angle minLatitude;
37 private final Angle maxLatitude;
38 private final Angle minLongitude;
39 private final Angle maxLongitude;
40 private final Angle deltaLat;
41 private final Angle deltaLon;
43 /**
44 * Creates a new <code>Sector</code> and initializes it to the specified angles. The angles are assumed to be
45 * normalized to +/- 90 degrees latitude and +/- 180 degrees longitude, but this method does not verify that.
47 * @param minLatitude the sector's minimum latitude in degrees.
48 * @param maxLatitude the sector's maximum latitude in degrees.
49 * @param minLongitude the sector's minimum longitude in degrees.
50 * @param maxLongitude the sector's maximum longitude in degrees.
51 * @return the new <code>Sector</code>
53 public static Sector fromDegrees(double minLatitude, double maxLatitude, double minLongitude,
54 double maxLongitude)
56 return new Sector(Angle.fromDegrees(minLatitude), Angle.fromDegrees(maxLatitude), Angle.fromDegrees(
57 minLongitude), Angle.fromDegrees(maxLongitude));
60 /**
61 * Creates a new <code>Sector</code> and initializes it to the specified angles. The angles are assumed to be
62 * normalized to +/- \u03c0/2 radians latitude and +/- \u03c0 radians longitude, but this method does not verify
63 * that.
65 * @param minLatitude the sector's minimum latitude in radians.
66 * @param maxLatitude the sector's maximum latitude in radians.
67 * @param minLongitude the sector's minimum longitude in radians.
68 * @param maxLongitude the sector's maximum longitude in radians.
69 * @return the new <code>Sector</code>
71 public static Sector fromRadians(double minLatitude, double maxLatitude, double minLongitude,
72 double maxLongitude)
74 return new Sector(Angle.fromRadians(minLatitude), Angle.fromRadians(maxLatitude), Angle.fromRadians(
75 minLongitude), Angle.fromRadians(maxLongitude));
78 public static Sector boundingSector(java.util.Iterator<TrackPoint> positions)
80 if (positions == null)
82 String message = Logging.getMessage("nullValue.TracksPointsIteratorNull");
83 Logging.logger().severe(message);
84 throw new IllegalArgumentException(message);
87 if (!positions.hasNext())
88 return EMPTY_SECTOR;
90 TrackPoint position = positions.next();
91 double minLat = position.getLatitude();
92 double minLon = position.getLongitude();
93 double maxLat = minLat;
94 double maxLon = minLon;
96 while (positions.hasNext())
98 TrackPoint p = positions.next();
99 double lat = p.getLatitude();
100 if (lat < minLat)
101 minLat = lat;
102 else if (lat > maxLat)
103 maxLat = lat;
105 double lon = p.getLongitude();
106 if (lon < minLon)
107 minLon = lon;
108 else if (lon > maxLon)
109 maxLon = lon;
112 return Sector.fromDegrees(minLat, maxLat, minLon, maxLon);
115 public static Sector boundingSector(Iterable<LatLon> positions)
117 if (positions == null)
119 String message = Logging.getMessage("nullValue.PositionsListIsNull");
120 Logging.logger().severe(message);
121 throw new IllegalArgumentException(message);
124 double minLat = Angle.POS90.getDegrees();
125 double minLon = Angle.POS180.getDegrees();
126 double maxLat = Angle.NEG180.getDegrees();
127 double maxLon = Angle.NEG180.getDegrees();
129 for (LatLon p : positions)
131 double lat = p.getLatitude().getDegrees();
132 if (lat < minLat)
133 minLat = lat;
134 if (lat > maxLat)
135 maxLat = lat;
137 double lon = p.getLongitude().getDegrees();
138 if (lon < minLon)
139 minLon = lon;
140 if (lon > maxLon)
141 maxLon = lon;
144 if (minLat == maxLat && minLon == maxLon)
145 return EMPTY_SECTOR;
147 return Sector.fromDegrees(minLat, maxLat, minLon, maxLon);
150 public static Sector boundingSector(Position pA, Position pB)
152 if (pA == null || pB == null)
154 String message = Logging.getMessage("nullValue.PositionsListIsNull");
155 Logging.logger().severe(message);
156 throw new IllegalArgumentException(message);
159 double minLat = pA.getLatitude().degrees;
160 double minLon = pA.getLongitude().degrees;
161 double maxLat = pA.getLatitude().degrees;
162 double maxLon = pA.getLongitude().degrees;
164 if (pB.getLatitude().degrees < minLat)
165 minLat = pB.getLatitude().degrees;
166 else if (pB.getLatitude().degrees > maxLat)
167 maxLat = pB.getLatitude().degrees;
169 if (pB.getLongitude().degrees < minLon)
170 minLon = pB.getLongitude().degrees;
171 else if (pB.getLongitude().degrees > maxLon)
172 maxLon = pB.getLongitude().degrees;
174 if (minLat == maxLat && minLon == maxLon)
175 return EMPTY_SECTOR;
177 return Sector.fromDegrees(minLat, maxLat, minLon, maxLon);
181 * Creates a new <code>Sector</code> and initializes it to the specified angles. The angles are assumed to be
182 * normalized to +/- 90 degrees latitude and +/- 180 degrees longitude, but this method does not verify that.
184 * @param minLatitude the sector's minimum latitude.
185 * @param maxLatitude the sector's maximum latitude.
186 * @param minLongitude the sector's minimum longitude.
187 * @param maxLongitude the sector's maximum longitude.
188 * @throws IllegalArgumentException if any of the angles are null
190 public Sector(Angle minLatitude, Angle maxLatitude, Angle minLongitude, Angle maxLongitude)
192 if (minLatitude == null || maxLatitude == null || minLongitude == null || maxLongitude == null)
194 String message = Logging.getMessage("nullValue.InputAnglesNull");
195 Logging.logger().severe(message);
196 throw new IllegalArgumentException(message);
199 this.minLatitude = minLatitude;
200 this.maxLatitude = maxLatitude;
201 this.minLongitude = minLongitude;
202 this.maxLongitude = maxLongitude;
203 this.deltaLat = Angle.fromDegrees(this.maxLatitude.degrees - this.minLatitude.degrees);
204 this.deltaLon = Angle.fromDegrees(this.maxLongitude.degrees - this.minLongitude.degrees);
207 public Sector(Sector sector)
209 if (sector == null)
211 String message = Logging.getMessage("nullValue.SectorIsNull");
212 Logging.logger().severe(message);
213 throw new IllegalArgumentException(message);
216 this.minLatitude = new Angle(sector.getMinLatitude());
217 this.maxLatitude = new Angle(sector.getMaxLatitude());
218 this.minLongitude = new Angle(sector.getMinLongitude());
219 this.maxLongitude = new Angle(sector.getMaxLongitude());
220 this.deltaLat = Angle.fromDegrees(this.maxLatitude.degrees - this.minLatitude.degrees);
221 this.deltaLon = Angle.fromDegrees(this.maxLongitude.degrees - this.minLongitude.degrees);
225 * Returns the sector's minimum latitude.
227 * @return The sector's minimum latitude.
229 public final Angle getMinLatitude()
231 return minLatitude;
235 * Returns the sector's minimum longitude.
237 * @return The sector's minimum longitude.
239 public final Angle getMinLongitude()
241 return minLongitude;
245 * Returns the sector's maximum latitude.
247 * @return The sector's maximum latitude.
249 public final Angle getMaxLatitude()
251 return maxLatitude;
255 * Returns the sector's maximum longitude.
257 * @return The sector's maximum longitude.
259 public final Angle getMaxLongitude()
261 return maxLongitude;
265 * Returns the angular difference between the sector's minimum and maximum latitudes: max - min
267 * @return The angular difference between the sector's minimum and maximum latitudes.
269 public final Angle getDeltaLat()
271 return this.deltaLat;//Angle.fromDegrees(this.maxLatitude.degrees - this.minLatitude.degrees);
274 public final double getDeltaLatDegrees()
276 return this.deltaLat.degrees;//this.maxLatitude.degrees - this.minLatitude.degrees;
279 public final double getDeltaLatRadians()
281 return this.deltaLat.radians;//this.maxLatitude.radians - this.minLatitude.radians;
285 * Returns the angular difference between the sector's minimum and maximum longitudes: max - min.
287 * @return The angular difference between the sector's minimum and maximum longitudes
289 public final Angle getDeltaLon()
291 return this.deltaLon;//Angle.fromDegrees(this.maxLongitude.degrees - this.minLongitude.degrees);
294 public final double getDeltaLonDegrees()
296 return this.deltaLon.degrees;//this.maxLongitude.degrees - this.minLongitude.degrees;
299 public final double getDeltaLonRadians()
301 return this.deltaLon.radians;//this.maxLongitude.radians - this.minLongitude.radians;
305 * Returns the latitude and longitude of the sector's angular center: (minimum latitude + maximum latitude) / 2,
306 * (minimum longitude + maximum longitude) / 2.
308 * @return The latitude and longitude of the sector's angular center
310 public final LatLon getCentroid()
312 Angle la = Angle.fromDegrees(0.5 * (this.getMaxLatitude().degrees + this.getMinLatitude().degrees));
313 Angle lo = Angle.fromDegrees(0.5 * (this.getMaxLongitude().degrees + this.getMinLongitude().degrees));
314 return new LatLon(la, lo);
317 public Vec4 computeCenterPoint(Globe globe)
319 if (globe == null)
321 String msg = Logging.getMessage("nullValue.GlobeIsNull");
322 Logging.logger().severe(msg);
323 throw new IllegalArgumentException(msg);
326 double lat = 0.5 * (this.minLatitude.degrees + this.maxLatitude.degrees);
327 double lon = 0.5 * (this.minLongitude.degrees + this.maxLongitude.degrees);
329 Angle cLat = Angle.fromDegrees(lat);
330 Angle cLon = Angle.fromDegrees(lon);
331 return globe.computePointFromPosition(cLat, cLon, globe.getElevation(cLat, cLon));
334 public Vec4[] computeCornerPoints(Globe globe)
336 if (globe == null)
338 String msg = Logging.getMessage("nullValue.GlobeIsNull");
339 Logging.logger().severe(msg);
340 throw new IllegalArgumentException(msg);
342 Vec4[] corners = new Vec4[4];
344 Angle minLat = this.minLatitude;
345 Angle maxLat = this.maxLatitude;
346 Angle minLon = this.minLongitude;
347 Angle maxLon = this.maxLongitude;
349 corners[0] = globe.computePointFromPosition(minLat, minLon, globe.getElevation(minLat, minLon));
350 corners[1] = globe.computePointFromPosition(minLat, maxLon, globe.getElevation(minLat, maxLon));
351 corners[2] = globe.computePointFromPosition(maxLat, maxLon, globe.getElevation(maxLat, maxLon));
352 corners[3] = globe.computePointFromPosition(maxLat, minLon, globe.getElevation(maxLat, minLon));
354 return corners;
358 * Returns a sphere that minimally surrounds the sector at a specified vertical exaggeration.
360 * @param globe the globe the sector is associated with
361 * @param verticalExaggeration the vertical exaggeration to apply to the globe's elevations when computing the
362 * sphere.
363 * @param sector the sector to return the bounding sphere for.
364 * @return The minimal bounding sphere in Cartesian coordinates.
365 * @throws IllegalArgumentException if <code>globe</code> or <code>sector</code> is null
367 static public Extent computeBoundingSphere(Globe globe, double verticalExaggeration, Sector sector)
369 if (globe == null)
371 String msg = Logging.getMessage("nullValue.GlobeIsNull");
372 Logging.logger().severe(msg);
373 throw new IllegalArgumentException(msg);
375 if (sector == null)
377 String msg = Logging.getMessage("nullValue.SectorIsNull");
378 Logging.logger().severe(msg);
379 throw new IllegalArgumentException(msg);
382 LatLon center = sector.getCentroid();
383 double maxHeight = globe.getMaxElevation() * verticalExaggeration;
384 double minHeight = 0;//globe.getMinElevation() * verticalExaggeration;
386 Vec4[] points = new Vec4[9];
387 points[0] = globe.computePointFromPosition(center.getLatitude(), center.getLongitude(), maxHeight);
388 points[1] = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMinLongitude(), maxHeight);
389 points[2] = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMaxLongitude(), maxHeight);
390 points[3] = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMinLongitude(), maxHeight);
391 points[4] = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMaxLongitude(), maxHeight);
392 points[5] = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMinLongitude(), minHeight);
393 points[6] = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMaxLongitude(), minHeight);
394 points[7] = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMinLongitude(), minHeight);
395 points[8] = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMaxLongitude(), minHeight);
397 return Sphere.createBoundingSphere(points);
401 * Returns a cylinder that minimally surrounds the sector at a specified vertical exaggeration.
403 * @param globe the globe the sector is associated with.
404 * @param verticalExaggeration the vertical exaggeration to apply to the globe's elevations when computing the
405 * cylinder.
406 * @param sector the sector to return the bounding cylinder for.
407 * @return The minimal bounding cylinder in Cartesian coordinates.
408 * @throws IllegalArgumentException if <code>globe</code> or <code>sector</code> is null
410 static public Cylinder computeBoundingCylinder(Globe globe, double verticalExaggeration, Sector sector)
412 if (globe == null)
414 String msg = Logging.getMessage("nullValue.GlobeIsNull");
415 Logging.logger().severe(msg);
416 throw new IllegalArgumentException(msg);
418 if (sector == null)
420 String msg = Logging.getMessage("nullValue.SectorIsNull");
421 Logging.logger().severe(msg);
422 throw new IllegalArgumentException(msg);
425 // Compute the center points of the bounding cylinder's top and bottom planes.
426 LatLon center = sector.getCentroid();
427 double maxHeight = globe.getMaxElevation() * verticalExaggeration;
428 double minHeight = 0;//globe.getMinElevation() * verticalExaggeration;
429 Vec4 centroidTop = globe.computePointFromPosition(center.getLatitude(), center.getLongitude(), maxHeight);
430 Vec4 lowPoint = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMinLongitude(), minHeight);
431 Vec4 axis = centroidTop.normalize3();
432 double lowDistance = axis.dot3(lowPoint);
433 Vec4 centroidBot = axis.multiply3(lowDistance);
435 // Compute radius of circumscribing circle around general quadrilateral.
436 Vec4 northwest = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMinLongitude(), maxHeight);
437 Vec4 southeast = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMaxLongitude(), maxHeight);
438 Vec4 southwest = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMinLongitude(), maxHeight);
439 Vec4 northeast = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMaxLongitude(), maxHeight);
440 double a = southwest.distanceTo3(southeast);
441 double b = southeast.distanceTo3(northeast);
442 double c = northeast.distanceTo3(northwest);
443 double d = northwest.distanceTo3(southwest);
444 double s = 0.5 * (a + b + c + d);
445 double area = Math.sqrt((s - a) * (s - b) * (s - c) * (s - d));
446 double radius = Math.sqrt((a * b + c * d) * (a * d + b * c) * (a * c + b * d)) / (4d * area);
448 return new Cylinder(centroidBot, centroidTop, radius);
451 public final boolean contains(Angle latitude, Angle longitude)
453 if (latitude == null || longitude == null)
455 String message = Logging.getMessage("nullValue.LatLonIsNull");
456 Logging.logger().severe(message);
457 throw new IllegalArgumentException(message);
460 return latitude.degrees >= this.minLatitude.degrees
461 && latitude.degrees <= this.maxLatitude.degrees
462 && longitude.degrees >= this.minLongitude.degrees
463 && longitude.degrees <= this.maxLongitude.degrees;
467 * Determines whether a latitude/longitude position is within the sector. The sector's angles are assumed to be
468 * normalized to +/- 90 degrees latitude and +/- 180 degrees longitude. The result of the operation is undefined if
469 * they are not.
471 * @param latLon the position to test, with angles normalized to +/- &#960 latitude and +/- 2&#960 longitude.
472 * @return <code>true</code> if the position is within the sector, <code>false</code> otherwise.
473 * @throws IllegalArgumentException if <code>latlon</code> is null.
475 public final boolean contains(LatLon latLon)
477 if (latLon == null)
479 String message = Logging.getMessage("nullValue.LatLonIsNull");
480 Logging.logger().severe(message);
481 throw new IllegalArgumentException(message);
484 return this.contains(latLon.getLatitude(), latLon.getLongitude());
488 * Determines whether a latitude/longitude postion expressed in radians is within the sector. The sector's angles
489 * are assumed to be normalized to +/- 90 degrees latitude and +/- 180 degrees longitude. The result of the
490 * operation is undefined if they are not.
492 * @param radiansLatitude the latitude in radians of the position to test, normalized +/- &#960.
493 * @param radiansLongitude the longitude in radians of the position to test, normalized +/- 2&#960.
494 * @return <code>true</code> if the position is within the sector, <code>false</code> otherwise.
496 public final boolean containsRadians(double radiansLatitude, double radiansLongitude)
498 return radiansLatitude >= this.minLatitude.radians && radiansLatitude <= this.maxLatitude.radians
499 && radiansLongitude >= this.minLongitude.radians && radiansLongitude <= this.maxLongitude.radians;
502 public final boolean containsDegrees(double degreesLatitude, double degreesLongitude)
504 return degreesLatitude >= this.minLatitude.degrees && degreesLatitude <= this.maxLatitude.degrees
505 && degreesLongitude >= this.minLongitude.degrees && degreesLongitude <= this.maxLongitude.degrees;
509 * Determines whether this sector intersects another sector's range of latitude and longitude. The sector's angles
510 * are assumed to be normalized to +/- 90 degrees latitude and +/- 180 degrees longitude. The result of the
511 * operation is undefined if they are not.
513 * @param that the sector to test for intersection.
514 * @return <code>true</code> if the sectors intersect, otherwise <code>false</code>.
516 public boolean intersects(Sector that)
518 if (that == null)
519 return false;
521 // Assumes normalized angles -- [-180, 180], [-90, 90] // TODO: have Angle normalize values when set
522 if (that.maxLongitude.degrees < this.minLongitude.degrees)
523 return false;
524 if (that.minLongitude.degrees > this.maxLongitude.degrees)
525 return false;
526 if (that.maxLatitude.degrees < this.minLatitude.degrees)
527 return false;
528 //noinspection RedundantIfStatement
529 if (that.minLatitude.degrees > this.maxLatitude.degrees)
530 return false;
532 return true;
536 * Returns a new sector whose angles are the extremes of the this sector and another. The new sector's minimum
537 * latitude and longitude will be the minimum of the two sectors. The new sector's maximum latitude and longitude
538 * will be the maximum of the two sectors. The sectors are assumed to be normalized to +/- 90 degrees latitude and
539 * +/- 180 degrees longitude. The result of the operation is undefined if they are not.
541 * @param that the sector to join with <code>this</code>.
542 * @return A new sector formed from the extremes of the two sectors, or <code>this</code> if the incoming sector is
543 * <code>null</code>.
545 public final Sector union(Sector that)
547 if (that == null)
548 return this;
550 Angle minLat = this.minLatitude;
551 Angle maxLat = this.maxLatitude;
552 Angle minLon = this.minLongitude;
553 Angle maxLon = this.maxLongitude;
555 if (that.minLatitude.degrees < this.minLatitude.degrees)
556 minLat = that.minLatitude;
557 if (that.maxLatitude.degrees > this.maxLatitude.degrees)
558 maxLat = that.maxLatitude;
559 if (that.minLongitude.degrees < this.minLongitude.degrees)
560 minLon = that.minLongitude;
561 if (that.maxLongitude.degrees > this.maxLongitude.degrees)
562 maxLon = that.maxLongitude;
564 return new Sector(minLat, maxLat, minLon, maxLon);
567 public final Sector union(Angle latitude, Angle longitude)
569 if (latitude == null || longitude == null)
570 return this;
572 Angle minLat = this.minLatitude;
573 Angle maxLat = this.maxLatitude;
574 Angle minLon = this.minLongitude;
575 Angle maxLon = this.maxLongitude;
577 if (latitude.degrees < this.minLatitude.degrees)
578 minLat = latitude;
579 if (latitude.degrees > this.maxLatitude.degrees)
580 maxLat = latitude;
581 if (longitude.degrees < this.minLongitude.degrees)
582 minLon = longitude;
583 if (longitude.degrees > this.maxLongitude.degrees)
584 maxLon = longitude;
586 return new Sector(minLat, maxLat, minLon, maxLon);
589 public static Sector union(Sector sectorA, Sector sectorB)
591 if (sectorA == null || sectorB == null)
593 if (sectorA == sectorB)
594 return null; // TODO: throw exception
596 return sectorB == null ? sectorA : sectorB;
599 return sectorA.union(sectorB);
602 public final Sector intersection(Sector that)
604 if (that == null)
605 return this;
607 Angle minLat, maxLat;
608 minLat = (this.minLatitude.degrees > that.minLatitude.degrees) ? this.minLatitude : that.minLatitude;
609 maxLat = (this.maxLatitude.degrees < that.maxLatitude.degrees) ? this.maxLatitude : that.maxLatitude;
610 if (minLat.degrees > maxLat.degrees)
611 return null;
613 Angle minLon, maxLon;
614 minLon = (this.minLongitude.degrees > that.minLongitude.degrees) ? this.minLongitude : that.minLongitude;
615 maxLon = (this.maxLongitude.degrees < that.maxLongitude.degrees) ? this.maxLongitude : that.maxLongitude;
616 if (minLon.degrees > maxLon.degrees)
617 return null;
619 return new Sector(minLat, maxLat, minLon, maxLon);
622 public final Sector intersection(Angle latitude, Angle longitude)
624 if (latitude == null || longitude == null)
625 return this;
627 if (!this.contains(latitude, longitude))
628 return null;
629 return new Sector(latitude, latitude, longitude, longitude);
632 public final Sector[] subdivide()
634 Angle midLat = Angle.average(this.minLatitude, this.maxLatitude);
635 Angle midLon = Angle.average(this.minLongitude, this.maxLongitude);
637 Sector[] sectors = new Sector[4];
638 sectors[0] = new Sector(this.minLatitude, midLat, this.minLongitude, midLon);
639 sectors[1] = new Sector(this.minLatitude, midLat, midLon, this.maxLongitude);
640 sectors[2] = new Sector(midLat, this.maxLatitude, this.minLongitude, midLon);
641 sectors[3] = new Sector(midLat, this.maxLatitude, midLon, this.maxLongitude);
643 return sectors;
647 * Returns a string indicating the sector's angles.
649 * @return A string indicating the sector's angles.
651 @Override
652 public String toString()
654 java.lang.StringBuffer sb = new java.lang.StringBuffer();
655 sb.append("(");
656 sb.append(this.minLatitude.toString());
657 sb.append(", ");
658 sb.append(this.minLongitude.toString());
659 sb.append(")");
661 sb.append(", ");
663 sb.append("(");
664 sb.append(this.maxLatitude.toString());
665 sb.append(", ");
666 sb.append(this.maxLongitude.toString());
667 sb.append(")");
669 return sb.toString();
673 * Retrieve the size of this object in bytes. This implementation returns an exact value of the object's size.
675 * @return the size of this object in bytes
677 public long getSizeInBytes()
679 return 4 * minLatitude.getSizeInBytes(); // 4 angles
683 * Compares this sector to a specified sector according to their minimum latitude, minimum longitude, maximum
684 * latitude, and maximum longitude, respectively.
686 * @param that the <code>Sector</code> to compareTo with <code>this</code>.
687 * @return -1 if this sector compares less than that specified, 0 if they're equal, and 1 if it compares greater.
688 * @throws IllegalArgumentException if <code>that</code> is null
690 public int compareTo(Sector that)
692 if (that == null)
694 String msg = Logging.getMessage("nullValue.SectorIsNull");
695 Logging.logger().severe(msg);
696 throw new IllegalArgumentException(msg);
699 if (this.getMinLatitude().compareTo(that.getMinLatitude()) < 0)
700 return -1;
702 if (this.getMinLatitude().compareTo(that.getMinLatitude()) > 0)
703 return 1;
705 if (this.getMinLongitude().compareTo(that.getMinLongitude()) < 0)
706 return -1;
708 if (this.getMinLongitude().compareTo(that.getMinLongitude()) > 0)
709 return 1;
711 if (this.getMaxLatitude().compareTo(that.getMaxLatitude()) < 0)
712 return -1;
714 if (this.getMaxLatitude().compareTo(that.getMaxLatitude()) > 0)
715 return 1;
717 if (this.getMaxLongitude().compareTo(that.getMaxLongitude()) < 0)
718 return -1;
720 if (this.getMaxLongitude().compareTo(that.getMaxLongitude()) > 0)
721 return 1;
723 return 0;
727 * Tests the equality of the sectors' angles. Sectors are equal if all of their corresponding angles are equal.
729 * @param o the sector to compareTo with <code>this</code>.
730 * @return <code>true</code> if the four corresponding angles of each sector are equal, <code>false</code>
731 * otherwise.
733 @Override
734 public boolean equals(Object o)
736 if (this == o)
737 return true;
738 if (o == null || getClass() != o.getClass())
739 return false;
741 final gov.nasa.worldwind.geom.Sector sector = (gov.nasa.worldwind.geom.Sector) o;
743 if (!maxLatitude.equals(sector.maxLatitude))
744 return false;
745 if (!maxLongitude.equals(sector.maxLongitude))
746 return false;
747 if (!minLatitude.equals(sector.minLatitude))
748 return false;
749 //noinspection RedundantIfStatement
750 if (!minLongitude.equals(sector.minLongitude))
751 return false;
753 return true;
757 * Computes a hash code from the sector's four angles.
759 * @return a hash code incorporating the sector's four angles.
761 @Override
762 public int hashCode()
764 int result;
765 result = minLatitude.hashCode();
766 result = 29 * result + maxLatitude.hashCode();
767 result = 29 * result + minLongitude.hashCode();
768 result = 29 * result + maxLongitude.hashCode();
769 return result;