shady.common
Class Segment

java.lang.Object
  extended by shady.common.AbstractSegment
      extended by shady.common.Segment
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
MultiSegment

public class Segment
extends AbstractSegment
implements java.io.Serializable

A 2D finite closed segment with a distinguished start and end.

Target: 1.1 JRE.

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
See Also:
Serialized Form

Field Summary
private static java.lang.String cvsid
          CVS id.
 Point.Cartesian end
          The end point.
 int index
          Our index if we're in an Environment.
 Point.Cartesian start
          The start point.
 
Constructor Summary
Segment()
          Create a new unitialized segment.
Segment(double startX, double startY, double endX, double endY)
          Create a new segment.
Segment(Point start, Point end)
          Create a new segment.
 
Method Summary
 Point getEnd()
          Get the end point.
 double getEndX()
          Get the end x coord, if any.
 double getEndY()
          Get the end y coord, if any.
 Point getStart()
          Get the start point.
 double getStartX()
          Get the start x coord, if any.
 double getStartY()
          Get the start y coord, if any.
 double interpolateX(double where)
          Interpolate the y coordinate along the segment.
 double interpolateY(double where)
          Interpolate the x coordinate along the segment.
 Segment invalidate()
          Invalidate this Segment.
 boolean isValid()
          Check whether this Segment is valid.
 Segment set(double startX, double startY, double endX, double endY)
          Set the start and end of this segment.
 Segment set(Point start, Point end)
          Set the start and end of this segment.
 java.lang.String toString(DoubleFormatter formatter)
          Return a human-readable String representation of this Segment.
 
Methods inherited from class shady.common.AbstractSegment
getLength, getLengthSq, getOrientation, interpolate, interpolateCartesian, interpolateCartesian, interpolateOnSegment, interpolateOnSegment, project, toString
 
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

start

public Point.Cartesian start

The start point.


end

public Point.Cartesian end

The end point.


index

public int index

Our index if we're in an Environment.

Constructor Detail

Segment

public Segment(Point start,
               Point end)

Create a new segment.

Parameters:
start - the start Point, a copy will be made
end - the end Point, a copy will be made

Segment

public Segment(double startX,
               double startY,
               double endX,
               double endY)

Create a new segment.

Parameters:
startX - the start x coord
startY - the start y coord
endX - the end x coord
endY - the end y coord

Segment

public Segment()

Create a new unitialized segment.

Method Detail

isValid

public boolean isValid()

Check whether this Segment is valid.

Checks that start and end are non-null and valid.

Overrides:
isValid in class AbstractSegment
Returns:
true iff this Segment is valid

invalidate

public Segment invalidate()

Invalidate this Segment.

After calling this isValid() will return false.

Returns:
self ref

getStartX

public double getStartX()

Get the start x coord, if any.

Overrides:
getStartX in class AbstractSegment
Returns:
the start x coord, or Double.NaN if start is unset

getStartY

public double getStartY()

Get the start y coord, if any.

Overrides:
getStartY in class AbstractSegment
Returns:
the start y coord, or Double.NaN if start is unset

getEndX

public double getEndX()

Get the end x coord, if any.

Overrides:
getEndX in class AbstractSegment
Returns:
the end x coord, or Double.NaN if end is unset

getEndY

public double getEndY()

Get the end y coord, if any.

Overrides:
getEndY in class AbstractSegment
Returns:
the end y coord, or Double.NaN if end is unset

getStart

public Point getStart()

Get the start point.

Returns:
the start point, null if none

getEnd

public Point getEnd()

Get the end point.

Returns:
the end point, null if none

interpolateX

public double interpolateX(double where)

Interpolate the y coordinate along the segment.

Specified by:
interpolateX in class AbstractSegment
Parameters:
where - the interpolation value (0.0->start, 1.0->end)
Returns:
the interpolated y coordinate

interpolateY

public double interpolateY(double where)

Interpolate the x coordinate along the segment.

Specified by:
interpolateY in class AbstractSegment
Parameters:
where - the interpolation value (0.0->start, 1.0->end)
Returns:
the interpolated x coordinate

toString

public java.lang.String toString(DoubleFormatter formatter)

Return a human-readable String representation of this Segment.

Overrides:
toString in class AbstractSegment
Parameters:
formatter - the formatter to use, null if none
Returns:
a human-readable String representation of this Segment

set

public Segment set(Point start,
                   Point end)

Set the start and end of this segment.

Parameters:
start - the new start, null to unset, a copy is made
end - the new end, null to unset, a copy is made
Returns:
a self ref

set

public Segment set(double startX,
                   double startY,
                   double endX,
                   double endY)

Set the start and end of this segment.

Parameters:
startX - the start x coord
startY - the start y coord
endX - the end x coord
endY - the end y coord
Returns:
a self ref