Ipelib
|
#include <ipeshape.h>
Public Member Functions | |
Shape () | |
Shape (const Rect &rect) | |
Shape (const Segment &seg) | |
Shape (const Vector ¢er, double radius) | |
Shape (const Vector ¢er, 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 |
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).
Shape::Shape | ( | ) |
Construct an empty shape (zero subpaths).
|
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().
|
explicit |
Convenience function: create a single line segment.
References ipe::Curve::appendSegment(), appendSubPath(), ipe::Segment::iP, and ipe::Segment::iQ.
|
explicit |
Convenience function: create circle with center and radius.
References appendSubPath(), ipe::Vector::x, and ipe::Vector::y.
|
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 | ( | ) |
Destructor (takes care of reference counting).
Shape::Shape | ( | const Shape & | rhs | ) |
Copy constructor (constant time).
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().
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().
Add shape (transformed by m) to box.
References ipe::SubPath::addToBBox(), countSubPaths(), and subPath().
Referenced by ipe::Group::addToBBox(), and ipe::Path::addToBBox().
References countSubPaths(), ipe::SubPath::distance(), and subPath().
Referenced by ipe::Path::distance().
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().
References countSubPaths(), ipe::SubPath::snapBnd(), and subPath().
Referenced by ipe::Path::snapBnd().
|
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().
|
inline |
Return subpath.
Referenced by addToBBox(), distance(), draw(), ipe::Path::draw(), isSegment(), load(), save(), snapBnd(), and snapVtx().
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().
void Shape::appendSubPath | ( | SubPath * | sp | ) |
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().