karbon
VSegment Class Reference
#include <vsegment.h>
Detailed Description
A class representing lines and beziers.We waste some KoPoints, if we would use only lines, but this makes it easy to convert the segment types into each other. Make sure yourself, that you pass values to functions within proper ranges.
Definition at line 42 of file vsegment.h.
Public Types | |
enum | VCtrlPointFixing { none = 0, first = 1, second = 2 } |
enum | VState { normal, deleted } |
Public Member Functions | |
VSegment (unsigned short deg=3) | |
VSegment (const VSegment &segment) | |
unsigned short | degree () const |
void | setDegree (unsigned short deg) |
bool | isBegin () const |
bool | isLine () const |
bool | isCurve () const |
VState | state () const |
void | setState (VState state) |
const KoPoint & | point (int i) const |
const KoPoint & | p (int i) const |
const KoPoint & | knot () const |
void | setPoint (int i, const KoPoint &p) |
void | setP (int i, const KoPoint &p) |
void | setKnot (const KoPoint &p) |
bool | pointIsSelected (int i) const |
bool | knotIsSelected () const |
void | selectPoint (int i, bool select=true) |
void | selectKnot (bool select=true) |
uint | nodeNear (const KoPoint &p, double isNearRange=VGlobal::isNearRange) const |
VSegment * | prev () const |
VSegment * | next () const |
bool | isFlat (double flatness=VGlobal::flatnessTolerance) const |
KoPoint | pointAt (double t) const |
void | pointDerivativesAt (double t, KoPoint *p=0L, KoPoint *d1=0L, KoPoint *d2=0L) const |
KoPoint | tangentAt (double t) const |
void | pointTangentNormalAt (double t, KoPoint *p=0L, KoPoint *tn=0L, KoPoint *n=0L) const |
double | length (double t=1.0) const |
double | chordLength () const |
double | polyLength () const |
double | lengthParam (double len) const |
double | nearestPointParam (const KoPoint &p) const |
bool | isSmooth (const VSegment &next) const |
bool | isSmooth () const |
VSegment * | revert () const |
VSegment * | splitAt (double t) |
bool | intersects (const VSegment &segment) const |
double | pointIsLeft (const KoPoint &p) const |
KoRect | boundingBox () const |
void | draw (VPainter *painter) const |
void | load (const QDomElement &element) |
VSegment * | clone () const |
Static Public Member Functions | |
static double | height (const KoPoint &a, const KoPoint &p, const KoPoint &b) |
static bool | linesIntersect (const KoPoint &a0, const KoPoint &a1, const KoPoint &b0, const KoPoint &b1) |
Friends | |
class | VSubpath |
class | VSubpathIterator |
Member Enumeration Documentation
Tells which control point is "fixed" i.e.
located at the corresponding knot and invisible. This flag makes no sense for line segments.
Definition at line 53 of file vsegment.h.
Member Function Documentation
unsigned short VSegment::degree | ( | ) | const [inline] |
Returns the segment's degree, which is identical to the number of nodes.
For cubic beziers it is "three" and "one" for lines.
Definition at line 77 of file vsegment.h.
void VSegment::setDegree | ( | unsigned short | deg | ) |
Sets the segment's degree and thus resizes the array of node data.
The node data is copied from the old knot "backwards".
Definition at line 72 of file vsegment.cc.
bool VSegment::isBegin | ( | ) | const [inline] |
VState VSegment::state | ( | ) | const [inline] |
void VSegment::setState | ( | VState | state | ) | [inline] |
const KoPoint& VSegment::point | ( | int | i | ) | const [inline] |
Returns the segment's point with index 0 <= i < degree().
Definition at line 115 of file vsegment.h.
const KoPoint& VSegment::p | ( | int | i | ) | const [inline] |
This is a convenience function.
It returns the point with index 0 <= i <= degree() while p( 0 ) is the knot of the previous segment.
Definition at line 125 of file vsegment.h.
const KoPoint& VSegment::knot | ( | ) | const [inline] |
Returns the knot.
This is a convenience function using point().
Definition at line 135 of file vsegment.h.
void VSegment::setPoint | ( | int | i, | |
const KoPoint & | p | |||
) | [inline] |
Sets the segment's point with index 0 <= i < degree() to "p".
Definition at line 143 of file vsegment.h.
void VSegment::setP | ( | int | i, | |
const KoPoint & | p | |||
) | [inline] |
This is a convenience function.
It sets the point with index 0 <= i <= degree() to "p" while setP( 0 ) sets the knot of the previous segment.
Definition at line 153 of file vsegment.h.
void VSegment::setKnot | ( | const KoPoint & | p | ) | [inline] |
bool VSegment::pointIsSelected | ( | int | i | ) | const [inline] |
Returns true if the point with index 0 <= i < degree() is selected.
Definition at line 173 of file vsegment.h.
bool VSegment::knotIsSelected | ( | ) | const [inline] |
Returns true if the knot is selected.
This is a convenience function.
Definition at line 181 of file vsegment.h.
void VSegment::selectPoint | ( | int | i, | |
bool | select = true | |||
) | [inline] |
void VSegment::selectKnot | ( | bool | select = true |
) | [inline] |
uint VSegment::nodeNear | ( | const KoPoint & | p, | |
double | isNearRange = VGlobal::isNearRange | |||
) | const |
Returns index of the node at point p.
Returns 0 if no segment point matches point p.
Definition at line 994 of file vsegment.cc.
VSegment * VSegment::prev | ( | ) | const |
Returns a pointer to the previous not deleted segment, if stored in a VSubpath.
Definition at line 1037 of file vsegment.cc.
VSegment * VSegment::next | ( | ) | const |
Returns a pointer to the next not deleted segment, if stored in a VSubpath.
Definition at line 1050 of file vsegment.cc.
bool VSegment::isFlat | ( | double | flatness = VGlobal::flatnessTolerance |
) | const |
Returns true if the segment is flat.
That means it's height is smaller than flatness.
Definition at line 139 of file vsegment.cc.
KoPoint VSegment::pointAt | ( | double | t | ) | const |
Calculates the point on this segment at parameter 0 <= t <= 1.
This is a convenience wrapper for pointDerivativesAt().
Definition at line 165 of file vsegment.cc.
void VSegment::pointDerivativesAt | ( | double | t, | |
KoPoint * | p = 0L , |
|||
KoPoint * | d1 = 0L , |
|||
KoPoint * | d2 = 0L | |||
) | const |
Calculates the point and the derivatives of first and second order for 0 <= t <= 1.
Definition at line 175 of file vsegment.cc.
KoPoint VSegment::tangentAt | ( | double | t | ) | const |
Calculates the normalized tangent vector (length=1) at the point parameterized by 0 <= t <= 1.
This is a convenience wrapper for pointTangentNormalAt(). Use the latter function directly if you need to calculate the point and normal vector or tangent vector at once.
Definition at line 248 of file vsegment.cc.
void VSegment::pointTangentNormalAt | ( | double | t, | |
KoPoint * | p = 0L , |
|||
KoPoint * | tn = 0L , |
|||
KoPoint * | n = 0L | |||
) | const |
Calculates the point, the tangent vector and the normal vector for 0 <= t <= 1.
The tangent vector and the normal vector are normalized (length=1).
Definition at line 258 of file vsegment.cc.
double VSegment::length | ( | double | t = 1.0 |
) | const |
Calculates the arclength from p0 to the point parametrized by 0 <= t <= 1.
For beziers this function is a bit expensive.
Definition at line 291 of file vsegment.cc.
double VSegment::chordLength | ( | ) | const |
Calculates the chord length (the distance from the previous knot to the current knot).
Definition at line 361 of file vsegment.cc.
double VSegment::polyLength | ( | ) | const |
double VSegment::lengthParam | ( | double | len | ) | const |
Calculates the parameter of a point located at arclength len.
This is the exact inverse operation of length( t ).
Definition at line 396 of file vsegment.cc.
double VSegment::nearestPointParam | ( | const KoPoint & | p | ) | const |
Calculates the parameter of the nearest point on this segment to the point p.
This function is pretty expensive.
Definition at line 437 of file vsegment.cc.
bool VSegment::isSmooth | ( | const VSegment & | next | ) | const |
Calculates wether the tangent at the knot is exactly parallel to the tangent at p0 of the next segment.
Returns false if the current segment is a "begin".
Definition at line 700 of file vsegment.cc.
VSegment * VSegment::revert | ( | ) | const |
Creates a reverted version of this segment.
For example: if this segment is a line from A to B, the result is a line from B to A.
Definition at line 1011 of file vsegment.cc.
VSegment * VSegment::splitAt | ( | double | t | ) |
Splits the segment at parameter 0 <= t <= 1.
Returns a pointer to the first segment and modifies the current one to be the second segment.
Definition at line 857 of file vsegment.cc.
double VSegment::height | ( | const KoPoint & | a, | |
const KoPoint & | p, | |||
const KoPoint & | b | |||
) | [static] |
bool VSegment::linesIntersect | ( | const KoPoint & | a0, | |
const KoPoint & | a1, | |||
const KoPoint & | b0, | |||
const KoPoint & | b1 | |||
) | [static] |
bool VSegment::intersects | ( | const VSegment & | segment | ) | const |
Returns true, if this segment intersects the other segment.
Definition at line 978 of file vsegment.cc.
double VSegment::pointIsLeft | ( | const KoPoint & | p | ) | const [inline] |
Returns a number > 0 if the point p is left, 0 if it's on and a number < 0 if it's right of the infinite line through the previous segment's knot and the current knot.
Definition at line 355 of file vsegment.h.
KoRect VSegment::boundingBox | ( | ) | const |
VSegment * VSegment::clone | ( | ) | const |
The documentation for this class was generated from the following files: