Ipelib: ipe::CurveSegment Class Reference

Ipelib

Public Types | Public Member Functions | Friends | List of all members
ipe::CurveSegment Class Reference
Ipe Geometry

`#include <ipeshape.h>`

## Public Types
enum | Type { EArc, ESegment, ESpline, EOldSpline, ECardinalSpline, ESpiroSpline }

## Public Member Functions
Type | type () const
int | countCP () const
Vector | cp (int i) const
Vector | last () const
Matrix | matrix () const
float | tension () const
Arc | arc () const
void | beziers (std::vector< Bezier > &bez) const
void | draw (Painter &painter) const
void | addToBBox (Rect &box, const Matrix &m, bool cp) const
double | distance (const Vector &v, const Matrix &m, double bound) const
void | snapVtx (const Vector &mouse, const Matrix &m, Vector &pos, double &bound, bool cp) const
void | snapBnd (const Vector &mouse, const Matrix &m, Vector &pos, double &bound) const

## Friends
class | Curve

## Detailed Description

A segment on an SubPath.

A segment is either an elliptic arc, a straight segment, or a spline curve, depending on its type(). This is a lightweight object, created on the fly by Curve::segment(). There is no public constructor, so the only way to create such an object is through that method.

The type() is one of the following:

- `ESegment:` the segment has two control points, and represents a line segment.
- `ESpline:` a B-spline curve with n control points. The first and last control point's knot value is repeated three times, so the curve begins and ends in these points. A spline with 4 control points is a single Bezier curve with those control points. A spline with 3 control points is defined to be a quadratic Bezier curve with those control points.
- `ECardinalSpline:` a cardinal spline curve with n control points. The curve passes through the control points in the given order. The tension is currently fixed at 0.5.
- `ESpiroSpline:` a clothoid spline curve with n control points, computed using Raph Levien's spiro code (through libspiro).
- `EOldSpline:` an incorrectly defined B-spline, used by Ipe for many years. Supported for compatibility.
- `EArc:` an elliptic arc, with begin and end point. The supporting ellipse is defined by the matrix(), it is the image under the affine transformation matrix() of the unit circle. matrix() is such that its inverse transforms both start and end position to points (nearly) on the unit circle. The arc is the image of the positively (counter-clockwise) directed arc from the pre-image of the start position to the pre-image of the end position. Whether this is a positively or negatively oriented arc in user space depends on the matrix.

## Member Enumeration Documentation

## ◆ Type

enum ipe::CurveSegment::Type

Enumerator
EArc |
ESegment |
ESpline |
EOldSpline |
ECardinalSpline |
ESpiroSpline |

## Member Function Documentation

## ◆ type()

CurveSegment::Type ipe::CurveSegment::type | ( |  | ) | const
| inline

Type of segment.

Referenced by ipe::Path::clone(), and ipe::Shape::isSegment().

## ◆ countCP()

int ipe::CurveSegment::countCP | ( |  | ) | const
| inline

Number of control points.

Referenced by ipe::Path::clone().

## ◆ cp()

Vector ipe::CurveSegment::cp | ( | int | i | ) | const
| inline

Return control point.

References addToBBox(), arc(), beziers(), distance(), draw(), last(), matrix(), snapBnd(), snapVtx(), and tension().

Referenced by ipe::Path::clone(), ipe::Curve::closed(), and ipe::Ellipse::matrix().

## ◆ last()

Vector ipe::CurveSegment::last | ( |  | ) | const
| inline

Return last control point.

Referenced by ipe::Path::clone(), and cp().

## ◆ matrix()

Matrix ipe::CurveSegment::matrix | ( |  | ) | const
| inline

Matrix (if Type() == EArc).

Referenced by ipe::Path::clone(), cp(), and ipe::Path::draw().

## ◆ tension()

float CurveSegment::tension | ( |  | ) | const

Tension (if Type() == ECardinalSpline)

Panics if segment is not a cardinal spline.

References ipe::ECardinalSpline.

Referenced by ipe::Curve::appendOldSpline(), and cp().

## ◆ arc()

Arc CurveSegment::arc | ( |  | ) | const

Return segment as Arc.

Panics if segment is not an arc.

Referenced by cp().

## ◆ beziers()

void CurveSegment::beziers | ( | std::vector< Bezier > & | bez | ) | const

Convert spline curve to a sequence of Bezier splines.

References ipe::Bezier::cardinalSpline(), ipe::ECardinalSpline, ipe::ESpiroSpline, ipe::Bezier::oldSpline(), and ipe::Bezier::spline().

Referenced by cp().

## ◆ draw()

void CurveSegment::draw | ( | Painter & | painter | ) | const

Draw the segment.

Current position of the painter is already on first control point.

References ipe::Painter::curveTo(), ipe::Painter::drawArc(), ipe::ECardinalSpline, ipe::ESpiroSpline, and ipe::Painter::lineTo().

Referenced by ipe::Curve::closed(), cp(), ipe::Ellipse::matrix(), and ipe::Shape::subPath().

## ◆ addToBBox()

void CurveSegment::addToBBox | ( | Rect & | box,
|  | const Matrix & | m,
|  | bool | cpf
| ) |  | const

Add segment to bounding box.

Does not assume that first control point has already been added.

If cpf is true, then control points of splines, Bezier curves, and the center of arcs are included in the bbox (so that snapping can find them). Otherwise, a tight bounding box for the geometric object itself is computed.

References ipe::Rect::addPoint(), ipe::Rect::addRect(), ipe::ECardinalSpline, and ipe::ESpiroSpline.

Referenced by ipe::Curve::closed(), cp(), and ipe::Ellipse::matrix().

## ◆ distance()

double CurveSegment::distance | ( | const Vector & | v,
|  | const Matrix & | m,
|  | double | bound
| ) |  | const

Return distance to the segment.

References ipe::Segment::distance(), ipe::ECardinalSpline, and ipe::ESpiroSpline.

Referenced by ipe::Curve::closed(), cp(), and ipe::Ellipse::matrix().

## ◆ snapVtx()

void CurveSegment::snapVtx | ( | const Vector & | mouse,
|  | const Matrix & | m,
|  | Vector & | pos,
|  | double & | bound,
|  | bool | ctl
| ) |  | const

Snap to vertex of the segment.

The method assumes that the first control point has already been tested.

References ipe::ECardinalSpline, and ipe::ESpiroSpline.

Referenced by ipe::Curve::closed(), cp(), and ipe::Ellipse::matrix().

## ◆ snapBnd()

void CurveSegment::snapBnd | ( | const Vector & | mouse,
|  | const Matrix & | m,
|  | Vector & | pos,
|  | double & | bound
| ) |  | const

References ipe::Curve::Curve(), ipe::Arc::distance(), ipe::ECardinalSpline, ipe::ESpiroSpline, and ipe::Segment::snap().

Referenced by ipe::Curve::closed(), cp(), and ipe::Ellipse::matrix().

## Friends And Related Function Documentation

## ◆ Curve

friend class Curve
| friend

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

- ipeshape.h
- ipeshape.cpp