edu.mit.sketch.geom
Class Line

java.lang.Object
  |
  +--java.awt.geom.Line2D
        |
        +--java.awt.geom.Line2D.Double
              |
              +--edu.mit.sketch.geom.Line
All Implemented Interfaces:
Cloneable, GeometricObject, Paintable, Rotatable, Serializable, Shape, Terminal, Translatable

public class Line
extends Line2D.Double
implements GeometricObject, Rotatable, Serializable

This class represents a line described by its end-points p, q.

See Also:
Serialized Form

Inner classes inherited from class java.awt.geom.Line2D
Line2D.Double, Line2D.Float
 
Field Summary
 Graphics graphics
          Graphics context for this Geometric object.
 long time_stamp
          Time stamp of this object.
 
Fields inherited from class java.awt.geom.Line2D.Double
x1, x2, y1, y2
 
Fields inherited from interface edu.mit.sketch.geom.GeometricObject
CIRCLE, ELLIPSE, LINE, POINT, POLYGON, RECTANGLE, SQUARE
 
Constructor Summary
Line()
          The constructor.
Line(double x1, double y1, double x2, double y2)
          The constructor.
Line(Line line)
          The constructor.
Line(Point p, Point q)
          The constructor.
 
Method Summary
 double chooseApproximateAngle(double[] angle_set)
          Returns the angle that is closest to the angle that this line makes with the x axis from the input argument.
 boolean containsGeometricObject(GeometricObject object)
          Returns false if the argument is not completely inside this object.
 boolean containsGeometricObjects(GeometricObject[] objects)
          Returns false if the objects in the input array are completely inside this object.
 double getAngle()
          Returns the angle of the object WRT the x axis in radians.
 double getCartesianAngle()
          Returns the angle of the object WRT the x axis in radians.
 Polygon getDataPoints()
          This method is used to get the original data points that forms this GeometricObject
 Point getIntersection(Line line)
          Returns the intersection of the two infinite length lines described by this line and the argument.
 double getLSQError(Point[] points, Range range)
          Returns the lsq error.
 double getLSQError(StrokeData data, Range range)
          Returns the lsq error.
 Polygon getPolygonalBounds()
          This method should return a polygon that fully contains the current object.
 Rectangle getRectangularBounds()
          Supplied for completeness.
 long getTimeStamp()
          Returns the time stamp of the current Terminal
 String getType()
          Implement GeometricObject
static boolean isLine(Polygon p)
          Returns true if the input Polygon is a line.
 boolean isParallel(Line line)
          Returns true if the lines are parallel must be replaced
 double length()
          Returns the length of this line.
 void paint()
          Draw the object
 void paint(Graphics g)
          Draw the object
 void paintOriginal(Graphics g)
          This method is used to paint the original data points that forms this GeometricObject
 void pointDown()
          Swaps the first and the second points if needed so that the second point is below the first one.
 boolean pointIsOn(Point point, int radius)
          Returns true if the point is within +-radius distance from the curve defining the object.
 boolean pointIsOnOriginal(Point p, int radius)
          Returns true if the point is within +-radius distance from the original curve defining the object.
 void pointLeft()
          Swaps the first and the second points if needed so that the second point is to the left of the first one.
 void pointRight()
          Swaps the first and the second points if needed so that the second point is to the right of the first one.
 void pointUp()
          Swaps the first and the second points if needed so that the second point is above the first one.
 void setDataPoints(Polygon points)
          This method is used to set the original data points that forms this GeometricObject
 void setGraphicsContext(Graphics g)
          Set graphics context for this Geometric object.
 void setTimeStamp(long time_stamp)
          Sets the time stamp of the current Terminal
 int spatialRelation(GeometricObject object)
          This method should return the spatial relation of the input parameter with respect to this object.
 void swapPoints()
          Swaps the first and the secons points.
 Polygon toPolygon()
          This method is used to get the original data points that forms this GeometricObject
 String toString()
          Override toString
 boolean touches(GeometricObject object)
          This method should return true if the input objects touch.
 void translate(double x, double y)
          Add the arguments to the position of the object.
 
Methods inherited from class java.awt.geom.Line2D.Double
getBounds2D, getP1, getP2, getX1, getX2, getY1, getY2, setLine
 
Methods inherited from class java.awt.geom.Line2D
clone, contains, contains, contains, contains, getBounds, getPathIterator, getPathIterator, intersects, intersects, intersectsLine, intersectsLine, linesIntersect, ptLineDist, ptLineDist, ptLineDist, ptLineDistSq, ptLineDistSq, ptLineDistSq, ptSegDist, ptSegDist, ptSegDist, ptSegDistSq, ptSegDistSq, ptSegDistSq, relativeCCW, relativeCCW, relativeCCW, setLine, setLine
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

time_stamp

public long time_stamp
Time stamp of this object.

graphics

public transient Graphics graphics
Graphics context for this Geometric object.
Constructor Detail

Line

public Line(Line line)
The constructor.

Line

public Line()
The constructor.

Line

public Line(double x1,
            double y1,
            double x2,
            double y2)
The constructor.

Line

public Line(Point p,
            Point q)
The constructor.
Method Detail

getType

public String getType()
Implement GeometricObject
Specified by:
getType in interface Paintable

