net.sf.latexdraw.glib.models.impl
Class LLine

java.lang.Object
  extended by java.awt.geom.Line2D
      extended by java.awt.geom.Line2D.Double
          extended by net.sf.latexdraw.glib.models.impl.LLine
All Implemented Interfaces:
java.awt.Shape, java.io.Serializable, java.lang.Cloneable, ILine

 class LLine
extends java.awt.geom.Line2D.Double
implements ILine

Defines a model of a line. This model must be used only to define other models. It is not a shape. See the LLines class for the shape.

This file is part of LaTeXDraw.
Copyright (c) 2005-2012 Arnaud BLOUIN

LaTeXDraw 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.
LaTeXDraw is distributed 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.

02/14/2008

Since:
3.0
Version:
3.0
Author:
Arnaud BLOUIN

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.geom.Line2D
java.awt.geom.Line2D.Double, java.awt.geom.Line2D.Float
 
Field Summary
protected  double a
          The director coefficient of the line (y=ax+b).
protected  double b
          y=ax+b.
private static long serialVersionUID
           
 
Fields inherited from class java.awt.geom.Line2D.Double
x1, x2, y1, y2
 
Constructor Summary
protected LLine(double x1, double y1, double x2, double y2)
          Constructs a line from the specified coordinates.
protected LLine(double b, IPoint p1)
          Creates a line by creating a second point with:
protected LLine(IPoint p1, IPoint p2)
          Constructs a line from the specified Point2D objects.
 
Method Summary
 IPoint[] findPoints(double x, double y, double distance)
          Gets the points which are on the line and at the distance "distance" of the point "p" of the line.
 IPoint[] findPoints(IPoint p, double distance)
          Gets the points which are on the line and at the distance "distance" of the point "p" of the line.
 IPoint[] findPoints(java.awt.geom.Point2D p, double distance)
          Gets the points which are on the line and at the distance "distance" of the point "p" of the line.
 double getA()
           
 double getB()
           
 IPoint getBottomRightPoint()
           
 IPoint getIntersection(ILine l)
           
 IPoint getIntersectionSegment(ILine l)
           
 double getLineAngle()
          Computes the angle of the line.
 IPoint getMiddlePt()
           
 ILine getPerpendicularLine(IPoint pt)
          Creates the line which is perpendicular to the current line at the point pt.
 IPoint getPoint1()
           
 IPoint getPoint2()
           
 IPoint getTopLeftPoint()
           
 double getXWithEquation(double y)
          Gets the X-coordinate thanks to the equation of the line and the Y-coordinate of the point.
 double getYWithEquation(double x)
          Gets the Y-coordinate thanks to the equation of the line and the X-coordinate of the point.
 boolean isDot()
           
 boolean isHorizontalLine()
           
 boolean isVerticalLine()
           
 void setLine(double x1, double y1, double x2, double y2)
          Sets the position of the line.
 void setP1(double x, double y)
          Sets the coordinates of the first point.
 void setP1(IPoint pt)
          Sets the first point.
 void setP2(double x, double y)
          Sets the coordinates of the second point.
 void setP2(IPoint pt)
          Sets the second point.
 void setX1(double x1)
          Sets the x coordinate of the first point.
 void setX2(double x2)
          Sets the x coordinate of the second point.
 void setY1(double y1)
          Sets the y coordinate of the first point.
 void setY2(double y2)
          Sets the y coordinate of the second point.
 void updateAandB()
          Update the y-intercept b and slope a.
 
Methods inherited from class java.awt.geom.Line2D.Double
getBounds2D, getP1, getP2, getX1, getX2, getY1, getY2
 
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, toString, wait, wait, wait
 
Methods inherited from interface net.sf.latexdraw.glib.models.interfaces.ILine
getX1, getX2, getY1, getY2
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

a

protected double a
The director coefficient of the line (y=ax+b).


b

protected double b
y=ax+b.

Constructor Detail

LLine

protected LLine(double x1,
                double y1,
                double x2,
                double y2)
Constructs a line from the specified coordinates.

Parameters:
x1 - the X coordinate of the start point.
y1 - the Y coordinate of the start point.
x2 - the X coordinate of the end point.
y2 - the Y coordinate of the end point.
Throws:
java.lang.IllegalArgumentException - If one of the given coordinate is not valid.

LLine

protected LLine(double b,
                IPoint p1)
Creates a line by creating a second point with:

Parameters:
b - y = ax+ b
p1 - The first point.
Throws:
java.lang.IllegalArgumentException - If one of the given parameter is not valid.

LLine

protected LLine(IPoint p1,
                IPoint p2)
Constructs a line from the specified Point2D objects.

Parameters:
p1 - the start Point2D of this line segment.
p2 - the end Point2D of this line segment.
Throws:
java.lang.IllegalArgumentException - If one of the given points is not valid.
Method Detail

setLine

public void setLine(double x1,
                    double y1,
                    double x2,
                    double y2)
Description copied from interface: ILine
Sets the position of the line. Do nothing if one of the given parameter is not valid.

Specified by:
setLine in interface ILine
Overrides:
setLine in class java.awt.geom.Line2D.Double
Parameters:
x1 - The x coordinate of the first point.
y1 - The y coordinate of the first point.
x2 - The x coordinate of the second point.
y2 - The y coordinate of the second point.

updateAandB

public void updateAandB()
Description copied from interface: ILine
Update the y-intercept b and slope a.

Specified by:
updateAandB in interface ILine

getXWithEquation

public double getXWithEquation(double y)
Description copied from interface: ILine
Gets the X-coordinate thanks to the equation of the line and the Y-coordinate of the point. The line must not by horizontal.

