Package com.dkt.graphics.elements
Class GLine
java.lang.Object
com.dkt.graphics.elements.GraphicE
com.dkt.graphics.elements.GLine
- All Implemented Interfaces:
Cloneable
This class represents a line segment
- Author:
- Federico Vera <[email protected]>
-
Field Summary
-
Constructor Summary
ConstructorDescriptionGLine
(int x, int y, double length, double angle) Constructs a new line based on its start point, length and angleGLine
(int x1, int y1, int x2, int y2) Constructs a new line segment based on the end pointsCopy constructorConstructs a new line segment based on the end points -
Method Summary
Modifier and TypeMethodDescriptionclone()
boolean
contains
(int x, int y) Tells if a point is contained in this line segmentboolean
Tells if a point is contained in this line segmentvoid
draw
(Graphics2D g) Draws the component on the given graphicsboolean
double
Retrieves the argument of the line segment (in degrees)Retrieves a copy of the end point of this line segmentRetrieves the middle point of the lineRetrieves an orthogonal line that segment contains (0, 0) as it's start pointgetOrthogal
(int x, int y) Retrieves an orthogonal line segment that contains (x, y) as it's start pointgetParallel
(int x, int y) Retrieves an parallel line segment that contains (x, y) as it's start pointdouble
Retrieves the argument of the line segment (in radians)Retrieves a copy of the start point of this line segmentint
hashCode()
double
modulus()
Retrieves the length of the line segmentvoid
traslate
(int x, int y) Traslates this element on X and Y
-
Constructor Details
-
GLine
Copy constructor- Parameters:
e
-GLine
to copy- Throws:
IllegalArgumentException
- ife
isnull
-
GLine
Constructs a new line segment based on the end points- Parameters:
p1
- start pointp2
- end point- Throws:
IllegalArgumentException
-
GLine
public GLine(int x1, int y1, int x2, int y2) Constructs a new line segment based on the end points- Parameters:
x1
- x coordinate of the start pointy1
- y coordinate of the start pointx2
- x coordinate of the end pointy2
- y coordinate of the end point
-
GLine
public GLine(int x, int y, double length, double angle) Constructs a new line based on its start point, length and angle- Parameters:
x
- x coordinate of the start pointy
- y coordinate of the start pointlength
- length of the vectorangle
- angle (in degrees) of the line segment
-
-
Method Details
-
getMiddlePoint
Retrieves the middle point of the line- Returns:
- middle point
-
getOrthogal
Retrieves an orthogonal line that segment contains (0, 0) as it's start point- Returns:
- Orthogonal
GLine
-
getOrthogal
Retrieves an orthogonal line segment that contains (x, y) as it's start point- Parameters:
x
- x coordinate of the start pointy
- y coordinate of the start point- Returns:
- Orthogonal
GLine
-
getParallel
Retrieves an parallel line segment that contains (x, y) as it's start point- Parameters:
x
- x coordinate of the start pointy
- y coordinate of the start point- Returns:
- Orthogonal
GLine
-
getStartPoint
Retrieves a copy of the start point of this line segment- Returns:
- start
GPoint
of the line segment
-
getEndPoint
Retrieves a copy of the end point of this line segment- Returns:
- end
GPoint
of the line segment
-
getRadArgument
public double getRadArgument()Retrieves the argument of the line segment (in radians)- Returns:
- angle in radians
-
getArgument
public double getArgument()Retrieves the argument of the line segment (in degrees)- Returns:
- angle in degrees
-
modulus
public double modulus()Retrieves the length of the line segment- Returns:
- length
-
contains
Tells if a point is contained in this line segment- Parameters:
p
- point to check- Returns:
true
if the point is contained in the segment andfalse
otherwise- Throws:
IllegalArgumentException
- ifp
isnull
-
contains
public boolean contains(int x, int y) Tells if a point is contained in this line segment- Parameters:
x
- the X coordinate of the pointy
- the Y coordinate of the point- Returns:
true
if the point is contained in the segment andfalse
otherwise
-
draw
Description copied from class:GraphicE
Draws the component on the given graphics -
traslate
public void traslate(int x, int y) Description copied from class:GraphicE
Traslates this element on X and Y -
clone
-
hashCode
public int hashCode() -
equals
-