Worldwind public release 0.2
[worldwind-tracker.git] / gov / nasa / worldwind / geom / Sector.java
blob640f3adb6f1eb63dcc16d9531ff9f0da1743a211
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.*;
11 /**
12 * <code>Sector</code> represents a rectangular reqion of latitude and longitude. The region is defined by four angles:
13 * its minimum and maximum latitude, its minimum and maximum longitude. The angles are assumed to be normalized to +/-
14 * 90 degrees latitude and +/- 180 degrees longitude. The minimums and maximums are relative to these ranges, e.g., -80
15 * is less than 20. Behavior of the class is undefined for angles outside these ranges. Normalization is not performed
16 * on the angles by this class, nor is it verifed by the class' methods. See {@link Angle} for a description of
17 * specifying angles.
18 * <p/>
19 * <code>Sector</code> instances are immutable. </p>
21 * @author Tom Gaskins
22 * @version $Id: Sector.java 1749 2007-05-06 19:48:14Z tgaskins $
23 * @see Angle
25 public class Sector implements Cacheable, Comparable<Sector>
27 /**
28 * A <code>Sector</code> of latitude [-90 degrees, + 90 degrees] and longitude [-180 degrees, + 180 degrees].
30 public static final Sector FULL_SPHERE = new Sector(Angle.NEG90, Angle.POS90, Angle.NEG180, Angle.POS180);
31 public static final Sector EMPTY_SECTOR = new Sector(Angle.ZERO, Angle.ZERO, Angle.ZERO, Angle.ZERO);
33 private final Angle minLatitude;
34 private final Angle maxLatitude;
35 private final Angle minLongitude;
36 private final Angle maxLongitude;
37 private final Angle deltaLat;
38 private final Angle deltaLon;
40 /**
41 * Creates a new <code>Sector</code> and initializes it to the specified angles. The angles are assumed to be
42 * normalized to +/- 90 degrees latitude and +/- 180 degrees longitude, but this method does not verify that.
44 * @param minLatitude the sector's minimum latitude in degrees.
45 * @param maxLatitude the sector's maximum latitude in degrees.
46 * @param minLongitude the sector's minimum longitude in degrees.
47 * @param maxLongitude the sector's maximum longitude in degrees.
48 * @return the new <code>Sector</code>
50 public static Sector fromDegrees(double minLatitude, double maxLatitude, double minLongitude,
51 double maxLongitude)
53 return new Sector(Angle.fromDegrees(minLatitude), Angle.fromDegrees(maxLatitude), Angle.fromDegrees(
54 minLongitude), Angle.fromDegrees(maxLongitude));
57 /**
58 * Creates a new <code>Sector</code> and initializes it to the specified angles. The angles are assumed to be
59 * normalized to +/- \u03c0/2 radians latitude and +/- \u03c0 radians longitude, but this method does not verify
60 * that.
62 * @param minLatitude the sector's minimum latitude in radians.
63 * @param maxLatitude the sector's maximum latitude in radians.
64 * @param minLongitude the sector's minimum longitude in radians.
65 * @param maxLongitude the sector's maximum longitude in radians.
66 * @return the new <code>Sector</code>
68 public static Sector fromRadians(double minLatitude, double maxLatitude, double minLongitude,
69 double maxLongitude)
71 return new Sector(Angle.fromRadians(minLatitude), Angle.fromRadians(maxLatitude), Angle.fromRadians(
72 minLongitude), Angle.fromRadians(maxLongitude));
75 public static Sector boundingSector(java.util.Iterator<TrackPoint> positions)
77 if (positions == null)
79 String message = WorldWind.retrieveErrMsg("nullValue.TracksPointsIteratorNull");
80 WorldWind.logger().log(java.util.logging.Level.FINE, message);
81 throw new IllegalArgumentException(message);
84 if (!positions.hasNext())
85 return EMPTY_SECTOR;
87 TrackPoint position = positions.next();
88 double minLat = position.getLatitude();
89 double minLon = position.getLongitude();
90 double maxLat = minLat;
91 double maxLon = minLon;
93 while (positions.hasNext())
95 TrackPoint p = positions.next();
96 double lat = p.getLatitude();
97 if (lat < minLat)
98 minLat = lat;
99 else if (lat > maxLat)
100 maxLat = lat;
102 double lon = p.getLongitude();
103 if (lon < minLon)
104 minLon = lon;
105 else if (lon > maxLon)
106 maxLon = lon;
109 return Sector.fromDegrees(minLat, maxLat, minLon, maxLon);
112 public static Sector boundingSector(Iterable<LatLon> positions)
114 if (positions == null)
116 String message = WorldWind.retrieveErrMsg("nullValue.PositionsListIsNull");
117 WorldWind.logger().log(java.util.logging.Level.FINE, message);
118 throw new IllegalArgumentException(message);
121 double minLat = Angle.POS90.getDegrees();
122 double minLon = Angle.POS180.getDegrees();
123 double maxLat = Angle.NEG180.getDegrees();
124 double maxLon = Angle.NEG180.getDegrees();
126 for (LatLon p : positions)
128 double lat = p.getLatitude().getDegrees();
129 if (lat < minLat)
130 minLat = lat;
131 if (lat > maxLat)
132 maxLat = lat;
134 double lon = p.getLongitude().getDegrees();
135 if (lon < minLon)
136 minLon = lon;
137 if (lon > maxLon)
138 maxLon = lon;
141 if (minLat == maxLat && minLon == maxLon)
142 return EMPTY_SECTOR;
144 return Sector.fromDegrees(minLat, maxLat, minLon, maxLon);
148 * Creates a new <code>Sector</code> and initializes it to the specified angles. The angles are assumed to be
149 * normalized to +/- 90 degrees latitude and +/- 180 degrees longitude, but this method does not verify that.
151 * @param minLatitude the sector's minimum latitude.
152 * @param maxLatitude the sector's maximum latitude.
153 * @param minLongitude the sector's minimum longitude.
154 * @param maxLongitude the sector's maximum longitude.
155 * @throws IllegalArgumentException if any of the angles are null
157 public Sector(Angle minLatitude, Angle maxLatitude, Angle minLongitude, Angle maxLongitude)
159 if (minLatitude == null || maxLatitude == null || minLongitude == null || maxLongitude == null)
161 String message = WorldWind.retrieveErrMsg("nullValue.InputAnglesNull");
162 WorldWind.logger().log(java.util.logging.Level.FINE, message);
163 throw new IllegalArgumentException(message);
166 this.minLatitude = minLatitude;
167 this.maxLatitude = maxLatitude;
168 this.minLongitude = minLongitude;
169 this.maxLongitude = maxLongitude;
170 this.deltaLat = Angle.fromDegrees(this.maxLatitude.degrees - this.minLatitude.degrees);
171 this.deltaLon = Angle.fromDegrees(this.maxLongitude.degrees - this.minLongitude.degrees);
174 public Sector(Sector sector)
176 if (sector == null)
178 String message = WorldWind.retrieveErrMsg("nullValue.SectorIsNull");
179 WorldWind.logger().log(java.util.logging.Level.FINE, message);
180 throw new IllegalArgumentException(message);
183 this.minLatitude = new Angle(sector.getMinLatitude());
184 this.maxLatitude = new Angle(sector.getMaxLatitude());
185 this.minLongitude = new Angle(sector.getMinLongitude());
186 this.maxLongitude = new Angle(sector.getMaxLongitude());
187 this.deltaLat = Angle.fromDegrees(this.maxLatitude.degrees - this.minLatitude.degrees);
188 this.deltaLon = Angle.fromDegrees(this.maxLongitude.degrees - this.minLongitude.degrees);
192 * Returns the sector's minimum latitude.
194 * @return The sector's minimum latitude.
196 public final Angle getMinLatitude()
198 return minLatitude;
202 * Returns the sector's minimum longitude.
204 * @return The sector's minimum longitude.
206 public final Angle getMinLongitude()
208 return minLongitude;
212 * Returns the sector's maximum latitude.
214 * @return The sector's maximum latitude.
216 public final Angle getMaxLatitude()
218 return maxLatitude;
222 * Returns the sector's maximum longitude.
224 * @return The sector's maximum longitude.
226 public final Angle getMaxLongitude()
228 return maxLongitude;
232 * Returns the angular difference between the sector's minimum and maximum latitudes: max - min
234 * @return The angular difference between the sector's minimum and maximum latitudes.
236 public final Angle getDeltaLat()
238 return this.deltaLat;//Angle.fromDegrees(this.maxLatitude.degrees - this.minLatitude.degrees);
241 public final double getDeltaLatDegrees()
243 return this.deltaLat.degrees;//this.maxLatitude.degrees - this.minLatitude.degrees;
246 public final double getDeltaLatRadians()
248 return this.deltaLat.radians;//this.maxLatitude.radians - this.minLatitude.radians;
252 * Returns the angular difference between the sector's minimum and maximum longitudes: max - min.
254 * @return The angular difference between the sector's minimum and maximum longitudes
256 public final Angle getDeltaLon()
258 return this.deltaLon;//Angle.fromDegrees(this.maxLongitude.degrees - this.minLongitude.degrees);
261 public final double getDeltaLonDegrees()
263 return this.deltaLon.degrees;//this.maxLongitude.degrees - this.minLongitude.degrees;
266 public final double getDeltaLonRadians()
268 return this.deltaLon.radians;//this.maxLongitude.radians - this.minLongitude.radians;
272 * Returns the latitude and longitude of the sector's angular center: (minimum latitude + maximum latitude) / 2,
273 * (minimum longitude + maximum longitude) / 2.
275 * @return The latitude and longitude of the sector's angular center
277 public final LatLon getCentroid()
279 Angle la = Angle.fromDegrees(0.5 * (this.getMaxLatitude().degrees + this.getMinLatitude().degrees));
280 Angle lo = Angle.fromDegrees(0.5 * (this.getMaxLongitude().degrees + this.getMinLongitude().degrees));
281 return new LatLon(la, lo);
284 public Point computeCenterPoint(Globe globe)
286 if (globe == null)
288 String msg = WorldWind.retrieveErrMsg("nullValue.GlobeIsNull");
289 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
290 throw new IllegalArgumentException(msg);
293 double lat = 0.5 * (this.minLatitude.degrees + this.maxLatitude.degrees);
294 double lon = 0.5 * (this.minLongitude.degrees + this.maxLongitude.degrees);
296 Angle cLat = Angle.fromDegrees(lat);
297 Angle cLon = Angle.fromDegrees(lon);
298 return globe.computePointFromPosition(cLat, cLon, globe.getElevation(cLat, cLon));
301 public Point[] computeCornerPoints(Globe globe)
303 if (globe == null)
305 String msg = WorldWind.retrieveErrMsg("nullValue.GlobeIsNull");
306 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
307 throw new IllegalArgumentException(msg);
309 Point[] corners = new Point[4];
311 Angle minLat = this.minLatitude;
312 Angle maxLat = this.maxLatitude;
313 Angle minLon = this.minLongitude;
314 Angle maxLon = this.maxLongitude;
316 corners[0] = globe.computePointFromPosition(minLat, minLon, globe.getElevation(minLat, minLon));
317 corners[1] = globe.computePointFromPosition(minLat, maxLon, globe.getElevation(minLat, maxLon));
318 corners[2] = globe.computePointFromPosition(maxLat, maxLon, globe.getElevation(maxLat, maxLon));
319 corners[3] = globe.computePointFromPosition(maxLat, minLon, globe.getElevation(maxLat, minLon));
321 return corners;
325 * Returns a sphere that minimally surrounds the sector at a specified vertical exaggeration.
327 * @param globe the globe the sector is associated with
328 * @param verticalExaggeration the vertical exaggeration to apply to the globe's elevations when computing the
329 * sphere.
330 * @param sector the sector to return the bounding sphere for.
331 * @return The minimal bounding sphere in Cartesian coordinates.
332 * @throws IllegalArgumentException if <code>globe</code> or <code>sector</code> is null
334 static public Extent computeBoundingSphere(Globe globe, double verticalExaggeration, Sector sector)
336 if (globe == null)
338 String msg = WorldWind.retrieveErrMsg("nullValue.GlobeIsNull");
339 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
340 throw new IllegalArgumentException(msg);
342 if (sector == null)
344 String msg = WorldWind.retrieveErrMsg("nullValue.SectorIsNull");
345 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
346 throw new IllegalArgumentException(msg);
349 LatLon center = sector.getCentroid();
350 double maxHeight = globe.getMaxElevation() * verticalExaggeration;
351 double minHeight = 0;//globe.getMinElevation() * verticalExaggeration;
353 Point[] points = new Point[9];
354 points[0] = globe.computePointFromPosition(center.getLatitude(), center.getLongitude(), maxHeight);
355 points[1] = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMinLongitude(), maxHeight);
356 points[2] = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMaxLongitude(), maxHeight);
357 points[3] = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMinLongitude(), maxHeight);
358 points[4] = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMaxLongitude(), maxHeight);
359 points[5] = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMinLongitude(), minHeight);
360 points[6] = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMaxLongitude(), minHeight);
361 points[7] = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMinLongitude(), minHeight);
362 points[8] = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMaxLongitude(), minHeight);
364 return Sphere.createBoundingSphere(points);
368 * Returns a cylinder that minimally surrounds the sector at a specified vertical exaggeration.
370 * @param globe the globe the sector is associated with.
371 * @param verticalExaggeration the vertical exaggeration to apply to the globe's elevations when computing the
372 * cylinder.
373 * @param sector the sector to return the bounding cylinder for.
374 * @return The minimal bounding cylinder in Cartesian coordinates.
375 * @throws IllegalArgumentException if <code>globe</code> or <code>sector</code> is null
377 static public Cylinder computeBoundingCylinder(Globe globe, double verticalExaggeration, Sector sector)
379 if (globe == null)
381 String msg = WorldWind.retrieveErrMsg("nullValue.GlobeIsNull");
382 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
383 throw new IllegalArgumentException(msg);
385 if (sector == null)
387 String msg = WorldWind.retrieveErrMsg("nullValue.SectorIsNull");
388 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
389 throw new IllegalArgumentException(msg);
392 // Compute the center points of the bounding cylinder's top and bottom planes.
393 LatLon center = sector.getCentroid();
394 double maxHeight = globe.getMaxElevation() * verticalExaggeration;
395 double minHeight = 0;//globe.getMinElevation() * verticalExaggeration;
396 Point centroidTop = globe.computePointFromPosition(center.getLatitude(), center.getLongitude(), maxHeight);
397 Point lowPoint = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMinLongitude(), minHeight);
398 Point axis = centroidTop.normalize();
399 double lowDistance = axis.dot(lowPoint);
400 Point centroidBot = axis.scale(lowDistance, lowDistance, lowDistance);
402 // Compute radius of circumscribing circle around general quadrilateral.
403 Point northwest = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMinLongitude(), maxHeight);
404 Point southeast = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMaxLongitude(), maxHeight);
405 Point southwest = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMinLongitude(), maxHeight);
406 Point northeast = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMaxLongitude(), maxHeight);
407 double a = southwest.distanceTo(southeast);
408 double b = southeast.distanceTo(northeast);
409 double c = northeast.distanceTo(northwest);
410 double d = northwest.distanceTo(southwest);
411 double s = 0.5 * (a + b + c + d);
412 double area = Math.sqrt((s - a) * (s - b) * (s - c) * (s - d));
413 double radius = Math.sqrt((a * b + c * d) * (a * d + b * c) * (a * c + b * d)) / (4d * area);
415 return new Cylinder(centroidBot, centroidTop, radius);
418 public final boolean contains(Angle latitude, Angle longitude)
420 if (latitude == null || longitude == null)
422 String message = WorldWind.retrieveErrMsg("nullValue.LatLonIsNull");
423 WorldWind.logger().log(java.util.logging.Level.FINE, message);
424 throw new IllegalArgumentException(message);
427 return latitude.degrees >= this.minLatitude.degrees
428 && latitude.degrees <= this.maxLatitude.degrees
429 && longitude.degrees >= this.minLongitude.degrees
430 && longitude.degrees <= this.maxLongitude.degrees;
434 * Determines whether a latitude/longitude position is within the sector. The sector's angles are assumed to be
435 * normalized to +/- 90 degrees latitude and +/- 180 degrees longitude. The result of the operation is undefined if
436 * they are not.
438 * @param latLon the position to test, with angles normalized to +/- &#960 latitude and +/- 2&#960 longitude.
439 * @return <code>true</code> if the position is within the sector, <code>false</code> otherwise.
440 * @throws IllegalArgumentException if <code>latlon</code> is null.
442 public final boolean contains(LatLon latLon)
444 if (latLon == null)
446 String message = WorldWind.retrieveErrMsg("nullValue.LatLonIsNull");
447 WorldWind.logger().log(java.util.logging.Level.FINE, message);
448 throw new IllegalArgumentException(message);
451 return this.contains(latLon.getLatitude(), latLon.getLongitude());
455 * Determines whether a latitude/longitude postion expressed in radians is within the sector. The sector's angles
456 * are assumed to be normalized to +/- 90 degrees latitude and +/- 180 degrees longitude. The result of the
457 * operation is undefined if they are not.
459 * @param radiansLatitude the latitude in radians of the position to test, normalized +/- &#960.
460 * @param radiansLongitude the longitude in radians of the position to test, normalized +/- 2&#960.
461 * @return <code>true</code> if the position is within the sector, <code>false</code> otherwise.
463 public final boolean containsRadians(double radiansLatitude, double radiansLongitude)
465 return radiansLatitude >= this.minLatitude.radians && radiansLatitude <= this.maxLatitude.radians
466 && radiansLongitude >= this.minLongitude.radians && radiansLongitude <= this.maxLongitude.radians;
469 public final boolean containsDegrees(double degreesLatitude, double degreesLongitude)
471 return degreesLatitude >= this.minLatitude.degrees && degreesLatitude <= this.maxLatitude.degrees
472 && degreesLongitude >= this.minLongitude.degrees && degreesLongitude <= this.maxLongitude.degrees;
476 * Determines whether this sector intersects another sector's range of latitude and longitude. The sector's angles
477 * are assumed to be normalized to +/- 90 degrees latitude and +/- 180 degrees longitude. The result of the
478 * operation is undefined if they are not.
480 * @param that the sector to test for intersection.
481 * @return <code>true</code> if the sectors intersect, otherwise <code>false</code>.
483 public boolean intersects(Sector that)
485 if (that == null)
486 return false;
488 // Assumes normalized angles -- [-180, 180], [-90, 90] // TODO: have Angle normalize values when set
489 if (that.maxLongitude.degrees < this.minLongitude.degrees)
490 return false;
491 if (that.minLongitude.degrees > this.maxLongitude.degrees)
492 return false;
493 if (that.maxLatitude.degrees < this.minLatitude.degrees)
494 return false;
495 //noinspection RedundantIfStatement
496 if (that.minLatitude.degrees > this.maxLatitude.degrees)
497 return false;
499 return true;
503 * Returns a new sector whose angles are the extremes of the this sector and another. The new sector's minimum
504 * latitude and longitude will be the minimum of the two sectors. The new sector's maximum latitude and longitude
505 * will be the maximum of the two sectors. The sectors are assumed to be normalized to +/- 90 degrees latitude and
506 * +/- 180 degrees longitude. The result of the operation is undefined if they are not.
508 * @param that the sector to join with <code>this</code>.
509 * @return A new sector formed from the extremes of the two sectors, or <code>this</code> if the incoming sector is
510 * <code>null</code>.
512 public final Sector union(Sector that)
514 if (that == null)
515 return this;
517 Angle minLat = this.minLatitude;
518 Angle maxLat = this.maxLatitude;
519 Angle minLon = this.minLongitude;
520 Angle maxLon = this.maxLongitude;
522 if (that.minLatitude.degrees < this.minLatitude.degrees)
523 minLat = that.minLatitude;
524 if (that.maxLatitude.degrees > this.maxLatitude.degrees)
525 maxLat = that.maxLatitude;
526 if (that.minLongitude.degrees < this.minLongitude.degrees)
527 minLon = that.minLongitude;
528 if (that.maxLongitude.degrees > this.maxLongitude.degrees)
529 maxLon = that.maxLongitude;
531 return new Sector(minLat, maxLat, minLon, maxLon);
534 public final Sector union(Angle latitude, Angle longitude)
536 if (latitude == null || longitude == null)
537 return this;
539 Angle minLat = this.minLatitude;
540 Angle maxLat = this.maxLatitude;
541 Angle minLon = this.minLongitude;
542 Angle maxLon = this.maxLongitude;
544 if (latitude.degrees < this.minLatitude.degrees)
545 minLat = latitude;
546 if (latitude.degrees > this.maxLatitude.degrees)
547 maxLat = latitude;
548 if (longitude.degrees < this.minLongitude.degrees)
549 minLon = longitude;
550 if (longitude.degrees > this.maxLongitude.degrees)
551 maxLon = longitude;
553 return new Sector(minLat, maxLat, minLon, maxLon);
556 public final Sector intersection(Sector that)
558 if (that == null)
559 return this;
561 Angle minLat, maxLat;
562 minLat = (this.minLatitude.degrees > that.minLatitude.degrees) ? this.minLatitude : that.minLatitude;
563 maxLat = (this.maxLatitude.degrees < that.maxLatitude.degrees) ? this.maxLatitude : that.maxLatitude;
564 if (minLat.degrees > maxLat.degrees)
565 return null;
567 Angle minLon, maxLon;
568 minLon = (this.minLongitude.degrees > that.minLongitude.degrees) ? this.minLongitude : that.minLongitude;
569 maxLon = (this.maxLongitude.degrees < that.maxLongitude.degrees) ? this.maxLongitude : that.maxLongitude;
570 if (minLon.degrees > maxLon.degrees)
571 return null;
573 return new Sector(minLat, maxLat, minLon, maxLon);
576 public final Sector intersection(Angle latitude, Angle longitude)
578 if (latitude == null || longitude == null)
579 return this;
581 if (!this.contains(latitude, longitude))
582 return null;
583 return new Sector(latitude, latitude, longitude, longitude);
586 public final Sector[] subdivide()
588 Angle midLat = Angle.average(this.minLatitude, this.maxLatitude);
589 Angle midLon = Angle.average(this.minLongitude, this.maxLongitude);
591 Sector[] sectors = new Sector[4];
592 sectors[0] = new Sector(this.minLatitude, midLat, this.minLongitude, midLon);
593 sectors[1] = new Sector(this.minLatitude, midLat, midLon, this.maxLongitude);
594 sectors[2] = new Sector(midLat, this.maxLatitude, this.minLongitude, midLon);
595 sectors[3] = new Sector(midLat, this.maxLatitude, midLon, this.maxLongitude);
597 return sectors;
601 * Returns a string indicating the sector's angles.
603 * @return A string indicating the sector's angles.
605 @Override
606 public String toString()
608 java.lang.StringBuffer sb = new java.lang.StringBuffer();
609 sb.append("(");
610 sb.append(this.minLatitude.toString());
611 sb.append(", ");
612 sb.append(this.minLongitude.toString());
613 sb.append(")");
615 sb.append(", ");
617 sb.append("(");
618 sb.append(this.maxLatitude.toString());
619 sb.append(", ");
620 sb.append(this.maxLongitude.toString());
621 sb.append(")");
623 return sb.toString();
627 * Retrieve the size of this object in bytes. This implementation returns an exact value of the object's size.
629 * @return the size of this object in bytes
631 public long getSizeInBytes()
633 return 4 * minLatitude.getSizeInBytes(); // 4 angles
637 * Compares this sector to a specified sector according to their minimum latitude, minimum longitude, maximum
638 * latitude, and maximum longitude, respectively.
640 * @param that the <code>Sector</code> to compareTo with <code>this</code>.
641 * @return -1 if this sector compares less than that specified, 0 if they're equal, and 1 if it compares greater.
642 * @throws IllegalArgumentException if <code>that</code> is null
644 public int compareTo(Sector that)
646 if (that == null)
648 String msg = WorldWind.retrieveErrMsg("nullValue.SectorIsNull");
649 WorldWind.logger().log(java.util.logging.Level.FINE, msg);
650 throw new IllegalArgumentException(msg);
653 if (this.getMinLatitude().compareTo(that.getMinLatitude()) < 0)
654 return -1;
656 if (this.getMinLatitude().compareTo(that.getMinLatitude()) > 0)
657 return 1;
659 if (this.getMinLongitude().compareTo(that.getMinLongitude()) < 0)
660 return -1;
662 if (this.getMinLongitude().compareTo(that.getMinLongitude()) > 0)
663 return 1;
665 if (this.getMaxLatitude().compareTo(that.getMaxLatitude()) < 0)
666 return -1;
668 if (this.getMaxLatitude().compareTo(that.getMaxLatitude()) > 0)
669 return 1;
671 if (this.getMaxLongitude().compareTo(that.getMaxLongitude()) < 0)
672 return -1;
674 if (this.getMaxLongitude().compareTo(that.getMaxLongitude()) > 0)
675 return 1;
677 return 0;
681 * Tests the equality of the sectors' angles. Sectors are equal if all of their corresponding angles are equal.
683 * @param o the sector to compareTo with <code>this</code>.
684 * @return <code>true</code> if the four corresponding angles of each sector are equal, <code>false</code>
685 * otherwise.
687 @Override
688 public boolean equals(Object o)
690 if (this == o)
691 return true;
692 if (o == null || getClass() != o.getClass())
693 return false;
695 final gov.nasa.worldwind.geom.Sector sector = (gov.nasa.worldwind.geom.Sector) o;
697 if (!maxLatitude.equals(sector.maxLatitude))
698 return false;
699 if (!maxLongitude.equals(sector.maxLongitude))
700 return false;
701 if (!minLatitude.equals(sector.minLatitude))
702 return false;
703 //noinspection RedundantIfStatement
704 if (!minLongitude.equals(sector.minLongitude))
705 return false;
707 return true;
711 * Computes a hash code from the sector's four angles.
713 * @return a hash code incorporating the sector's four angles.
715 @Override
716 public int hashCode()
718 int result;
719 result = minLatitude.hashCode();
720 result = 29 * result + maxLatitude.hashCode();
721 result = 29 * result + minLongitude.hashCode();
722 result = 29 * result + maxLongitude.hashCode();
723 return result;