gishur.x2.core
Class XQuadCurve

java.lang.Object
  |
  +--gishur.x2.core.XObject
        |
        +--gishur.x2.core.XIntersectableObject
              |
              +--gishur.x2.core.XParametricCurve
                    |
                    +--gishur.x2.core.XQuadCurve
All Implemented Interfaces:
java.lang.Cloneable, Cloneable, Intersectable, Intersectable, java.io.Serializable

public class XQuadCurve
extends XParametricCurve

A quadratic curve segment.

Version:
1.0
Author:
Thomas Wolf
See Also:
Serialized Form

Fields inherited from class gishur.x2.core.XParametricCurve
DIRECTION_DOWN, DIRECTION_LEFT, DIRECTION_RIGHT, DIRECTION_UP, STATE_BOTH_END, STATE_SOURCE_END, STATE_TARGET_END
 
Fields inherited from class gishur.x2.core.XObject
RESERVED_STATE_MAX_MASK, STATE_DIRTY, STATE_LOCKED, STATE_MUTABLE
 
Fields inherited from interface gishur.x2.core.Intersectable
FACES, POINT_INSIDE, POINT_ON_BORDER, POINT_OUTSIDE, POINTS, POINTS_CURVES
 
Fields inherited from interface gishur.core.geom.Intersectable
DEFAULT
 
Constructor Summary
XQuadCurve(double x1, double y1, double x2, double y2, double x3, double y3)
          Creates a parabola segment defined by the control points (x1,y1), (x2,y2) and (x3,y3).
XQuadCurve(double x1, double y1, double x2, double y2, double x3, double y3, boolean se, boolean te)
          Creates a parabola segment defined by the control points (x1,y1), (x2,y2) and (x3,y3).
XQuadCurve(XPoint control0, XPoint control1, XPoint control2)
          Creates a parabola segment defined by the control points control0, control1 and control2 and the state state.
XQuadCurve(XPoint control0, XPoint control1, XPoint control2, boolean se, boolean te)
          Creates a parabola segment defined by the control points control0, control1 and control2 and the state state.
 
Method Summary
 java.lang.Object clone()
          Creates a new object of the same class as this object.
 XPoint control0()
          Return the first control point of the parabola.
 XPoint control1()
          Return the second control point of the parabola.
 XPoint control2()
          Return the third control point of the parabola.
static XQuadCurve createBisector(XPoint p, XSegment l)
           
 boolean equals(java.lang.Object o)
          Determines whether two objects (this and o) are equal.
 boolean equals(XQuadCurve q)
          Determines whether two parabolas are equal.
 XQuadCurve flip()
          Flips source and target control points.
 java.lang.Object getOldXObject()
          Returns corresponding old gishur.x-object.
protected  XObject[] getXObjectMembers()
          This method should return all XObject members that contain geometric information.
 XPoint[] intersectHorizontal(double y)
          Calculates the intersection points between this curve and the horizontal line with y-coordinate y.
 java.lang.Object intersection(int mode, java.lang.Object o)
          Calculates the intersection between this object and the given object o.
 XPoint[] intersectVertical(double x)
          Calculates the intersection points between this curve and the vertical line with x-coordinate x.
 int locate(XPoint p)
          Locates the specified point.
 void makeImmutable()
          Makes this object immutable.
 void makeMutable()
          Makes this object mutable.
 double param(XPoint p)
          Calculates the parameter for the curve of a given point.
 XPoint point(double t)
          Calculates a point on the curve with parameter t.
 void setControl0(XPoint control0)
          Sets the first control point to control0 (if not null).
 void setControl1(XPoint control1)
          Sets the second control point to control1 (if not null).
 void setControl2(XPoint control2)
          Sets the third control point to control2 (if not null).
 void setSource(double t)
          Sets the source control point to the curve point with parameter t.
 void setSource(XPoint source)
          Sets the source point to source.
 void setTarget(double t)
          Sets the target control point to the curve point with parameter t.
 void setTarget(XPoint target)
          Sets the target point to target.
 XPoint source()
          Return the source point of the parabola segment.
 boolean supportIntersection(int mode, java.lang.Object o)
          Returns true, if this class (or object) provides intersection with the given object o.
 XPoint target()
          Return the target point of the parabola segment.
 java.lang.String toString()
          Returns a string representation of the parabola.
 XObject transform(double m00, double m01, double m02, double m10, double m11, double m12)
          Transforms this XObject by the given affine transformation matrix.
 XPoint vector(double t, int dir, boolean normalize)
          Returns a (normalized) vector in the specified direction relative to this curve at a point on the curve with parameter t.
 