toString

public String toString()
Override toString
Overrides:
toString in class Object

paint

public void paint()
Draw the object
Specified by:
paint in interface Paintable

paint

public void paint(Graphics g)
Draw the object
Specified by:
paint in interface Paintable

paintOriginal

public void paintOriginal(Graphics g)
This method is used to paint the original data points that forms this GeometricObject
Specified by:
paintOriginal in interface Paintable

pointIsOn

public boolean pointIsOn(Point point,
                         int radius)
Returns true if the point is within +-radius distance from the curve defining the object. Returns false o/w.
Specified by:
pointIsOn in interface Translatable

pointIsOnOriginal

public boolean pointIsOnOriginal(Point p,
                                 int radius)
Returns true if the point is within +-radius distance from the original curve defining the object. Returns false o/w.
Specified by:
pointIsOnOriginal in interface Translatable

setGraphicsContext

public void setGraphicsContext(Graphics g)
Set graphics context for this Geometric object. Must be set at least once before doing any drawing.
Specified by:
setGraphicsContext in interface Paintable

touches

public boolean touches(GeometricObject object)
This method should return true if the input objects touch. It should be optimized making use of the object type information.
Specified by:
touches in interface GeometricObject

getRectangularBounds

public Rectangle getRectangularBounds()
Supplied for completeness.
Specified by:
getRectangularBounds in interface GeometricObject

containsGeometricObject

public boolean containsGeometricObject(GeometricObject object)
Returns false if the argument is not completely inside this object. Return true O/W.
Specified by:
containsGeometricObject in interface GeometricObject

getPolygonalBounds

public Polygon getPolygonalBounds()
This method should return a polygon that fully contains the current object. The polygon is implicity closed and the last point doesn't necessarily have to be the same as the first (zeroth) point.
Specified by:
getPolygonalBounds in interface GeometricObject

spatialRelation

public int spatialRelation(GeometricObject object)
This method should return the spatial relation of the input parameter with respect to this object. see the SpatialRelation class for a detailed list of possible spatial relations. Another version of this method should be implemented for handling spatial relations where a rotated coordinate system is to be used.
Specified by:
spatialRelation in interface GeometricObject

getCartesianAngle

public double getCartesianAngle()
Returns the angle of the object WRT the x axis in radians. Known eksik: Probably confused between this and getAngle()

getAngle

public double getAngle()
Returns the angle of the object WRT the x axis in radians. Known eksik: Probably confused between this and getCartesianAngl()
Specified by:
getAngle in interface Rotatable

isLine

public static boolean isLine(Polygon p)
Returns true if the input Polygon is a line.

setTimeStamp

public void setTimeStamp(long time_stamp)
Sets the time stamp of the current Terminal
Specified by:
setTimeStamp in interface Terminal

getTimeStamp

public long getTimeStamp()
Returns the time stamp of the current Terminal
Specified by:
getTimeStamp in interface Terminal

swapPoints

public void swapPoints()
Swaps the first and the secons points.

pointRight

public void pointRight()
Swaps the first and the second points if needed so that the second point is to the right of the first one. The overall line structure is preserved.

pointLeft

public void pointLeft()
Swaps the first and the second points if needed so that the second point is to the left of the first one. The overall line structure is preserved.

pointUp

public void pointUp()
Swaps the first and the second points if needed so that the second point is above the first one. The overall line structure is preserved.

pointDown

public void pointDown()
Swaps the first and the second points if needed so that the second point is below the first one. The overall line structure is preserved.

setDataPoints

public void setDataPoints(Polygon points)
This method is used to set the original data points that forms this GeometricObject
Specified by:
setDataPoints in interface GeometricObject

getDataPoints

public Polygon getDataPoints()
This method is used to get the original data points that forms this GeometricObject
Specified by:
getDataPoints in interface GeometricObject

toPolygon

public Polygon toPolygon()
This method is used to get the original data points that forms this GeometricObject

chooseApproximateAngle

public double chooseApproximateAngle(double[] angle_set)
Returns the angle that is closest to the angle that this line makes with the x axis from the input argument. In this context, Math.PI is not the same as 0. The method uses the absolute value of difference as the metric for distance.

containsGeometricObjects

public boolean containsGeometricObjects(GeometricObject[] objects)
Returns false if the objects in the input array are completely inside this object. Return true O/W.
Specified by:
containsGeometricObjects in interface GeometricObject

translate

public void translate(double x,
                      double y)
Add the arguments to the position of the object.
Specified by:
translate in interface Translatable

length

public double length()
Returns the length of this line.

getLSQError

public double getLSQError(Point[] points,
                          Range range)
Returns the lsq error.

getLSQError

public double getLSQError(StrokeData data,
                          Range range)
Returns the lsq error.

isParallel

public boolean isParallel(Line line)
Returns true if the lines are parallel must be replaced

getIntersection

public Point getIntersection(Line line)
                      throws GeometricComputationException
Returns the intersection of the two infinite length lines described by this line and the argument. This method converts the end-points of the lines to ints rather than working with doubles. This is reasonably good approximation. After all even if we use doubles, we won't get a "perfect" intersection point and the simplification makes handling of special cases easier. Return null if the lines are parallel (even if they are the same).