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 virtual inline
64 void toStream(std::ostream & ostr) const override {
65 ostr << '(';
67 ostr << ')';
68 }
69
70};
71
72}
73
74}
75
76
77template <size_t N>
78std::ostream & operator<<(std::ostream & ostr, const drain::image::Transform<N> & tr){
79 tr.toStream(ostr);
80 return ostr;
81}
82
83
84namespace drain {
85
86namespace image {
87
88
89// Future option
91
92public:
93
94 typedef double coord_t;
95
97
98 inline
99 bool empty() const {
100 return (rotate.empty() && scale.empty() && translate.empty() && matrix.empty()) ;
101 }
102
103 inline
104 void setTranslate(const coord_t & x, const coord_t & y){
105 // translate.ensureSize(2);
106 translate.set(x,y);
107 }
108
109 inline
110 void setTranslateX(const coord_t & x){
111 // translate.ensureSize(1);
112 // translate.set(x);
113 translate[0] = x;
114 }
115
116 inline
117 void setTranslateY(const coord_t & y){
118 // translate.ensureSize(2);
119 // svg::coord_t x = translate.get<svg::coord_t>(1);
120 translate[1] = y;
121 // translate.set(x, y);
122 }
123
125
126
127 struct Translate : public Transform<2> {
128
129 double & x;
130 double & y;
131
132 inline
133 Translate(double x=0.0, double y=0.0) : x(++next()=x), y(++next()=y){
134 }
135
136 inline
137 Translate(const Translate & t) : x(++next()=t.x), y(++next()=t.y){
138 }
139
140 };
141
142
143 Transform<3> rotate;
144 Transform<2> scale;
145 //Transform<2> translate;
146 Translate translate;
147 Transform<6> matrix;
148
149 void toStream(std::ostream & ostr) const;
150
151};
152
153
154} // image::
155
156} // drain::
157
158inline
159std::ostream & operator<<(std::ostream & ostr, const drain::image::TransformSVG & tr){
160 tr.toStream(ostr);
161 return ostr;
162}
163
164#endif
165
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:90
Definition TransformSVG.h:55
Definition DataSelector.cpp:1277
Angle (deg), [x,y].
Definition TransformSVG.h:127