Methods inherited from class gishur.x2.core.XParametricCurve
checkParam, finite, hasNoEnd, inverseDirection, liesInterior, majorEndPoint, minorEndPoint, normal, normal, setSourceEnd, setTargetEnd, sourceEnd, tangent, tangent, targetEnd
 
Methods inherited from class gishur.x2.core.XIntersectableObject
contains, contains, liesOn
 
Methods inherited from class gishur.x2.core.XObject
checkState, checkStateCleared, clearDirty, clearState, copy, dirty, getMutable, inverseTransform, lock, locked, modify, mutable, restoreMutability, rotate, scale, setState, state, state, toString_complete, toString_state, transform, translate, translate, unlock
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XQuadCurve

public XQuadCurve(double x1,
                  double y1,
                  double x2,
                  double y2,
                  double x3,
                  double y3,
                  boolean se,
                  boolean te)
Creates a parabola segment defined by the control points (x1,y1), (x2,y2) and (x3,y3). The values of se and te define, if the curve ends at the source point (se==true) or/and at the target point (te==true).
Parameters:
x1,y1 - first control point
x2,y2 - second control point
x3,y3 - third control point
se - curve ends at source point
te - curve ends at target point

XQuadCurve

public XQuadCurve(XPoint control0,
                  XPoint control1,
                  XPoint control2,
                  boolean se,
                  boolean te)
Creates a parabola segment defined by the control points control0, control1 and control2 and the state state. The values of se and te define, if the curve ends at the source point (se==true) or/and at the target point (te==true).
Parameters:
control0 - first control point
control1 - second control point
control2 - third control point
se - curve ends at source point
te - curve ends at target point

XQuadCurve

public XQuadCurve(XPoint control0,
                  XPoint control1,
                  XPoint control2)
Creates a parabola segment defined by the control points control0, control1 and control2 and the state state.
Parameters:
control0 - first control point
control1 - second control point
control2 - third control point

XQuadCurve

public XQuadCurve(double x1,
                  double y1,
                  double x2,
                  double y2,
                  double x3,
                  double y3)
Creates a parabola segment defined by the control points (x1,y1), (x2,y2) and (x3,y3).
Parameters:
x1,y1 - first control point
x2,y2 - second control point
x3,y3 - third control point
Method Detail

createBisector

public static final XQuadCurve createBisector(XPoint p,
                                              XSegment l)

toString

public java.lang.String toString()
Returns a string representation of the parabola. Open endpoints are marked with "<<" respectively ">>".
Overrides:
toString in class XObject
Returns:
a string representation of the object.

clone

public java.lang.Object clone()
Creates a new object of the same class as this object.
Overrides:
clone in class XObject
Returns:
a clone of this instance.
Throws:
OutOfMemoryError - if there is not enough memory.
See Also:
Cloneable

equals

public boolean equals(XQuadCurve q)
Determines whether two parabolas are equal.
Parameters:
q - parabola to compare with this.
Returns:
True, if the two parabolas are equal.

equals

public boolean equals(java.lang.Object o)
Determines whether two objects (this and o) are equal.
Overrides:
equals in class java.lang.Object
Parameters:
o - Object to compare with.
Returns:
True, if the two objects are equal.

