Loading...
Searching...
No Matches
TransformSVG.h
1/*
2
3MIT License
4
5Copyright (c) 2023 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31/*
32 * TreeSVG.h
33 *
34 * Created on: Jun 24, 2012
35 * Author: mpeura
36 */
37
38#ifndef DRAIN_TRANSFORM_SVG
39#define DRAIN_TRANSFORM_SVG
40
41//#include "drain/util/EnumFlags.h"
42#include "drain/UniTuple.h"
43//#include "drain/util/FileInfo.h"
44//#include "drain/util/Frame.h"
45//#include "drain/util/SelectorXML.h"
46//#include "drain/util/TreeXML.h"
47//#include "AlignSVG.h"
48
49namespace drain {
50
51namespace image {
52
53
54template <size_t N>
55class Transform : public UniTuple<double,N> {
56
57public:
58
59 bool empty() const {
60 return (*this == 0.0);
61 }
62
63
64 template <class T>
65 Transform<N> & operator=(const T & x){
66 set(x);
67 }
68
69 template <class T>
70 Transform<N> & operator=(const std::initializer_list<T> & x){
72 }
73
74
75
76 virtual inline
77 void toStream(std::ostream & ostr) const override {
78 ostr << '(';
80 ostr << ')';
81 }
82
83};
84
85}
86
87}
88
89
90template <size_t N>
91std::ostream & operator<<(std::ostream & ostr, const drain::image::Transform<N> & tr){
92 tr.toStream(ostr);
93 return ostr;
94}
95
96
97namespace drain {
98
99namespace image {
100
101
102// Future option
104
105public:
106
107 typedef double coord_t;
108
110 TransformSVG();
111
113 TransformSVG(const TransformSVG & tr);
114
115 TransformSVG & operator=(const TransformSVG &) = default;
116
117 inline
118 bool empty() const {
119 return (rotate.empty() && scale.empty() && translate.empty() && matrix.empty()) ;
120 }
121
122 inline
123 void setTranslate(const coord_t & x, const coord_t & y){
124 // translate.ensureSize(2);
125 translate.set(x,y);
126 }
127
128 inline
129 void setTranslateX(const coord_t & x){
130 // translate.ensureSize(1);
131 // translate.set(x);
132 translate[0] = x;
133 }
134
135 inline
136 void setTranslateY(const coord_t & y){
137 // translate.ensureSize(2);
138 // svg::coord_t x = translate.get<svg::coord_t>(1);
139 translate[1] = y;
140 // translate.set(x, y);
141 }
142
144
145
146 struct Translate : public Transform<2> {
147
148 double & x;
149 double & y;
150
151 inline
152 Translate(double x=0.0, double y=0.0) : x(++next()=x), y(++next()=y){
153 }
154
155 inline
156 Translate(const Translate & t) : x(++next()=t.x), y(++next()=t.y){
157 }
158
159 inline
160 Translate & operator=(const Translate & t){
161 x = t.x;
162 y = t.y;
163 return *this;
164 }
165
166
167 };
168
169
170 Transform<3> rotate;
171 Transform<2> scale;
172 //Transform<2> translate;
173 Translate translate;
174 Transform<6> matrix;
175
176 void toStream(std::ostream & ostr) const;
177
178};
179
180
181} // image::
182
183inline
184std::ostream & operator<<(std::ostream & ostr, const image::TransformSVG & tr){
185 tr.toStream(ostr);
186 return ostr;
187}
188
189} // drain::
190
191/*
192 *
193 */
194
195#endif
196
tuplebase_t & assignSequence(T &sequence, bool LENIENT=false)
Proposed for tuples only; derived classes should not shadow this.
Definition TupleBase.h:287
virtual void toStreamFormatted(std::ostream &ostr, char separator=',') const
Definition TupleBase.h:331
Tuple of N elements of type T.
Definition UniTuple.h:65
Definition TransformSVG.h:103
TransformSVG()
Default constructor.
Definition TransformSVG.cpp:46
Definition TransformSVG.h:55
Definition Data.h:1473
Angle (deg), [x,y].
Definition TransformSVG.h:146