Specified by:
getXWithEquation in interface ILine
Parameters:
y - The Y-coordinate of the point.
Returns:
The X-coordinate of the point or NaN if the line is horizontal or if the two points of the line are equal, or if the given y is not valid.

getYWithEquation

public double getYWithEquation(double x)
Description copied from interface: ILine
Gets the Y-coordinate thanks to the equation of the line and the X-coordinate of the point. The line must not by vertical.

Specified by:
getYWithEquation in interface ILine
Parameters:
x - The X-coordinate of the point.
Returns:
The Y-coordinate of the point or NaN if the line is vertical or if the two points of the line are equal, or if the given x is not valid.

findPoints

public IPoint[] findPoints(java.awt.geom.Point2D p,
                           double distance)
Description copied from interface: ILine
Gets the points which are on the line and at the distance "distance" of the point "p" of the line.

Specified by:
findPoints in interface ILine
Parameters:
p - The point of reference.
distance - The distance between p and the points we must find.
Returns:
The found points or null if a problem occurs.

findPoints

public IPoint[] findPoints(IPoint p,
                           double distance)
Description copied from interface: ILine
Gets the points which are on the line and at the distance "distance" of the point "p" of the line.

Specified by:
findPoints in interface ILine
Parameters:
p - The point of reference.
distance - The distance between p and the points we must find.
Returns:
The found points or null if a problem occurs.

findPoints

public IPoint[] findPoints(double x,
                           double y,
                           double distance)
Description copied from interface: ILine
Gets the points which are on the line and at the distance "distance" of the point "p" of the line.

Specified by:
findPoints in interface ILine
Parameters:
x - The x-coordinate of the point of reference.
y - The y-coordinate of the point of reference.
distance - The distance between p and the points we must find.
Returns:
The found points or null if a problem occurs.

getPerpendicularLine

public ILine getPerpendicularLine(IPoint pt)
Description copied from interface: ILine
Creates the line which is perpendicular to the current line at the point pt.

Specified by:
getPerpendicularLine in interface ILine
Parameters:
pt - The point of crossing between the two lines.
Returns:
The perpendicular line.

isVerticalLine

public boolean isVerticalLine()
Specified by:
isVerticalLine in interface ILine
Returns:
True if the line is vertical.

isHorizontalLine

public boolean isHorizontalLine()
Specified by:
isHorizontalLine in interface ILine
Returns:
True if the line is horizontal.

getIntersection

public IPoint getIntersection(ILine l)
Specified by:
getIntersection in interface ILine
Parameters:
l - The second lines
Returns:
The intersection between two lines. Null if the given is not valid or if both lines are parallels or both lines are identical.

getMiddlePt

public IPoint getMiddlePt()
Specified by:
getMiddlePt in interface ILine
Returns:
The middle point of the line.

getIntersectionSegment

public IPoint getIntersectionSegment(ILine l)
Specified by:
getIntersectionSegment in interface ILine
Parameters:
l - The second line.
Returns:
The point of the intersection between of the two segments.

getTopLeftPoint

public IPoint getTopLeftPoint()
Specified by:
getTopLeftPoint in interface ILine
Returns:
The top left point of the line (may be not a point on the line).

getBottomRightPoint

public IPoint getBottomRightPoint()
Specified by:
getBottomRightPoint in interface ILine
Returns:
The bottom right point of the line (may be not a point on the line).

getA

public double getA()
Specified by:
getA in interface ILine
Returns:
the a parameter of the line.

getB

public double getB()
Specified by:
getB in interface ILine
Returns:
the b parameter of the line.

getPoint1

public IPoint getPoint1()
Specified by:
getPoint1 in interface ILine
Returns:
The first point.

getPoint2

public IPoint getPoint2()
Specified by:
getPoint2 in interface ILine
Returns:
The second point.

setP1

public void setP1(IPoint pt)
Description copied from interface: ILine
Sets the first point.

Specified by:
setP1 in interface ILine
Parameters:
pt - The new first point.

setP1

public void setP1(double x,
                  double y)
Description copied from interface: ILine
Sets the coordinates of the first point.

Specified by:
setP1 in interface ILine
Parameters:
x - The new x coordinate of the first point.
y - The new y coordinate of the first point.

setP2

public void setP2(IPoint pt)
Description copied from interface: ILine
Sets the second point.

Specified by:
setP2 in interface ILine
Parameters:
pt - The new second point.

setP2

public void setP2(double x,
                  double y)
Description copied from interface: ILine
Sets the coordinates of the second point.

Specified by:
setP2 in interface ILine
Parameters:
x - The new x coordinate of the second point.
y - The new y coordinate of the second point.

setX1

public void setX1(double x1)
Description copied from interface: ILine
Sets the x coordinate of the first point.

Specified by:
setX1 in interface ILine
Parameters:
x1 - The new x coordinate of the first point.

setX2

public void setX2(double x2)
Description copied from interface: ILine
Sets the x coordinate of the second point.

Specified by:
setX2 in interface ILine
Parameters:
x2 - The new x coordinate of the second point.

setY1

public void setY1(double y1)
Description copied from interface: ILine
Sets the y coordinate of the first point.

Specified by:
setY1 in interface ILine
Parameters:
y1 - The new y coordinate of the first point.

setY2

public void setY2(double y2)
Description copied from interface: ILine
Sets the y coordinate of the second point.

Specified by:
setY2 in interface ILine
Parameters:
y2 - The new y coordinate of the second point.

getLineAngle

public double getLineAngle()
Description copied from interface: ILine
Computes the angle of the line.

Specified by:
getLineAngle in interface ILine
Returns:
The angle of the line.

isDot

public boolean isDot()
Specified by:
isDot in interface ILine
Returns:
True if the two points of the line are equals meaning this is not a line but a 'dot'.