Inkscape
Vector Graphics Editor
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages Concepts
geom-curves.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef INKSCAPE_HELPER_GEOM_CURVES_H
3#define INKSCAPE_HELPER_GEOM_CURVES_H
4
9/*
10 * Author:
11 * Johan Engelen <goejendaagh@zonnet.nl>
12 *
13 * Copyright (C) 2008-2009 Johan Engelen
14 *
15 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
16 */
17
18#include <2geom/line.h>
19#include <2geom/bezier-curve.h>
20
23{
24 // the curve can be a quad/cubic bezier, but could still be a perfect straight line
25 // if the control points are exactly on the line connecting the initial and final points.
26 auto const line = Geom::Line{c.initialPoint(), c.finalPoint()};
27 for (int i = 1; i < c.order(); i++) {
28 if (!Geom::are_near(c[i], line)) {
29 return false;
30 }
31 }
32 return true;
33}
34
35inline bool is_straight_curve(Geom::Curve const &c)
36{
37 if (dynamic_cast<Geom::LineSegment const *>(&c)) {
38 return true;
39 } else if (auto bezier = dynamic_cast<Geom::BezierCurve const *>(&c)) {
40 return is_straight_curve(*bezier);
41 } else {
42 return false;
43 }
44}
45
46#endif // INKSCAPE_HELPER_GEOM_CURVES_H
47
48/*
49 Local Variables:
50 mode:c++
51 c-file-style:"stroustrup"
52 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
53 indent-tabs-mode:nil
54 fill-column:99
55 End:
56*/
57// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Bezier curve.
Two-dimensional Bezier curve of arbitrary order.
Abstract continuous curve on a plane defined on [0,1].
Definition curve.h:78
Infinite line on a plane.
Definition line.h:53
Point initialPoint() const
Definition line.h:225
double c[8][4]
bool is_straight_curve(Geom::BezierCurve const &c)
Definition geom-curves.h:22
Infinite straight line.
bool are_near(Affine const &a1, Affine const &a2, Coord eps=EPSILON)