makeMutable

public void makeMutable()
Makes this object mutable. This means this Object can modify its coordinates (and some other geometric information). This must be assured by every subclass of XObject itself - but propagation to all XObject members contained by this class (returned by getXObjectMembers()) is assured by this method.
Overrides:
makeMutable in class XObject

makeImmutable

public void makeImmutable()
Makes this object immutable. This means this Object cannot modify its coordinates (and some other geometric information). This must be assured by every subclass of XObject itself - but propagation to all XObject members contained by this class (returned by getXObjectMembers()) is assured by this method.
Overrides:
makeImmutable in class XObject

getXObjectMembers

protected XObject[] getXObjectMembers()
This method should return all XObject members that contain geometric information. The result will be used by makeMutable(), makeImmutable(), XObject.clearDirty(), XObject.lock() and XObject.unlock(). To make this work there must not occur circular dependencies.
Overrides:
getXObjectMembers in class XObject
Returns:
Array with all XObject members (or null if none).

source

public XPoint source()
Return the source point of the parabola segment.
Overrides:
source in class XParametricCurve
Returns:
Source point of the parabola segment or control0() if the parabola is unbounded on the source side.

target

public XPoint target()
Return the target point of the parabola segment.
Overrides:
target in class XParametricCurve
Returns:
Target point of the parabola segment or control2() if the parabola is unbounded on the target side.

control0

public XPoint control0()
Return the first control point of the parabola.
Returns:
First control point.

control1

public XPoint control1()
Return the second control point of the parabola.
Returns:
Second control point.

control2

public XPoint control2()
Return the third control point of the parabola.
Returns:
Third control point.

point

public XPoint point(double t)
Calculates a point on the curve with parameter t. If the curve is XParametricCurve.finite(), then holds 0≤t≤1.
Overrides:
point in class XParametricCurve
Parameters:
t - parameter
Point - on the curve with parameter t or null if the parameter is not valid.

param

public double param(XPoint p)
Calculates the parameter for the curve of a given point. The point must lie on the curve or an GeomException will be thrown.
Overrides:
param in class XParametricCurve
Parameters:
p - point
Returns:
Parameter of p.
Throws:
GeomException - if p does not lie on the curve

vector

public XPoint vector(double t,
                     int dir,
                     boolean normalize)
Returns a (normalized) vector in the specified direction relative to this curve at a point on the curve with parameter t. The value of dir specifies if the vector should point tangential along the curve (XParametricCurve.DIRECTION_UP), point tangential in the opposite direction (XParametricCurve.DIRECTION_DOWN), point normal to the curve to the right (XParametricCurve.DIRECTION_RIGHT) or point normal to the curve to the left (XParametricCurve.DIRECTION_LEFT).
Overrides:
vector in class XParametricCurve
Parameters:
t - parameter of the curve point where to calculate the vector
dir - direction constant
normalize - true, if result vector should be normalized
Returns:
Vector tangential or normal to the curve at the specified point.
Throws:
GeomException - if dir has an illegal value

flip

public XQuadCurve flip()
Flips source and target control points.
Returns:
Flipped parabola

setSource

public void setSource(double t)
Sets the source control point to the curve point with parameter t. Setting the source point has no effect on the parabola itself (but on the second control point), it moves only the segment borders. The object must be mutable.
Parameters:
t - parameter for new source control point
Throws:
GeomException - if object is immutable

setTarget

public void setTarget(double t)
Sets the target control point to the curve point with parameter t. Setting the target point has no effect on the parabola itself (but on the second control point), it moves only the segment borders. The object must be mutable.
Parameters:
t - parameter for new target control point
Throws:
GeomException - if object is immutable

setSource

public void setSource(XPoint source)
Sets the source point to source. source must lie on the curve or must be null. Setting the source point has no effect on the parabola itself, it moves only the segment borders. The value null removes the bound on the source side. (if not null). The object must be mutable.
Overrides:
setSource in class XParametricCurve
Parameters:
source - new source point
Throws:
GeomException - if object is immutable

