9a07ba860fceda73485a5f4a146d233ac14b8e9c
[synfig.git] / synfig-core / src / synfig / blinepoint.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file blinepoint.h
3 **      \brief Template Header
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_BLINEPOINT_H
26 #define __SYNFIG_BLINEPOINT_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include "vector.h"
31 #include "uniqueid.h"
32 #include <algorithm>
33
34 /* === M A C R O S ========================================================= */
35
36 /* === T Y P E D E F S ===================================================== */
37
38 /* === C L A S S E S & S T R U C T S ======================================= */
39
40 namespace synfig {
41
42 class BLinePoint : public UniqueID
43 {
44 private:
45         Point   vertex_;
46         Vector  tangent_[2];
47         float   width_;
48         float   origin_;
49         bool    split_tangent_;
50         bool    link_radius_;
51         bool    link_theta_;
52
53 public:
54
55         BLinePoint():
56                 vertex_(Point(0,0)),
57                 width_(0.01),
58                 origin_(0.0),
59                 split_tangent_(false),
60                 link_radius_(true),
61                 link_theta_(true)
62         { tangent_[0] = Point(0,0); tangent_[1] = Point(0,0); }
63
64         const Point& get_vertex()const { return vertex_; }
65         void set_vertex(const Point& x) { vertex_=x; }
66
67
68         const Vector& get_tangent1()const { return tangent_[0]; }
69         const Vector& get_tangent2()const { return tangent_[1]; }
70         void set_tangent(const Vector& x) { tangent_[0]=tangent_[1]=x; }
71         void set_tangent1(const Vector& x) { tangent_[0]=x; normalize(1);}
72         void set_tangent2(const Vector& x) { tangent_[1]=x; normalize(0);}
73
74
75         const float& get_width()const { return width_; }
76         void set_width(float x) { width_=x; }
77
78         // We store the origin offset by 0.5 so that
79         // can have the origin set to the default by zeroing
80         // out the structure.
81         float get_origin()const { return origin_+0.5f; }
82         void set_origin(float x) { origin_=x-0.5f; }
83
84
85         const bool& get_split_tangent_flag()const { return split_tangent_; }
86         void set_split_tangent_flag(bool x=true) { link_radius_=link_theta_=!x; normalize();}
87
88         const bool& get_link_radius_flag()const { return link_radius_; }
89         void set_link_radius_flag(bool x=true) { link_radius_=x; normalize();}
90
91         const bool& get_link_theta_flag()const { return link_theta_; }
92         void set_link_theta_flag(bool x=true) { link_theta_=x; normalize();}
93
94         //normalize tangents, i.e. make sure their values correspond to the linkage
95         void normalize(int i=0);
96
97         void reverse();
98
99 }; // END of class BLinePoint
100
101 }; // END of namespace synfig
102
103 /* === E N D =============================================================== */
104
105 #endif