Update to Worldwind release 0.4.1
[worldwind-tracker.git] / gov / nasa / worldwind / geom / Sector.java
blobcfc60dbfbc28bab902fbe667ef62091e0a30592f
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 3307 2007-10-16 14:43:49Z patrickmurris $
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 boundingSectorfromLatLons(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 boundingSectorfromPositions(Iterable<Position> positions)
152 if (positions == null)
154 String message = Logging.getMessage("nullValue.PositionsListIsNull");
155 Logging.logger().severe(message);
156 throw new IllegalArgumentException(message);
159 double minLat = Angle.POS90.getDegrees();
160 double minLon = Angle.POS180.getDegrees();
161 double maxLat = Angle.NEG180.getDegrees();
162 double maxLon = Angle.NEG180.getDegrees();
164 for (Position p : positions)
166 double lat = p.getLatitude().getDegrees();
167 if (lat < minLat)
168 minLat = lat;
169 if (lat > maxLat)
170 maxLat = lat;
172 double lon = p.getLongitude().getDegrees();
173 if (lon < minLon)
174 minLon = lon;
175 if (lon > maxLon)
176 maxLon = lon;
179 if (minLat == maxLat && minLon == maxLon)
180 return EMPTY_SECTOR;
182 return Sector.fromDegrees(minLat, maxLat, minLon, maxLon);
185 public static Sector boundingSector(Position pA, Position pB)
187 if (pA == null || pB == null)
189 String message = Logging.getMessage("nullValue.PositionsListIsNull");
190 Logging.logger().severe(message);
191 throw new IllegalArgumentException(message);
194 double minLat = pA.getLatitude().degrees;
195 double minLon = pA.getLongitude().degrees;
196 double maxLat = pA.getLatitude().degrees;
197 double maxLon = pA.getLongitude().degrees;
199 if (pB.getLatitude().degrees < minLat)
200 minLat = pB.getLatitude().degrees;
201 else if (pB.getLatitude().degrees > maxLat)
202 maxLat = pB.getLatitude().degrees;
204 if (pB.getLongitude().degrees < minLon)
205 minLon = pB.getLongitude().degrees;
206 else if (pB.getLongitude().degrees > maxLon)
207 maxLon = pB.getLongitude().degrees;
209 if (minLat == maxLat && minLon == maxLon)
210 return EMPTY_SECTOR;
212 return Sector.fromDegrees(minLat, maxLat, minLon, maxLon);
216 * Creates a new <code>Sector</code> and initializes it to the specified angles. The angles are assumed to be
217 * normalized to +/- 90 degrees latitude and +/- 180 degrees longitude, but this method does not verify that.
219 * @param minLatitude the sector's minimum latitude.
220 * @param maxLatitude the sector's maximum latitude.
221 * @param minLongitude the sector's minimum longitude.
222 * @param maxLongitude the sector's maximum longitude.
223 * @throws IllegalArgumentException if any of the angles are null
225 public Sector(Angle minLatitude, Angle maxLatitude, Angle minLongitude, Angle maxLongitude)
227 if (minLatitude == null || maxLatitude == null || minLongitude == null || maxLongitude == null)
229 String message = Logging.getMessage("nullValue.InputAnglesNull");
230 Logging.logger().severe(message);
231 throw new IllegalArgumentException(message);
234 this.minLatitude = minLatitude;
235 this.maxLatitude = maxLatitude;
236 this.minLongitude = minLongitude;
237 this.maxLongitude = maxLongitude;
238 this.deltaLat = Angle.fromDegrees(this.maxLatitude.degrees - this.minLatitude.degrees);
239 this.deltaLon = Angle.fromDegrees(this.maxLongitude.degrees - this.minLongitude.degrees);
242 public Sector(Sector sector)
244 if (sector == null)
246 String message = Logging.getMessage("nullValue.SectorIsNull");
247 Logging.logger().severe(message);
248 throw new IllegalArgumentException(message);
251 this.minLatitude = new Angle(sector.getMinLatitude());
252 this.maxLatitude = new Angle(sector.getMaxLatitude());
253 this.minLongitude = new Angle(sector.getMinLongitude());
254 this.maxLongitude = new Angle(sector.getMaxLongitude());
255 this.deltaLat = Angle.fromDegrees(this.maxLatitude.degrees - this.minLatitude.degrees);
256 this.deltaLon = Angle.fromDegrees(this.maxLongitude.degrees - this.minLongitude.degrees);
260 * Returns the sector's minimum latitude.
262 * @return The sector's minimum latitude.
264 public final Angle getMinLatitude()
266 return minLatitude;
270 * Returns the sector's minimum longitude.
272 * @return The sector's minimum longitude.
274 public final Angle getMinLongitude()
276 return minLongitude;
280 * Returns the sector's maximum latitude.
282 * @return The sector's maximum latitude.
284 public final Angle getMaxLatitude()
286 return maxLatitude;
290 * Returns the sector's maximum longitude.
292 * @return The sector's maximum longitude.
294 public final Angle getMaxLongitude()
296 return maxLongitude;
300 * Returns the angular difference between the sector's minimum and maximum latitudes: max - min
302 * @return The angular difference between the sector's minimum and maximum latitudes.
304 public final Angle getDeltaLat()
306 return this.deltaLat;//Angle.fromDegrees(this.maxLatitude.degrees - this.minLatitude.degrees);
309 public final double getDeltaLatDegrees()
311 return this.deltaLat.degrees;//this.maxLatitude.degrees - this.minLatitude.degrees;
314 public final double getDeltaLatRadians()
316 return this.deltaLat.radians;//this.maxLatitude.radians - this.minLatitude.radians;
320 * Returns the angular difference between the sector's minimum and maximum longitudes: max - min.
322 * @return The angular difference between the sector's minimum and maximum longitudes
324 public final Angle getDeltaLon()
326 return this.deltaLon;//Angle.fromDegrees(this.maxLongitude.degrees - this.minLongitude.degrees);
329 public final double getDeltaLonDegrees()
331 return this.deltaLon.degrees;//this.maxLongitude.degrees - this.minLongitude.degrees;
334 public final double getDeltaLonRadians()
336 return this.deltaLon.radians;//this.maxLongitude.radians - this.minLongitude.radians;
340 * Returns the latitude and longitude of the sector's angular center: (minimum latitude + maximum latitude) / 2,
341 * (minimum longitude + maximum longitude) / 2.
343 * @return The latitude and longitude of the sector's angular center
345 public final LatLon getCentroid()
347 Angle la = Angle.fromDegrees(0.5 * (this.getMaxLatitude().degrees + this.getMinLatitude().degrees));
348 Angle lo = Angle.fromDegrees(0.5 * (this.getMaxLongitude().degrees + this.getMinLongitude().degrees));
349 return new LatLon(la, lo);
352 public Vec4 computeCenterPoint(Globe globe)
354 if (globe == null)
356 String msg = Logging.getMessage("nullValue.GlobeIsNull");
357 Logging.logger().severe(msg);
358 throw new IllegalArgumentException(msg);
361 double lat = 0.5 * (this.minLatitude.degrees + this.maxLatitude.degrees);
362 double lon = 0.5 * (this.minLongitude.degrees + this.maxLongitude.degrees);
364 Angle cLat = Angle.fromDegrees(lat);
365 Angle cLon = Angle.fromDegrees(lon);
366 return globe.computePointFromPosition(cLat, cLon, globe.getElevation(cLat, cLon));
369 public Vec4[] computeCornerPoints(Globe globe)
371 if (globe == null)
373 String msg = Logging.getMessage("nullValue.GlobeIsNull");
374 Logging.logger().severe(msg);
375 throw new IllegalArgumentException(msg);
377 Vec4[] corners = new Vec4[4];
379 Angle minLat = this.minLatitude;
380 Angle maxLat = this.maxLatitude;
381 Angle minLon = this.minLongitude;
382 Angle maxLon = this.maxLongitude;
384 corners[0] = globe.computePointFromPosition(minLat, minLon, globe.getElevation(minLat, minLon));
385 corners[1] = globe.computePointFromPosition(minLat, maxLon, globe.getElevation(minLat, maxLon));
386 corners[2] = globe.computePointFromPosition(maxLat, maxLon, globe.getElevation(maxLat, maxLon));
387 corners[3] = globe.computePointFromPosition(maxLat, minLon, globe.getElevation(maxLat, minLon));
389 return corners;
393 * Returns a sphere that minimally surrounds the sector at a specified vertical exaggeration.
395 * @param globe the globe the sector is associated with
396 * @param verticalExaggeration the vertical exaggeration to apply to the globe's elevations when computing the
397 * sphere.
398 * @param sector the sector to return the bounding sphere for.
399 * @return The minimal bounding sphere in Cartesian coordinates.
400 * @throws IllegalArgumentException if <code>globe</code> or <code>sector</code> is null
402 static public Extent computeBoundingSphere(Globe globe, double verticalExaggeration, Sector sector)
404 if (globe == null)
406 String msg = Logging.getMessage("nullValue.GlobeIsNull");
407 Logging.logger().severe(msg);
408 throw new IllegalArgumentException(msg);
410 if (sector == null)
412 String msg = Logging.getMessage("nullValue.SectorIsNull");
413 Logging.logger().severe(msg);
414 throw new IllegalArgumentException(msg);
417 LatLon center = sector.getCentroid();
418 double maxHeight = globe.getMaxElevation(sector) * verticalExaggeration;
419 double minHeight = globe.getMinElevation(sector) * verticalExaggeration;
421 Vec4[] points = new Vec4[9];
422 points[0] = globe.computePointFromPosition(center.getLatitude(), center.getLongitude(), maxHeight);
423 points[1] = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMinLongitude(), maxHeight);
424 points[2] = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMaxLongitude(), maxHeight);
425 points[3] = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMinLongitude(), maxHeight);
426 points[4] = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMaxLongitude(), maxHeight);
427 points[5] = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMinLongitude(), minHeight);
428 points[6] = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMaxLongitude(), minHeight);
429 points[7] = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMinLongitude(), minHeight);
430 points[8] = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMaxLongitude(), minHeight);
432 return Sphere.createBoundingSphere(points);
435 public final boolean contains(Angle latitude, Angle longitude)
437 if (latitude == null || longitude == null)
439 String message = Logging.getMessage("nullValue.LatLonIsNull");
440 Logging.logger().severe(message);
441 throw new IllegalArgumentException(message);
444 return latitude.degrees >= this.minLatitude.degrees
445 && latitude.degrees <= this.maxLatitude.degrees
446 && longitude.degrees >= this.minLongitude.degrees
447 && longitude.degrees <= this.maxLongitude.degrees;
451 * Determines whether a latitude/longitude position is within the sector. The sector's angles are assumed to be
452 * normalized to +/- 90 degrees latitude and +/- 180 degrees longitude. The result of the operation is undefined if
453 * they are not.
455 * @param latLon the position to test, with angles normalized to +/- &#960 latitude and +/- 2&#960 longitude.
456 * @return <code>true</code> if the position is within the sector, <code>false</code> otherwise.
457 * @throws IllegalArgumentException if <code>latlon</code> is null.
459 public final boolean contains(LatLon latLon)
461 if (latLon == null)
463 String message = Logging.getMessage("nullValue.LatLonIsNull");
464 Logging.logger().severe(message);
465 throw new IllegalArgumentException(message);
468 return this.contains(latLon.getLatitude(), latLon.getLongitude());
472 * Determines whether a latitude/longitude postion expressed in radians is within the sector. The sector's angles
473 * are assumed to be normalized to +/- 90 degrees latitude and +/- 180 degrees longitude. The result of the
474 * operation is undefined if they are not.
476 * @param radiansLatitude the latitude in radians of the position to test, normalized +/- &#960.
477 * @param radiansLongitude the longitude in radians of the position to test, normalized +/- 2&#960.
478 * @return <code>true</code> if the position is within the sector, <code>false</code> otherwise.
480 public final boolean containsRadians(double radiansLatitude, double radiansLongitude)
482 return radiansLatitude >= this.minLatitude.radians && radiansLatitude <= this.maxLatitude.radians
483 && radiansLongitude >= this.minLongitude.radians && radiansLongitude <= this.maxLongitude.radians;
486 public final boolean containsDegrees(double degreesLatitude, double degreesLongitude)
488 return degreesLatitude >= this.minLatitude.degrees && degreesLatitude <= this.maxLatitude.degrees
489 && degreesLongitude >= this.minLongitude.degrees && degreesLongitude <= this.maxLongitude.degrees;
493 * Determines whether this sector intersects another sector's range of latitude and longitude. The sector's angles
494 * are assumed to be normalized to +/- 90 degrees latitude and +/- 180 degrees longitude. The result of the
495 * operation is undefined if they are not.
497 * @param that the sector to test for intersection.
498 * @return <code>true</code> if the sectors intersect, otherwise <code>false</code>.
500 public boolean intersects(Sector that)
502 if (that == null)
503 return false;
505 // Assumes normalized angles -- [-180, 180], [-90, 90] // TODO: have Angle normalize values when set
506 if (that.maxLongitude.degrees < this.minLongitude.degrees)
507 return false;
508 if (that.minLongitude.degrees > this.maxLongitude.degrees)
509 return false;
510 if (that.maxLatitude.degrees < this.minLatitude.degrees)
511 return false;
512 //noinspection RedundantIfStatement
513 if (that.minLatitude.degrees > this.maxLatitude.degrees)
514 return false;
516 return true;
520 * Returns a new sector whose angles are the extremes of the this sector and another. The new sector's minimum
521 * latitude and longitude will be the minimum of the two sectors. The new sector's maximum latitude and longitude
522 * will be the maximum of the two sectors. The sectors are assumed to be normalized to +/- 90 degrees latitude and
523 * +/- 180 degrees longitude. The result of the operation is undefined if they are not.
525 * @param that the sector to join with <code>this</code>.
526 * @return A new sector formed from the extremes of the two sectors, or <code>this</code> if the incoming sector is
527 * <code>null</code>.
529 public final Sector union(Sector that)
531 if (that == null)
532 return this;
534 Angle minLat = this.minLatitude;
535 Angle maxLat = this.maxLatitude;
536 Angle minLon = this.minLongitude;
537 Angle maxLon = this.maxLongitude;
539 if (that.minLatitude.degrees < this.minLatitude.degrees)
540 minLat = that.minLatitude;
541 if (that.maxLatitude.degrees > this.maxLatitude.degrees)
542 maxLat = that.maxLatitude;
543 if (that.minLongitude.degrees < this.minLongitude.degrees)
544 minLon = that.minLongitude;
545 if (that.maxLongitude.degrees > this.maxLongitude.degrees)
546 maxLon = that.maxLongitude;
548 return new Sector(minLat, maxLat, minLon, maxLon);
551 public final Sector union(Angle latitude, Angle longitude)
553 if (latitude == null || longitude == null)
554 return this;
556 Angle minLat = this.minLatitude;
557 Angle maxLat = this.maxLatitude;
558 Angle minLon = this.minLongitude;
559 Angle maxLon = this.maxLongitude;
561 if (latitude.degrees < this.minLatitude.degrees)
562 minLat = latitude;
563 if (latitude.degrees > this.maxLatitude.degrees)
564 maxLat = latitude;
565 if (longitude.degrees < this.minLongitude.degrees)
566 minLon = longitude;
567 if (longitude.degrees > this.maxLongitude.degrees)
568 maxLon = longitude;
570 return new Sector(minLat, maxLat, minLon, maxLon);
573 public static Sector union(Sector sectorA, Sector sectorB)
575 if (sectorA == null || sectorB == null)
577 if (sectorA == sectorB)
578 return null; // TODO: throw exception
580 return sectorB == null ? sectorA : sectorB;
583 return sectorA.union(sectorB);
586 public final Sector intersection(Sector that)
588 if (that == null)
589 return this;
591 Angle minLat, maxLat;
592 minLat = (this.minLatitude.degrees > that.minLatitude.degrees) ? this.minLatitude : that.minLatitude;
593 maxLat = (this.maxLatitude.degrees < that.maxLatitude.degrees) ? this.maxLatitude : that.maxLatitude;
594 if (minLat.degrees > maxLat.degrees)
595 return null;
597 Angle minLon, maxLon;
598 minLon = (this.minLongitude.degrees > that.minLongitude.degrees) ? this.minLongitude : that.minLongitude;
599 maxLon = (this.maxLongitude.degrees < that.maxLongitude.degrees) ? this.maxLongitude : that.maxLongitude;
600 if (minLon.degrees > maxLon.degrees)
601 return null;
603 return new Sector(minLat, maxLat, minLon, maxLon);
606 public final Sector intersection(Angle latitude, Angle longitude)
608 if (latitude == null || longitude == null)
609 return this;
611 if (!this.contains(latitude, longitude))
612 return null;
613 return new Sector(latitude, latitude, longitude, longitude);
616 public final Sector[] subdivide()
618 Angle midLat = Angle.average(this.minLatitude, this.maxLatitude);
619 Angle midLon = Angle.average(this.minLongitude, this.maxLongitude);
621 Sector[] sectors = new Sector[4];
622 sectors[0] = new Sector(this.minLatitude, midLat, this.minLongitude, midLon);
623 sectors[1] = new Sector(this.minLatitude, midLat, midLon, this.maxLongitude);
624 sectors[2] = new Sector(midLat, this.maxLatitude, this.minLongitude, midLon);
625 sectors[3] = new Sector(midLat, this.maxLatitude, midLon, this.maxLongitude);
627 return sectors;
631 * Returns a string indicating the sector's angles.
633 * @return A string indicating the sector's angles.
635 @Override
636 public String toString()
638 java.lang.StringBuffer sb = new java.lang.StringBuffer();
639 sb.append("(");
640 sb.append(this.minLatitude.toString());
641 sb.append(", ");
642 sb.append(this.minLongitude.toString());
643 sb.append(")");
645 sb.append(", ");
647 sb.append("(");
648 sb.append(this.maxLatitude.toString());
649 sb.append(", ");
650 sb.append(this.maxLongitude.toString());
651 sb.append(")");
653 return sb.toString();
657 * Retrieve the size of this object in bytes. This implementation returns an exact value of the object's size.
659 * @return the size of this object in bytes
661 public long getSizeInBytes()
663 return 4 * minLatitude.getSizeInBytes(); // 4 angles
667 * Compares this sector to a specified sector according to their minimum latitude, minimum longitude, maximum
668 * latitude, and maximum longitude, respectively.
670 * @param that the <code>Sector</code> to compareTo with <code>this</code>.
671 * @return -1 if this sector compares less than that specified, 0 if they're equal, and 1 if it compares greater.
672 * @throws IllegalArgumentException if <code>that</code> is null
674 public int compareTo(Sector that)
676 if (that == null)
678 String msg = Logging.getMessage("nullValue.SectorIsNull");
679 Logging.logger().severe(msg);
680 throw new IllegalArgumentException(msg);
683 if (this.getMinLatitude().compareTo(that.getMinLatitude()) < 0)
684 return -1;
686 if (this.getMinLatitude().compareTo(that.getMinLatitude()) > 0)
687 return 1;
689 if (this.getMinLongitude().compareTo(that.getMinLongitude()) < 0)
690 return -1;
692 if (this.getMinLongitude().compareTo(that.getMinLongitude()) > 0)
693 return 1;
695 if (this.getMaxLatitude().compareTo(that.getMaxLatitude()) < 0)
696 return -1;
698 if (this.getMaxLatitude().compareTo(that.getMaxLatitude()) > 0)
699 return 1;
701 if (this.getMaxLongitude().compareTo(that.getMaxLongitude()) < 0)
702 return -1;
704 if (this.getMaxLongitude().compareTo(that.getMaxLongitude()) > 0)
705 return 1;
707 return 0;
711 * Tests the equality of the sectors' angles. Sectors are equal if all of their corresponding angles are equal.
713 * @param o the sector to compareTo with <code>this</code>.
714 * @return <code>true</code> if the four corresponding angles of each sector are equal, <code>false</code>
715 * otherwise.
717 @Override
718 public boolean equals(Object o)
720 if (this == o)
721 return true;
722 if (o == null || getClass() != o.getClass())
723 return false;
725 final gov.nasa.worldwind.geom.Sector sector = (gov.nasa.worldwind.geom.Sector) o;
727 if (!maxLatitude.equals(sector.maxLatitude))
728 return false;
729 if (!maxLongitude.equals(sector.maxLongitude))
730 return false;
731 if (!minLatitude.equals(sector.minLatitude))
732 return false;
733 //noinspection RedundantIfStatement
734 if (!minLongitude.equals(sector.minLongitude))
735 return false;
737 return true;
741 * Computes a hash code from the sector's four angles.
743 * @return a hash code incorporating the sector's four angles.
745 @Override
746 public int hashCode()
748 int result;
749 result = minLatitude.hashCode();
750 result = 29 * result + maxLatitude.hashCode();
751 result = 29 * result + minLongitude.hashCode();
752 result = 29 * result + maxLongitude.hashCode();
753 return result;