Algorithm
Development Kit 1.0

algs.model
Interface ILineSegment

All Known Implementing Classes:
TwoDLineSegment

public interface ILineSegment

A Line Segment between two-dimensional points.

The common etiquette is that the start of a line segment has the higher y-value than the end of the line segment; note for horizontal line segments the start will be the one whose x-value is smaller (i.e., left-to-right).

Since:
1.0
Version:
1.0, 6/15/08
Author:
George Heineman

Field Summary
static int COINCIDENT
           
static int INTERSECTING
           
static int NON_INTERSECTING
           
static int PARALLEL
          Types of intersecting line segments.
 
Method Summary
 IPoint getEnd()
          Return the coordinate value of the End of the line segment as a two-dimensional IPoint.
 IPoint getStart()
          Return the coordinate value of the Start of the line segment as a two-dimensional IPoint.
 IPoint intersection(ILineSegment other)
          Return the intersection point with the given Line Segment, or null if no such intersection.
 boolean intersection(IPoint p)
          Determine if Line Segment intersects the given point.
 boolean isHorizontal()
          Determine if horizontal line.
 boolean isPoint()
          Determine if this line segment is simply a point (same start & end).
 boolean isVertical()
          Determine if vertical line.
 boolean pointOnLeft(IPoint p)
          Determine if the given point is to the left of the line segment, if we view the line segment from the lower (end) point to the upper (start) point.
 boolean pointOnRight(IPoint p)
          Determine if the given point is to the right of the line segment, if we view the line segment from the lower (end) point to the upper (start) point.
 int sign()
          Return the sign of the slope of the line segment.
 double slope()
          Return the slope of the line segment.
 double yIntercept()
          Return the y-intercept of the line segment if it were extended to be a full line.
 

Field Detail

PARALLEL

static final int PARALLEL
Types of intersecting line segments.

See Also:
Constant Field Values

COINCIDENT

static final int COINCIDENT
See Also:
Constant Field Values

INTERSECTING

static final int INTERSECTING
See Also:
Constant Field Values

NON_INTERSECTING

static final int NON_INTERSECTING
See Also:
Constant Field Values
Method Detail

getStart

IPoint getStart()
Return the coordinate value of the Start of the line segment as a two-dimensional IPoint. The start point will have a higher y-value than the end line, except for horizontal lines.


getEnd

IPoint getEnd()
Return the coordinate value of the End of the line segment as a two-dimensional IPoint. The end point will have a lower y-value than the end line, except for horizontal lines.


isPoint

boolean isPoint()
Determine if this line segment is simply a point (same start & end).


slope

double slope()
Return the slope of the line segment. For vertical lines, Double.NaN


sign

int sign()
Return the sign of the slope of the line segment. Vertical lines return 1. Horizontal lines return 0. Lines with positive slope return +1 while lines with negative slope return -1.


isHorizontal

boolean isHorizontal()
Determine if horizontal line.


isVertical

boolean isVertical()
Determine if vertical line.


intersection

IPoint intersection(ILineSegment other)
Return the intersection point with the given Line Segment, or null if no such intersection. Note that for overlapping line segments, it is unclear WHAT should be returned.


intersection

boolean intersection(IPoint p)
Determine if Line Segment intersects the given point.


pointOnRight

boolean pointOnRight(IPoint p)
Determine if the given point is to the right of the line segment, if we view the line segment from the lower (end) point to the upper (start) point.


pointOnLeft

boolean pointOnLeft(IPoint p)
Determine if the given point is to the left of the line segment, if we view the line segment from the lower (end) point to the upper (start) point.


yIntercept

double yIntercept()
Return the y-intercept of the line segment if it were extended to be a full line. For vertical lines, Double.NaN


Algorithm Development Kit 1.0

This code supports the Algorithms in a Nutshell book, published by O'Reilly Media, Inc. in November 2008. Please visit the book web page to learn of any changes to the code repository or to record a potential defect.