karbon

#include <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 TQDomElement &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
 

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.

Member Enumeration Documentation

◆ VCtrlPointFixing

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.

◆ VState

enum VSegment::VState

Definition at line 60 of file vsegment.h.

Constructor & Destructor Documentation

◆ VSegment() [1/2]

VSegment::VSegment ( unsigned short  deg = 3)

Definition at line 30 of file vsegment.cpp.

◆ VSegment() [2/2]

VSegment::VSegment ( const VSegment &  segment)

Definition at line 45 of file vsegment.cpp.

◆ ~VSegment()

VSegment::~VSegment ( )

Definition at line 66 of file vsegment.cpp.

Member Function Documentation

◆ boundingBox()

KoRect VSegment::boundingBox ( ) const

Calculates the bounding box.

Definition at line 724 of file vsegment.cpp.

◆ chordLength()

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.cpp.

◆ clone()

VSegment * VSegment::clone ( ) const

Returns a pointer to a copy of this segment.

Definition at line 1108 of file vsegment.cpp.

◆ degree()

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.

◆ draw()

void VSegment::draw ( VPainter *  painter) const

Definition at line 114 of file vsegment.cpp.

◆ height()

double VSegment::height ( const KoPoint &  a,
const KoPoint &  p,
const KoPoint &  b 
)
static

Calculates height of point p above line AB.

Definition at line 922 of file vsegment.cpp.

◆ intersects()

bool VSegment::intersects ( const VSegment &  segment) const

Returns true, if this segment intersects the other segment.

Definition at line 978 of file vsegment.cpp.

◆ isBegin()

bool VSegment::isBegin ( ) const
inline

Tests for the segment type ("begin", "line" or "curve").

Definition at line 91 of file vsegment.h.

◆ isCurve()

bool VSegment::isCurve ( ) const
inline

Definition at line 93 of file vsegment.h.

◆ isFlat()

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.cpp.

◆ isLine()

bool VSegment::isLine ( ) const
inline

Definition at line 92 of file vsegment.h.

◆ isSmooth() [1/2]

bool VSegment::isSmooth ( ) const
inline

Definition at line 302 of file vsegment.h.

◆ isSmooth() [2/2]

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.cpp.

◆ knot()

const KoPoint & VSegment::knot ( ) const
inline

Returns the knot.

This is a convenience function using point().

Definition at line 135 of file vsegment.h.

◆ knotIsSelected()

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.

◆ length()

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.cpp.

◆ lengthParam()

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.cpp.

◆ linesIntersect()

bool VSegment::linesIntersect ( const KoPoint &  a0,
const KoPoint &  a1,
const KoPoint &  b0,
const KoPoint &  b1 
)
static

Calculates whether lines A0A1 and B0B1 intersect.

Definition at line 949 of file vsegment.cpp.

◆ load()

void VSegment::load ( const TQDomElement &  element)

Definition at line 1064 of file vsegment.cpp.

◆ nearestPointParam()

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.cpp.

◆ next()

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.cpp.

◆ nodeNear()

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.cpp.

◆ p()

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.

◆ point()

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.

◆ pointAt()

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.cpp.

◆ pointDerivativesAt()

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.cpp.

◆ pointIsLeft()

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.

◆ pointIsSelected()

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.

◆ pointTangentNormalAt()

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.cpp.

◆ polyLength()

double VSegment::polyLength ( ) const

Calculates the length of the control polygon.

Definition at line 373 of file vsegment.cpp.

◆ prev()

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.cpp.

◆ revert()

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.cpp.

◆ selectKnot()

void VSegment::selectKnot ( bool  select = true)
inline

Selects/deselects the knot of this segment.

Definition at line 197 of file vsegment.h.

◆ selectPoint()

void VSegment::selectPoint ( int  i,
bool  select = true 
)
inline

Selects the point with index 0 <= i < degree().

Definition at line 189 of file vsegment.h.

◆ setDegree()

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.cpp.

◆ setKnot()

void VSegment::setKnot ( const KoPoint &  p)
inline

Sets the knot.

This is a convenience function.

Definition at line 164 of file vsegment.h.

◆ setP()

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.

◆ setPoint()

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.

◆ setState()

void VSegment::setState ( VState  state)
inline

Sets the segment state.

Definition at line 106 of file vsegment.h.

◆ splitAt()

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.cpp.

◆ state()

VState VSegment::state ( ) const
inline

Returns the segment state.

Definition at line 98 of file vsegment.h.

◆ tangentAt()

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.cpp.

Friends And Related Symbol Documentation

◆ VSubpath

friend class VSubpath
friend

Definition at line 44 of file vsegment.h.

◆ VSubpathIterator

friend class VSubpathIterator
friend

Definition at line 45 of file vsegment.h.


The documentation for this class was generated from the following files: