ipe::Shape Class Reference
Ipe Geometry

`#include <ipeshape.h>`

## Public Member Functions

| Shape ()
| Shape (const Rect &rect)
| Shape (const Segment &seg)
| Shape (const Vector &center, double radius)
| Shape (const Vector &center, double radius, double alpha0, double alpha1)
| ~Shape ()
| Shape (const Shape &rhs)
Shape & | operator= (const Shape &rhs)
bool | load (String data)
void | save (Stream &stream) 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
int | countSubPaths () const
const SubPath * | subPath (int i) const
bool | isSegment () const
void | appendSubPath (SubPath *sp)
void | draw (Painter &painter) const

## Detailed Description

A geometric shape, consisting of several (open or closed) subpaths.

This class represents vector graphics geometry following the PDF "path", but is actually a bit more complicated since we add new subtypes: arcs, parabolas, uniform B-splines (in PDF, all of these are converted to cubic Bezier splines).

A Shape consists of a set of subpaths (SubPath), each of which is either open or closed, and which are rendered by stroking and filling as a whole. The distinction between open and closed is meaningful for stroking only, for filling any open subpath is implicitely closed. Stroking a set of subpaths is identical to stroking them individually. This is not true for filling: using several subpaths, one can construct objects with holes, and more complicated pattern.

A subpath is either an Ellipse (a complete, closed ellipse), a ClosedSpline (a closed uniform B-spline curve), or a Curve. A curve consists of a sequence of segments. Segments are either straight, a quadratic Bezier spline, a cubic Bezier spline, an elliptic arc, or a uniform cubic B-spline.

Shape is implemented using reference counting and can be copied and passed by value efficiently. The only mutator methods are appendSubPath() and load(), which can only be called during construction of the Shape (that is, before its implementation has been shared).

## Constructor & Destructor Documentation

## Shape() [1/6]

Shape::Shape | ( |  | ) |

Construct an empty shape (zero subpaths).

## Shape() [2/6]

Shape::Shape | ( | const Rect & | rect | ) |

explicit

Convenience function: create a rectangle shape.

References ipe::Curve::appendSegment(), appendSubPath(), ipe::Rect::bottomLeft(), ipe::Rect::bottomRight(), ipe::Curve::setClosed(), ipe::Rect::topLeft(), and ipe::Rect::topRight().

## Shape() [3/6]

Shape::Shape | ( | const Segment & | seg | ) |

explicit

Convenience function: create a single line segment.

References ipe::Curve::appendSegment(), appendSubPath(), ipe::Segment::iP, and ipe::Segment::iQ.

## Shape() [4/6]

Shape::Shape | ( | const Vector & | center,
|  | double | radius
| ) |  |

explicit

Convenience function: create circle with center and radius.

References appendSubPath(), ipe::Vector::x, and ipe::Vector::y.

## Shape() [5/6]

Shape::Shape | ( | const Vector & | center,
|  | double | radius,
|  | double | alpha0,
|  | double | alpha1
| ) |  |

explicit

Convenience function: create circular arc.

If alpha1 is larger than alpha0, the arc is oriented positively, otherwise negatively.

References ipe::Curve::appendArc(), appendSubPath(), ipe::Vector::x, and ipe::Vector::y.

## ~Shape()

Shape::~Shape | ( |  | ) |

Destructor (takes care of reference counting).

## Shape() [6/6]

Shape::Shape | ( | const Shape & | rhs | ) |

Copy constructor (constant time).

## Member Function Documentation

## operator=()

Shape & Shape::operator= | ( | const Shape & | rhs | ) |

Assignment operator (constant-time).

## load()

bool Shape::load | ( | String | data | ) |

Create a Shape from XML data.

Appends subpaths from XML data to the current Shape. Returns false if the path syntax is incorrect (the Shape will be in an inconsistent state and must be discarded).

This method can only be used during construction of the Shape. It will panic if the implementation has been shared.

References ipe::Curve::appendArc(), ipe::Curve::appendCardinalSpline(), ipe::Curve::appendOldSpline(), ipe::Curve::appendSegment(), ipe::Curve::appendSpiroSpline(), ipe::Curve::appendSpiroSplinePrecomputed(), ipe::Curve::appendSpline(), appendSubPath(), ipe::SubPath::asCurve(), ipe::Curve::countSegments(), countSubPaths(), ipe::Matrix::determinant(), ipe::Lex::eos(), ipe::Lex::nextToken(), ipe::Curve::setClosed(), ipe::Lex::skipWhitespace(), subPath(), and ipe::Lex::token().

Referenced by ipe::Group::Group().

## save()

void Shape::save | ( | Stream & | stream | ) | const

Save Shape onto XML stream.

References countSubPaths(), ipe::SubPath::save(), and subPath().

Referenced by ipe::Group::saveAsXml(), and ipe::Path::saveAsXml().

## addToBBox()

void Shape::addToBBox | ( | Rect & | box,
|  | const Matrix & | m,
|  | bool | cp
| ) |  | const

Add shape (transformed by m) to box.

References ipe::SubPath::addToBBox(), countSubPaths(), and subPath().

Referenced by ipe::Group::addToBBox(), and ipe::Path::addToBBox().

## distance()

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

References countSubPaths(), ipe::SubPath::distance(), and subPath().

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

## snapVtx()

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

References countSubPaths(), ipe::SubPath::snapVtx(), and subPath().

Referenced by ipe::Path::snapCtl(), and ipe::Path::snapVtx().

## snapBnd()

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

References countSubPaths(), ipe::SubPath::snapBnd(), and subPath().

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

## countSubPaths()

int ipe::Shape::countSubPaths | ( |  | ) | const

inline

Return number of subpaths.

Referenced by ipe::Group::addToBBox(), addToBBox(), distance(), ipe::Group::draw(), draw(), ipe::Group::drawSimple(), ipe::Group::Group(), isSegment(), load(), save(), ipe::Group::saveAsXml(), snapBnd(), and snapVtx().

## subPath()

const SubPath * ipe::Shape::subPath | ( | int | i | ) | const

inline

Return subpath.

Referenced by addToBBox(), distance(), draw(), ipe::Path::draw(), isSegment(), load(), save(), snapBnd(), and snapVtx().

## isSegment()

bool Shape::isSegment | ( |  | ) | const

Is this Shape a single straight segment?

References ipe::SubPath::asCurve(), ipe::SubPath::closed(), ipe::Curve::countSegments(), countSubPaths(), ipe::SubPath::ECurve, ipe::CurveSegment::ESegment, ipe::Curve::segment(), subPath(), ipe::CurveSegment::type(), and ipe::SubPath::type().

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

## appendSubPath()

void Shape::appendSubPath | ( | SubPath * | sp | ) |

Append a SubPath to shape.

The Shape will take ownership of the subpath. This method can only be used during construction of the Shape. It will panic if the implementation has been shared.

Referenced by load(), and Shape().

## draw()

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

Draw the Shape as a path to painter.

Does not call newPath() on painter.

References countSubPaths(), ipe::SubPath::draw(), and subPath().

Referenced by ipe::Group::draw(), ipe::Path::draw(), ipe::Group::drawSimple(), and ipe::Path::drawSimple().

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

- ipeshape.h
- ipeshape.cpp