setTarget

public void setTarget(XPoint target)
Sets the target point to target. target must lie on the curve or must be null. Setting the target point has no effect on the parabola itself, it moves only the segment borders. The value null removes the bound on the target side. (if not null). The object must be mutable.
Overrides:
setTarget in class XParametricCurve
Parameters:
target - new target point
Throws:
GeomException - if object is immutable

setControl0

public void setControl0(XPoint control0)
Sets the first control point to control0 (if not null). The object must be mutable.
Parameters:
control0 - first control point
Throws:
GeomException - if object is immutable

setControl1

public void setControl1(XPoint control1)
Sets the second control point to control1 (if not null). The object must be mutable.
Parameters:
control1 - second control point
Throws:
GeomException - if object is immutable

setControl2

public void setControl2(XPoint control2)
Sets the third control point to control2 (if not null). The object must be mutable.
Parameters:
control2 - third point
Throws:
GeomException - if object is immutable

transform

public XObject transform(double m00,
                         double m01,
                         double m02,
                         double m10,
                         double m11,
                         double m12)
Transforms this XObject by the given affine transformation matrix.
Overrides:
transform in class XObject
Parameters:
m00,m01,m02 - first row of the transformation matrix
m10,m11,m12 - second row of the transformation matrix
Returns:
transformed XObject (this, only if it is mutable, otherwise a new XObject represeting the transformed object)

supportIntersection

public boolean supportIntersection(int mode,
                                   java.lang.Object o)
Returns true, if this class (or object) provides intersection with the given object o. It should only return true, if this class provides an intersection metod itself. The XQuadCurve class can handle intersections with objects of type XPoint, XSegment and XQuadCurve with intersection modes Intersectable.DEFAULT, Intersectable.POINTS and Intersectable.POINTS_CURVES.
Parameters:
mode - intersection mode
o - object for intersection
Returns:
true, if intersection is supported

intersection

public java.lang.Object intersection(int mode,
                                     java.lang.Object o)
Calculates the intersection between this object and the given object o. This method should not be called directly, rather construct an Intersection object (it will call this method). The returned Object is either a single intersection object or an array or a list (based upon BasicList) of intersection objects.

This method does not verify, if the intersection with o can be calculated (use supportIntersection(int, java.lang.Object) instead), but throws an IntersectionException, if an error occures. This means, it may be that supportIntersection(int, java.lang.Object) returns true and this method does not throw an exception and returns with a (propably wrong) result.

The resulted objects are always newly created and do not point to existing objects.

Parameters:
mode - intersection mode
o - object for intersection
Returns:
intersection object(s)
Throws:
IntersectionException - if an error occured

locate

public int locate(XPoint p)
Locates the specified point. The result is a point location constant (one of {Intersectable.POINT_INSIDE,Intersectable.POINT_OUTSIDE, Intersectable.POINT_ON_BORDER}). Because this class represents line objects, Intersectable.POINT_INSIDE cannot occur as return value.
Parameters:
p - point to locate
Returns:
location constant
Throws:
GeomException - p is null

intersectVertical

public XPoint[] intersectVertical(double x)
Calculates the intersection points between this curve and the vertical line with x-coordinate x.
Parameters:
x - x-coordinate of the vertical line
Returns:
Array with all intersection points (length 0 if no intersections).

intersectHorizontal

public XPoint[] intersectHorizontal(double y)
Calculates the intersection points between this curve and the horizontal line with y-coordinate y.
Parameters:
y - y-coordinate of the horizontal line
Returns:
Array with all intersection points (length 0 if no intersections).

getOldXObject

public java.lang.Object getOldXObject()
Returns corresponding old gishur.x-object.
Overrides:
getOldXObject in class XObject
Returns:
Corresponding old gishur.x-object.