ps2
Class GeoSegment

java.lang.Object
  extended by ps2.GeoSegment

public class GeoSegment
extends Object

A GeoSegment models a straight line segment on the earth. GeoSegments are immutable.

A compass heading is a nonnegative real number less than 360. In compass headings, north = 0, east = 90, south = 180, and west = 270.

When used in a map, a GeoSegment might represent part of a street, boundary, or other feature. As an example usage, this map

  Penny Lane  a
              |
              i--j--k  Abbey Road
              |
              z
 
could be represented by the following GeoSegments: ("Penny Lane", a, i), ("Penny Lane", z, i), ("Abbey Road", i, j), and ("Abbey Road", j, k).

A name is given to all GeoSegment objects so that it is possible to differentiate between two GeoSegment objects with identical GeoPoint endpoints. Equality between GeoSegment objects requires that the names be equal String objects and the end points be equal GeoPoint objects.

Specification Fields
Derived Fields

Constructor Summary
GeoSegment(String name, GeoPoint p1, GeoPoint p2)
           
 
Method Summary
 boolean equals(Object gs)
          Compares the specified Object with with this GeoSegment for equality.
 double getHeading()
           
 double getLength()
           
 String getName()
           
 GeoPoint getP1()
           
 GeoPoint getP2()
           
 int hashCode()
           
 GeoSegment reverse()
          Returns a new GeoSegment like this one, but with its endpoints reversed.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GeoSegment

public GeoSegment(String name,
                  GeoPoint p1,
                  GeoPoint p2)
Requires:
name != null && p1 != null && p2 != null
Effects:
constructs a new GeoSegment with the specified name and endpoints
Method Detail

reverse

public GeoSegment reverse()
Returns a new GeoSegment like this one, but with its endpoints reversed.

Returns:
a new GeoSegment gs such that gs.name = this.name && gs.p1 = this.p2 && gs.p2 = this.p1

getName

public String getName()
Returns:
the name of this GeoSegment.

getP1

public GeoPoint getP1()
Returns:
first endpoint of the segment.

getP2

public GeoPoint getP2()
Returns:
second endpoint of the segment.

getLength

public double getLength()
Returns:
the length of the segment, using the flat-surface, near-Seattle approximation.

getHeading

public double getHeading()
Returns:
the compass heading from p1 to p2, in degrees, using the flat-surface, near-Seattle approximation.
Requires:
this.length != 0

equals

public boolean equals(Object gs)
Compares the specified Object with with this GeoSegment for equality.

Overrides:
equals in class Object
Returns:
gs != null && (gs instanceof GeoSegment) && gs.name = this.name && gs.p1 = this.p1 && gs.p2 = this.p2

hashCode

public int hashCode()
Overrides:
hashCode in class Object
Returns:
a valid hashcode for this.

toString

public String toString()
Overrides:
toString in class Object
Returns:
a string representation of this.