31 #ifndef _2GEOM_D2 //If this is change, change the guard in rect.h as well.
38 #include <boost/concept_check.hpp>
50 D2() {f[X] = f[Y] = T();}
51 explicit D2(Point
const &a) {
52 f[X] = T(a[X]); f[Y] = T(a[Y]);
55 D2(T
const &a, T
const &b) {
62 T& operator[](
unsigned i) {
return f[i]; }
63 T
const & operator[](
unsigned i)
const {
return f[i]; }
66 typedef Point output_type;
68 boost::function_requires<FragmentConcept<T> >();
69 return f[X].isZero() && f[Y].isZero();
71 bool isConstant()
const {
72 boost::function_requires<FragmentConcept<T> >();
73 return f[X].isConstant() && f[Y].isConstant();
75 bool isFinite()
const {
76 boost::function_requires<FragmentConcept<T> >();
77 return f[X].isFinite() && f[Y].isFinite();
80 boost::function_requires<FragmentConcept<T> >();
81 return Point(f[X].at0(), f[Y].at0());
84 boost::function_requires<FragmentConcept<T> >();
85 return Point(f[X].at1(), f[Y].at1());
87 Point valueAt(
double t)
const {
88 boost::function_requires<FragmentConcept<T> >();
91 std::vector<Point > valueAndDerivatives(
double t,
unsigned count)
const {
92 std::vector<Coord> x = f[X].valueAndDerivatives(t, count),
93 y = f[Y].valueAndDerivatives(t, count);
94 std::vector<Point> res;
95 for(
unsigned i = 0; i < count; i++) {
96 res.push_back(Point(x[i], y[i]));
100 D2<SBasis> toSBasis()
const {
101 boost::function_requires<FragmentConcept<T> >();
102 return D2<SBasis>(f[X].toSBasis(), f[Y].toSBasis());
105 Point operator()(
double t)
const;
106 Point operator()(
double x,
double y)
const;
108 template <
typename T>
109 inline D2<T> reverse(
const D2<T> &a) {
110 boost::function_requires<FragmentConcept<T> >();
111 return D2<T>(reverse(a[X]), reverse(a[Y]));
114 template <
typename T>
115 inline D2<T> portion(
const D2<T> &a,
Coord f,
Coord t) {
116 boost::function_requires<FragmentConcept<T> >();
117 return D2<T>(portion(a[X], f, t), portion(a[Y], f, t));
121 template <
typename T>
123 operator==(D2<T>
const &a, D2<T>
const &b) {
124 boost::function_requires<boost::EqualityComparableConcept<T> >();
125 return a[0]==b[0] && a[1]==b[1];
127 template <
typename T>
129 operator!=(D2<T>
const &a, D2<T>
const &b) {
130 boost::function_requires<boost::EqualityComparableConcept<T> >();
131 return a[0]!=b[0] || a[1]!=b[1];
135 template <
typename T>
137 are_near(D2<T>
const &a, D2<T>
const &b,
double tol) {
138 boost::function_requires<NearConcept<T> >();
139 return are_near(a[0], b[0]) && are_near(a[1], b[1]);
143 template <
typename T>
145 operator+(D2<T>
const &a, D2<T>
const &b) {
146 boost::function_requires<AddableConcept<T> >();
149 for(
unsigned i = 0; i < 2; i++)
153 template <
typename T>
155 operator-(D2<T>
const &a, D2<T>
const &b) {
156 boost::function_requires<AddableConcept<T> >();
159 for(
unsigned i = 0; i < 2; i++)
163 template <
typename T>
165 operator+=(D2<T> &a, D2<T>
const &b) {
166 boost::function_requires<AddableConcept<T> >();
168 for(
unsigned i = 0; i < 2; i++)
172 template <
typename T>
174 operator-=(D2<T> &a, D2<T>
const & b) {
175 boost::function_requires<AddableConcept<T> >();
177 for(
unsigned i = 0; i < 2; i++)
183 template <
typename T>
185 operator-(D2<T>
const & a) {
186 boost::function_requires<ScalableConcept<T> >();
188 for(
unsigned i = 0; i < 2; i++)
192 template <
typename T>
194 operator*(D2<T>
const & a, Point
const & b) {
195 boost::function_requires<ScalableConcept<T> >();
198 for(
unsigned i = 0; i < 2; i++)
202 template <
typename T>
204 operator/(D2<T>
const & a, Point
const & b) {
205 boost::function_requires<ScalableConcept<T> >();
208 for(
unsigned i = 0; i < 2; i++)
212 template <
typename T>
214 operator*=(D2<T> &a, Point
const & b) {
215 boost::function_requires<ScalableConcept<T> >();
217 for(
unsigned i = 0; i < 2; i++)
221 template <
typename T>
223 operator/=(D2<T> &a, Point
const & b) {
224 boost::function_requires<ScalableConcept<T> >();
226 for(
unsigned i = 0; i < 2; i++)
231 template <
typename T>
232 inline D2<T> operator*(D2<T>
const & a,
double b) {
return D2<T>(a[0]*b, a[1]*b); }
233 template <
typename T>
234 inline D2<T> operator*=(D2<T> & a,
double b) { a[0] *= b; a[1] *= b;
return a; }
235 template <
typename T>
236 inline D2<T> operator/(D2<T>
const & a,
double b) {
return D2<T>(a[0]/b, a[1]/b); }
237 template <
typename T>
238 inline D2<T> operator/=(D2<T> & a,
double b) { a[0] /= b; a[1] /= b;
return a; }
241 D2<T> operator*(D2<T>
const &v, Matrix
const &m) {
242 boost::function_requires<AddableConcept<T> >();
243 boost::function_requires<ScalableConcept<T> >();
245 for(
unsigned i = 0; i < 2; i++)
246 ret[i] = v[X] * m[i] + v[Y] * m[i + 2] + m[i + 4];
251 template <
typename T>
253 operator+(D2<T>
const & a, Point b) {
254 boost::function_requires<OffsetableConcept<T> >();
256 for(
unsigned i = 0; i < 2; i++)
260 template <
typename T>
262 operator-(D2<T>
const & a, Point b) {
263 boost::function_requires<OffsetableConcept<T> >();
265 for(
unsigned i = 0; i < 2; i++)
269 template <
typename T>
271 operator+=(D2<T> & a, Point b) {
272 boost::function_requires<OffsetableConcept<T> >();
273 for(
unsigned i = 0; i < 2; i++)
277 template <
typename T>
279 operator-=(D2<T> & a, Point b) {
280 boost::function_requires<OffsetableConcept<T> >();
281 for(
unsigned i = 0; i < 2; i++)
286 template <
typename T>
288 dot(D2<T>
const & a, D2<T>
const & b) {
289 boost::function_requires<AddableConcept<T> >();
290 boost::function_requires<MultiplicableConcept<T> >();
293 for(
unsigned i = 0; i < 2; i++)
298 template <
typename T>
300 cross(D2<T>
const & a, D2<T>
const & b) {
301 boost::function_requires<ScalableConcept<T> >();
302 boost::function_requires<MultiplicableConcept<T> >();
304 return a[1] * b[0] - a[0] * b[1];
309 template <
typename T>
311 rot90(D2<T>
const & a) {
312 boost::function_requires<ScalableConcept<T> >();
313 return D2<T>(-a[Y], a[X]);
317 template <
typename T>
319 compose(D2<T>
const & a, T
const & b) {
321 for(
unsigned i = 0; i < 2; i++)
322 r[i] = compose(a[i],b);
326 template <
typename T>
328 compose_each(D2<T>
const & a, D2<T>
const & b) {
330 for(
unsigned i = 0; i < 2; i++)
331 r[i] = compose(a[i],b[i]);
335 template <
typename T>
337 compose_each(T
const & a, D2<T>
const & b) {
339 for(
unsigned i = 0; i < 2; i++)
340 r[i] = compose(a,b[i]);
347 D2<T>::operator()(
double t)
const {
349 for(
unsigned i = 0; i < 2; i++)
350 p[i] = (*
this)[i](t);
357 D2<T>::operator()(
double x,
double y)
const {
359 for(
unsigned i = 0; i < 2; i++)
360 p[i] = (*
this)[i](x, y);
366 D2<T> derivative(D2<T>
const & a) {
367 return D2<T>(derivative(a[X]), derivative(a[Y]));
370 D2<T> integral(D2<T>
const & a) {
371 return D2<T>(integral(a[X]), integral(a[Y]));
377 #include "d2-sbasis.h"
382 template <
typename T>
383 Rect bounds_fast(
const D2<T> &a) {
384 boost::function_requires<FragmentConcept<T> >();
385 return Rect(bounds_fast(a[X]), bounds_fast(a[Y]));
387 template <
typename T>
388 Rect bounds_exact(
const D2<T> &a) {
389 boost::function_requires<FragmentConcept<T> >();
390 return Rect(bounds_exact(a[X]), bounds_exact(a[Y]));
392 template <
typename T>
393 Rect bounds_local(
const D2<T> &a,
const Interval &t) {
394 boost::function_requires<FragmentConcept<T> >();
395 return Rect(bounds_local(a[X], t), bounds_local(a[Y], t));
double Coord
Definition: coord.h:45