shady.common
Class AbstractSegment

java.lang.Object
  extended by shady.common.AbstractSegment
Direct Known Subclasses:
Segment

public abstract class AbstractSegment
extends java.lang.Object

An abstract 2D line segment.

Copyright (C) 2006 Marsette A. Vona, III

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Author:
Marsette (Marty) A. Vona, III

Field Summary
private static java.lang.String cvsid
          CVS id.
 
Constructor Summary
AbstractSegment()
           
 
Method Summary
 double getEndX()
          Get the end x coord, if any.
 double getEndY()
          Get the end y coord, if any.
 double getLength()
          Get the length .
 double getLengthSq()
          Get the length squared.
 double getOrientation()
          Get the orientation of this Segment relative to the positive x axis, in degrees.
 double getStartX()
          Get the start x coord, if any.
 double getStartY()
          Get the start y coord, if any.
 Point interpolate(double where, Point ret)
          Convenience cover of interpolateCartesian(double, Point.Cartesian) and interpolateOnSegment(double, Point.OnSegment).
 Point.Cartesian interpolateCartesian(double where)
          Convenience cover of interpolateCartesian(double, Point.Cartesian), always conses.
 Point.Cartesian interpolateCartesian(double where, Point.Cartesian ret)
          Interpolate a Cartesian point along the segment.
 Point.OnSegment interpolateOnSegment(double where)
          Convenience cover of interpolateOnSegment(double, Point.OnSegment), always conses.
 Point.OnSegment interpolateOnSegment(double where, Point.OnSegment ret)
          Interpolate an OnSegment point along the segment.
abstract  double interpolateX(double where)
          Interpolate the y coordinate along the segment.
abstract  double interpolateY(double where)
          Interpolate the x coordinate along the segment.
 boolean isValid()
          Check whether this Segment is valid.
 double project(Point point)
          Project point onto this segment.
 java.lang.String toString()
          Convenience cover of toString(DoubleFormatter), uses no formatter.
 java.lang.String toString(DoubleFormatter formatter)
          Return a human-readable string giving the start and end coords of this segment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cvsid

private static final java.lang.String cvsid

CVS id.

See Also:
Constant Field Values
Constructor Detail

AbstractSegment

public AbstractSegment()
Method Detail

isValid

public boolean isValid()

Check whether this Segment is valid.

Default imple hecks that all coords are not NaN.

Returns:
true iff this Segment is valid

getStartX

public double getStartX()

Get the start x coord, if any.

Default impl covers interpolateX(double).

Returns:
the start x coord

getStartY

public double getStartY()

Get the start y coord, if any.

Default impl covers interpolateY(double).

Returns:
the start y coord

getEndX

public double getEndX()

Get the end x coord, if any.

Default impl covers interpolateX(double).

Returns:
the end x coord

getEndY

public double getEndY()

Get the end y coord, if any.

Default impl covers interpolateY(double).

Returns:
the end y coord

interpolateX

public abstract double interpolateX(double where)

Interpolate the y coordinate along the segment.

Parameters:
where - the interpolation value (0.0->start, 1.0->end)
Returns:
the interpolated y coordinate

interpolateY

public abstract double interpolateY(double where)

Interpolate the x coordinate along the segment.

Parameters:
where - the interpolation value (0.0->start, 1.0->end)
Returns:
the interpolated x coordinate

interpolateCartesian

public Point.Cartesian interpolateCartesian(double where,
                                            Point.Cartesian ret)

Interpolate a Cartesian point along the segment.

Parameters:
where - the interpolation value (0.0->start, 1.0->end)
ret - the return point is written here, if null then a new Point.Cartesian is consed
Returns:
ret, filled in with the interpolated point

interpolateCartesian

public Point.Cartesian interpolateCartesian(double where)

Convenience cover of interpolateCartesian(double, Point.Cartesian), always conses.


interpolateOnSegment

public Point.OnSegment interpolateOnSegment(double where,
                                            Point.OnSegment ret)

Interpolate an OnSegment point along the segment.

Parameters:
where - the interpolation value (0.0->start, 1.0->end)
ret - the return point is written here, if null then a new Point.OnSegment is consed
Returns:
ret, filled in with the interpolated point

interpolateOnSegment

public Point.OnSegment interpolateOnSegment(double where)

Convenience cover of interpolateOnSegment(double, Point.OnSegment), always conses.


interpolate

public Point interpolate(double where,
                         Point ret)

Convenience cover of interpolateCartesian(double, Point.Cartesian) and interpolateOnSegment(double, Point.OnSegment).

Parameters:
where - the interpolation value (0.0->start, 1.0->end)
ret - the return point is written here, if null then a new Point.Cartesian is consed
Returns:
ret, filled in with the interpolated point

getOrientation

public double getOrientation()

Get the orientation of this Segment relative to the positive x axis, in degrees.

The segment (0, 0)->(1, 0) has orientation 0.

The segment (0, 0)->(0, 1) has orientation 90.

The segment (0, 0)->(-1, 0) has orientation 180.

The segment (0, 0)->(0, -1) has orientation -90.

Returns:
the orientation of this Segment relative to the positive x axis, in degrees, in the range (-180, 180], NaN if invalid

getLengthSq

public double getLengthSq()

Get the length squared.

Returns:
the length squared or NaN if invalid

getLength

public double getLength()

Get the length .

Returns:
the length or NaN if invalid

project

public double project(Point point)

Project point onto this segment.

Semantics same as VonaMath.project().

Parameters:
point - the point to project, not null
Returns:
the location of the projection on this segment (see VonaMath.project())

toString

public java.lang.String toString(DoubleFormatter formatter)

Return a human-readable string giving the start and end coords of this segment.

Parameters:
formatter - the formatter to use, null if none
Returns:
a human-readable string giving the start and end coords of this segment

toString

public java.lang.String toString()

Convenience cover of toString(DoubleFormatter), uses no formatter.

Overrides:
toString in class java.lang.Object