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) ///< step per 2PI 25 #define SAMPLE_SIZE 8 ///< sample size per one bezier 26 27 28 #define SP_SPIRAL(obj) (dynamic_cast<SPSpiral*>((SPObject*)obj)) 29 #define SP_IS_SPIRAL(obj) (dynamic_cast<const SPSpiral*>((SPObject*)obj) != NULL) 30 31 /** 32 * A spiral Shape. 33 * 34 * The Spiral shape is defined as: 35 * \verbatim 36 x(t) = rad * t^exp cos(2 * Pi * revo*t + arg) + cx 37 y(t) = rad * t^exp sin(2 * Pi * revo*t + arg) + cy \endverbatim 38 * where spiral curve is drawn for {t | t0 <= t <= 1}. The rad and arg 39 * parameters can also be represented by transformation. 40 * 41 * \todo Should I remove these attributes? 42 */ 43 class SPSpiral : public SPShape { 44 public: 45 SPSpiral(); 46 ~SPSpiral() override; 47 48 float cx, cy; 49 float exp; ///< Spiral expansion factor 50 float revo; ///< Spiral revolution factor 51 float rad; ///< Spiral radius 52 float arg; ///< Spiral argument 53 float t0; 54 55 /* Lowlevel interface */ 56 void setPosition(double cx, double cy, double exp, double revo, double rad, double arg, double t0); 57 Geom::Affine set_transform(Geom::Affine const& xform) override; 58 59 Geom::Point getXY(double t) const; 60 61 void getPolar(double t, double* rad, double* arg) const; 62 63 bool isInvalid() const; 64 65 void build(SPDocument* doc, Inkscape::XML::Node* repr) override; 66 Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override; 67 void update(SPCtx *ctx, unsigned int flags) override; 68 void set(SPAttr key, char const* value) override; 69 70 void snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) const override; 71 const char* displayName() const override; 72 char* description() const override; 73 void update_patheffect(bool write) override; 74 void set_shape() override; 75 76 private: 77 Geom::Point getTangent(double t) const; 78 void fitAndDraw(SPCurve* c, double dstep, Geom::Point darray[], Geom::Point const& hat1, Geom::Point& hat2, double* t) const; 79 }; 80 81 #endif // SEEN_SP_SPIRAL_H 82