Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
sbasis-curve.h
Go to the documentation of this file.
1/*
5 * Authors:
6 * MenTaLguY <mental@rydia.net>
7 * Marco Cecchetti <mrcekets at gmail.com>
8 * Krzysztof KosiƄski <tweenk.pl@gmail.com>
9 *
10 * Copyright 2007-2009 Authors
11 *
12 * This library is free software; you can redistribute it and/or
13 * modify it either under the terms of the GNU Lesser General Public
14 * License version 2.1 as published by the Free Software Foundation
15 * (the "LGPL") or, at your option, under the terms of the Mozilla
16 * Public License Version 1.1 (the "MPL"). If you do not alter this
17 * notice, a recipient may use your version of this file under either
18 * the MPL or the LGPL.
19 *
20 * You should have received a copy of the LGPL along with this library
21 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * You should have received a copy of the MPL along with this library
24 * in the file COPYING-MPL-1.1
25 *
26 * The contents of this file are subject to the Mozilla Public License
27 * Version 1.1 (the "License"); you may not use this file except in
28 * compliance with the License. You may obtain a copy of the License at
29 * http://www.mozilla.org/MPL/
30 *
31 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
32 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
33 * the specific language governing rights and limitations.
34 */
35
36#ifndef LIB2GEOM_SEEN_SBASIS_CURVE_H
37#define LIB2GEOM_SEEN_SBASIS_CURVE_H
38
39#include <2geom/curve.h>
40#include <2geom/exception.h>
41#include <2geom/nearest-time.h>
43#include <2geom/transforms.h>
44
45namespace Geom
46{
47
80class SBasisCurve : public Curve {
81private:
83
84public:
85 explicit SBasisCurve(D2<SBasis> const &sb) : inner(sb) {}
86 explicit SBasisCurve(Curve const &other) : inner(other.toSBasis()) {}
87
88 Curve *duplicate() const override { return new SBasisCurve(*this); }
89 Point initialPoint() const override { return inner.at0(); }
90 Point finalPoint() const override { return inner.at1(); }
91 bool isDegenerate() const override { return inner.isConstant(0); }
92 bool isLineSegment() const override { return inner[X].size() == 1; }
93 Point pointAt(Coord t) const override { return inner.valueAt(t); }
94 std::vector<Point> pointAndDerivatives(Coord t, unsigned n) const override {
95 return inner.valueAndDerivatives(t, n);
96 }
97 Coord valueAt(Coord t, Dim2 d) const override { return inner[d].valueAt(t); }
98 void setInitial(Point const &v) override {
99 for (unsigned d = 0; d < 2; d++) { inner[d][0][0] = v[d]; }
100 }
101 void setFinal(Point const &v) override {
102 for (unsigned d = 0; d < 2; d++) { inner[d][0][1] = v[d]; }
103 }
104 Rect boundsFast() const override { return *bounds_fast(inner); }
105 Rect boundsExact() const override { return *bounds_exact(inner); }
106 void expandToTransformed(Rect &bbox, Affine const &transform) const override {
107 bbox |= bounds_exact(inner * transform);
108 }
109 OptRect boundsLocal(OptInterval const &i, unsigned deg) const override {
110 return bounds_local(inner, i, deg);
111 }
112 std::vector<Coord> roots(Coord v, Dim2 d) const override { return Geom::roots(inner[d] - v); }
113 Coord nearestTime( Point const& p, Coord from = 0, Coord to = 1 ) const override {
114 return nearest_time(p, inner, from, to);
115 }
116 std::vector<Coord> allNearestTimes( Point const& p, Coord from = 0,
117 Coord to = 1 ) const override
118 {
119 return all_nearest_times(p, inner, from, to);
120 }
121 Coord length(Coord tolerance) const override { return ::Geom::length(inner, tolerance); }
122 Curve *portion(Coord f, Coord t) const override {
123 return new SBasisCurve(Geom::portion(inner, f, t));
124 }
125
126 using Curve::operator*=;
127 void operator*=(Affine const &m) override { inner = inner * m; }
128
129 Curve *derivative() const override {
131 }
132 D2<SBasis> toSBasis() const override { return inner; }
133 bool isNear(Curve const &/*c*/, Coord /*eps*/) const override {
134 THROW_NOTIMPLEMENTED();
135 return false;
136 }
137 int degreesOfFreedom() const override {
138 return inner[0].degreesOfFreedom() + inner[1].degreesOfFreedom();
139 }
140
141protected:
142 bool _equalTo(Curve const &c) const override {
143 if (this == &c) return true;
144 auto other = dynamic_cast<SBasisCurve const *>(&c);
145 if (!other) return false;
146 return inner == other->inner;
147 }
148};
149
150} // end namespace Geom
151
152#endif // LIB2GEOM_SEEN_SBASIS_CURVE_H
153
154/*
155 Local Variables:
156 mode:c++
157 c-file-style:"stroustrup"
158 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
159 indent-tabs-mode:nil
160 fill-column:99
161 End:
162*/
163// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Defines the different types of exceptions that 2geom can throw.
Abstract curve type.
3x3 matrix representing an affine transformation.
Definition affine.h:70
Abstract continuous curve on a plane defined on [0,1].
Definition curve.h:78
void transform(Affine const &m)
Transform this curve by an affine transformation.
Definition curve.h:193
Adaptor that creates 2D functions from 1D ones.
Definition d2.h:55
Range of real numbers that can be empty.
Definition interval.h:199
Axis-aligned rectangle that can be empty.
Definition rect.h:203
Two-dimensional point that doubles as a vector.
Definition point.h:66
Axis aligned, non-empty rectangle.
Definition rect.h:92
Symmetric power basis curve.
void setInitial(Point const &v) override
Change the starting point of the curve.
std::vector< Coord > roots(Coord v, Dim2 d) const override
Computes time values at which the curve intersects an axis-aligned line.
bool isDegenerate() const override
Check whether the curve has exactly zero length.
Coord nearestTime(Point const &p, Coord from=0, Coord to=1) const override
Compute a time value at which the curve comes closest to a specified point.
Curve * derivative() const override
Create a derivative of this curve.
bool _equalTo(Curve const &c) const override
Curve * portion(Coord f, Coord t) const override
Create a curve that corresponds to a part of this curve.
Curve * duplicate() const override
Create an exact copy of this curve.
OptRect boundsLocal(OptInterval const &i, unsigned deg) const override
D2< SBasis > toSBasis() const override
Convert the curve to a symmetric power basis polynomial.
void setFinal(Point const &v) override
Change the ending point of the curve.
int degreesOfFreedom() const override
Return the number of independent parameters required to represent all variations of this curve.
bool isLineSegment() const override
Check whether the curve is a line segment.
Rect boundsFast() const override
Quickly compute the curve's approximate bounding box.
bool isNear(Curve const &, Coord) const override
Test whether two curves are approximately the same.
Point finalPoint() const override
Retrieve the end of the curve.
SBasisCurve(Curve const &other)
void expandToTransformed(Rect &bbox, Affine const &transform) const override
Expand the given rectangle to include the transformed curve, assuming it already contains its initial...
Coord valueAt(Coord t, Dim2 d) const override
Evaluate one of the coordinates at the specified time value.
Point pointAt(Coord t) const override
Evaluate the curve at a specified time value.
void operator*=(Affine const &m) override
D2< SBasis > inner
SBasisCurve(D2< SBasis > const &sb)
std::vector< Coord > allNearestTimes(Point const &p, Coord from=0, Coord to=1) const override
Compute time values at which the curve comes closest to a specified point.
std::vector< Point > pointAndDerivatives(Coord t, unsigned n) const override
Evaluate the curve and its derivatives.
Point initialPoint() const override
Retrieve the start of the curve.
Coord length(Coord tolerance) const override
Compute the arc length of this curve.
Rect boundsExact() const override
Compute the curve's exact bounding box.
double c[8][4]
Dim2
2D axis enumeration (X or Y).
Definition coord.h:48
double Coord
Floating point type used to store coordinates.
Definition coord.h:76
@ X
Definition coord.h:48
Various utility functions.
Definition affine.h:22
OptInterval bounds_exact(Bezier const &b)
Definition bezier.cpp:310
OptInterval bounds_local(Bezier const &b, OptInterval const &i)
Definition bezier.cpp:320
Coord nearest_time(Point const &p, Curve const &c)
Definition curve.h:354
std::vector< double > roots(SBasis const &s)
std::vector< double > all_nearest_times(Point const &p, D2< SBasis > const &c, D2< SBasis > const &dc, double from=0, double to=1)
Bezier portion(const Bezier &a, double from, double to)
Definition bezier.cpp:250
Bezier derivative(Bezier const &a)
Definition bezier.cpp:282
OptInterval bounds_fast(Bezier const &b)
Definition bezier.cpp:305
Nearest time routines for D2<SBasis> and Piecewise<D2<SBasis>>
two-dimensional geometric operators.
Affine transformation classes.