Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
sp-spiral.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef SEEN_SP_SPIRAL_H
3#define SEEN_SP_SPIRAL_H
4/*
5 * Authors:
6 * Mitsuru Oka <oka326@parkcity.ne.jp>
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 *
9 * Copyright (C) 1999-2002 Lauris Kaplinski
10 * Copyright (C) 2000-2001 Ximian, Inc.
11 *
12 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
13 */
14
15#include "sp-shape.h"
16
17#define noSPIRAL_VERBOSE
18
19#define SP_EPSILON 1e-5
20#define SP_EPSILON_2 (SP_EPSILON * SP_EPSILON)
21#define SP_HUGE 1e5
22
23#define SPIRAL_TOLERANCE 3.0
24#define SAMPLE_STEP (1.0/4.0)
25#define SAMPLE_SIZE 8
26
39class SPSpiral final : public SPShape {
40public:
41 SPSpiral();
42 ~SPSpiral() override;
43 int tag() const override { return tag_of<decltype(*this)>; }
44
45 float cx, cy;
46 float exp;
47 float revo;
48 float rad;
49 float arg;
50 float t0;
51
52 /* Lowlevel interface */
53 void setPosition(double cx, double cy, double exp, double revo, double rad, double arg, double t0);
54 Geom::Affine set_transform(Geom::Affine const& xform) override;
55
56 Geom::Point getXY(double t) const;
57
58 void getPolar(double t, double* rad, double* arg) const;
59
60 bool isInvalid() const;
61
62 void build(SPDocument* doc, Inkscape::XML::Node* repr) override;
63 Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override;
64 void update(SPCtx *ctx, unsigned int flags) override;
65 void set(SPAttr key, char const* value) override;
66
67 void snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) const override;
68 const char* typeName() const override;
69 const char* displayName() const override;
70 char* description() const override;
71 void update_patheffect(bool write) override;
72 void set_shape() override;
73
74private:
75 Geom::Point getTangent(double t) const;
76 void fitAndDraw(Geom::Path &c, double dstep, Geom::Point darray[], Geom::Point const& hat1, Geom::Point& hat2, double* t) const;
77};
78
79#endif // SEEN_SP_SPIRAL_H
SPAttr
Definition attributes.h:27
constexpr int tag_of
Convenience function to retrieve the tag (class id) of a given type.
Definition cast.h:26
3x3 matrix representing an affine transformation.
Definition affine.h:70
Sequence of contiguous curves, aka spline.
Definition path.h:353
Two-dimensional point that doubles as a vector.
Definition point.h:66
Storing of snapping preferences.
Interface for refcounted XML nodes.
Definition node.h:80
Typed SVG document implementation.
Definition document.h:101
Inkscape::XML::Node * repr
Definition sp-object.h:193
Base class for shapes, including <path> element.
Definition sp-shape.h:38
A spiral Shape.
Definition sp-spiral.h:39
void update_patheffect(bool write) override
void set_shape() override
bool isInvalid() const
Return true if spiral has properties that make it invalid.
void build(SPDocument *doc, Inkscape::XML::Node *repr) override
Definition sp-spiral.cpp:50
Geom::Point getTangent(double t) const
Returns the derivative of sp_spiral_get_xy with respect to t, scaled to a unit vector.
void update(SPCtx *ctx, unsigned int flags) override
float t0
Definition sp-spiral.h:50
void fitAndDraw(Geom::Path &c, double dstep, Geom::Point darray[], Geom::Point const &hat1, Geom::Point &hat2, double *t) const
Fit beziers together to spiral and draw it.
float cx
Definition sp-spiral.h:45
~SPSpiral() override
float revo
Spiral revolution factor.
Definition sp-spiral.h:47
float rad
Spiral radius.
Definition sp-spiral.h:48
const char * typeName() const override
The item's type name, not node tag name.
float exp
Spiral expansion factor.
Definition sp-spiral.h:46
float arg
Spiral argument.
Definition sp-spiral.h:49
const char * displayName() const override
The item's type name as a translated human string.
Inkscape::XML::Node * write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override
Definition sp-spiral.cpp:62
void setPosition(double cx, double cy, double exp, double revo, double rad, double arg, double t0)
Set spiral properties and update display.
char * description() const override
void getPolar(double t, double *rad, double *arg) const
Compute rad and/or arg for point on spiral.
Geom::Affine set_transform(Geom::Affine const &xform) override
Set spiral transform.
void snappoints(std::vector< Inkscape::SnapCandidatePoint > &p, Inkscape::SnapPreferences const *snapprefs) const override
float cy
Definition sp-spiral.h:45
Geom::Point getXY(double t) const
Return one of the points on the spiral.
int tag() const override
Definition sp-spiral.h:43
double c[8][4]
static cairo_user_data_key_t key
Interface for XML documents.
Definition document.h:43
Unused.
Definition sp-object.h:94