| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * \file | ||
| 3 | * \brief Template concepts used by 2Geom | ||
| 4 | *//* | ||
| 5 | * Copyright 2007 Michael Sloan <mgsloan@gmail.com> | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it either under the terms of the GNU Lesser General Public | ||
| 9 | * License version 2.1 as published by the Free Software Foundation | ||
| 10 | * (the "LGPL") or, at your option, under the terms of the Mozilla | ||
| 11 | * Public License Version 1.1 (the "MPL"). If you do not alter this | ||
| 12 | * notice, a recipient may use your version of this file under either | ||
| 13 | * the MPL or the LGPL. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the LGPL along with this library | ||
| 16 | * in the file COPYING-LGPL-2.1; if not, output to the Free Software | ||
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 18 | * You should have received a copy of the MPL along with this library | ||
| 19 | * in the file COPYING-MPL-1.1 | ||
| 20 | * | ||
| 21 | * The contents of this file are subject to the Mozilla Public License | ||
| 22 | * Version 1.1 (the "License"); you may not use this file except in | ||
| 23 | * compliance with the License. You may obtain a copy of the License at | ||
| 24 | * http://www.mozilla.org/MPL/ | ||
| 25 | * | ||
| 26 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY | ||
| 27 | * OF ANY KIND, either express or implied. See the LGPL or the MPL for | ||
| 28 | * the specific language governing rights and limitations. | ||
| 29 | */ | ||
| 30 | |||
| 31 | #ifndef LIB2GEOM_SEEN_CONCEPTS_H | ||
| 32 | #define LIB2GEOM_SEEN_CONCEPTS_H | ||
| 33 | |||
| 34 | #include <2geom/sbasis.h> | ||
| 35 | #include <2geom/interval.h> | ||
| 36 | #include <2geom/point.h> | ||
| 37 | #include <2geom/rect.h> | ||
| 38 | #include <2geom/intersection.h> | ||
| 39 | #include <vector> | ||
| 40 | #include <boost/concept/assert.hpp> | ||
| 41 | #include <2geom/forward.h> | ||
| 42 | #include <2geom/transforms.h> | ||
| 43 | |||
| 44 | namespace Geom { | ||
| 45 | |||
| 46 | //forward decls | ||
| 47 | template <typename T> struct ResultTraits; | ||
| 48 | |||
| 49 | template <> struct ResultTraits<double> { | ||
| 50 | typedef OptInterval bounds_type; | ||
| 51 | typedef SBasis sb_type; | ||
| 52 | }; | ||
| 53 | |||
| 54 | template <> struct ResultTraits<Point> { | ||
| 55 | typedef OptRect bounds_type; | ||
| 56 | typedef D2<SBasis> sb_type; | ||
| 57 | }; | ||
| 58 | |||
| 59 | //A concept for one-dimensional functions defined on [0,1] | ||
| 60 | template <typename T> | ||
| 61 | struct FragmentConcept { | ||
| 62 | typedef typename T::output_type OutputType; | ||
| 63 | typedef typename ResultTraits<OutputType>::bounds_type BoundsType; | ||
| 64 | typedef typename ResultTraits<OutputType>::sb_type SbType; | ||
| 65 | T t; | ||
| 66 | double d; | ||
| 67 | OutputType o; | ||
| 68 | bool b; | ||
| 69 | BoundsType i; | ||
| 70 | Interval dom; | ||
| 71 | std::vector<OutputType> v; | ||
| 72 | unsigned u; | ||
| 73 | SbType sb; | ||
| 74 | void constraints() { | ||
| 75 | t = T(o); | ||
| 76 | b = t.isZero(d); | ||
| 77 | b = t.isConstant(d); | ||
| 78 | b = t.isFinite(); | ||
| 79 | o = t.at0(); | ||
| 80 | o = t.at1(); | ||
| 81 | t.at0() = o; | ||
| 82 | t.at1() = o; | ||
| 83 | o = t.valueAt(d); | ||
| 84 | o = t(d); | ||
| 85 | v = t.valueAndDerivatives(d, u-1); | ||
| 86 | //Is a pure derivative (ignoring others) accessor ever much faster? | ||
| 87 | //u = number of values returned. first val is value. | ||
| 88 | sb = t.toSBasis(); | ||
| 89 | t = reverse(t); | ||
| 90 | i = bounds_fast(t); | ||
| 91 | i = bounds_exact(t); | ||
| 92 | i = bounds_local(t, dom); | ||
| 93 | /*With portion, Interval makes some sense, but instead I'm opting for | ||
| 94 | doubles, for the following reasons: | ||
| 95 | A) This way a reversed portion may be specified | ||
| 96 | B) Performance might be a bit better for piecewise and such | ||
| 97 | C) Interval version provided below | ||
| 98 | */ | ||
| 99 | t = portion(t, d, d); | ||
| 100 | } | ||
| 101 | }; | ||
| 102 | |||
| 103 | template <typename T> | ||
| 104 | struct ShapeConcept { | ||
| 105 | typedef typename ShapeTraits<T>::TimeType Time; | ||
| 106 | typedef typename ShapeTraits<T>::IntervalType Interval; | ||
| 107 | typedef typename ShapeTraits<T>::AffineClosureType AffineClosure; | ||
| 108 | typedef typename ShapeTraits<T>::IntersectionType Isect; | ||
| 109 | |||
| 110 | T shape, other; | ||
| 111 | Time t; | ||
| 112 | Point p; | ||
| 113 | AffineClosure ac; | ||
| 114 | Affine m; | ||
| 115 | Translate tr; | ||
| 116 | Coord c; | ||
| 117 | bool bool_; | ||
| 118 | std::vector<Isect> ivec; | ||
| 119 | |||
| 120 | void constraints() { | ||
| 121 | p = shape.pointAt(t); | ||
| 122 | c = shape.valueAt(t, X); | ||
| 123 | ivec = shape.intersect(other); | ||
| 124 | t = shape.nearestTime(p); | ||
| 125 | shape *= tr; | ||
| 126 | ac = shape; | ||
| 127 | ac *= m; | ||
| 128 | bool_ = (shape == shape); | ||
| 129 | bool_ = (shape != other); | ||
| 130 | bool_ = shape.isDegenerate(); | ||
| 131 | //bool_ = are_near(shape, other, c); | ||
| 132 | } | ||
| 133 | }; | ||
| 134 | |||
| 135 | template <typename T> | ||
| 136 | ✗ | inline T portion(const T& t, const Interval& i) { return portion(t, i.min(), i.max()); } | |
| 137 | |||
| 138 | template <typename T> | ||
| 139 | struct EqualityComparableConcept { | ||
| 140 | T a, b; | ||
| 141 | bool bool_; | ||
| 142 | void constraints() { | ||
| 143 | bool_ = (a == b); | ||
| 144 | bool_ = (a != b); | ||
| 145 | } | ||
| 146 | }; | ||
| 147 | |||
| 148 | template <typename T> | ||
| 149 | struct NearConcept { | ||
| 150 | T a, b; | ||
| 151 | double tol; | ||
| 152 | bool res; | ||
| 153 | void constraints() { | ||
| 154 | res = are_near(a, b, tol); | ||
| 155 | } | ||
| 156 | }; | ||
| 157 | |||
| 158 | template <typename T> | ||
| 159 | struct OffsetableConcept { | ||
| 160 | T t; | ||
| 161 | typename T::output_type d; | ||
| 162 | void constraints() { | ||
| 163 | t = t + d; t += d; | ||
| 164 | t = t - d; t -= d; | ||
| 165 | } | ||
| 166 | }; | ||
| 167 | |||
| 168 | template <typename T> | ||
| 169 | struct ScalableConcept { | ||
| 170 | T t; | ||
| 171 | typename T::output_type d; | ||
| 172 | void constraints() { | ||
| 173 | t = -t; | ||
| 174 | t = t * d; t *= d; | ||
| 175 | t = t / d; t /= d; | ||
| 176 | } | ||
| 177 | }; | ||
| 178 | |||
| 179 | template <typename T> | ||
| 180 | struct AddableConcept { | ||
| 181 | T i, j; | ||
| 182 | void constraints() { | ||
| 183 | i += j; i = i + j; | ||
| 184 | i -= j; i = i - j; | ||
| 185 | } | ||
| 186 | }; | ||
| 187 | |||
| 188 | template <typename T> | ||
| 189 | struct MultiplicableConcept { | ||
| 190 | T i, j; | ||
| 191 | void constraints() { | ||
| 192 | i *= j; i = i * j; | ||
| 193 | } | ||
| 194 | }; | ||
| 195 | |||
| 196 | } // end namespace Geom | ||
| 197 | |||
| 198 | #endif // LIB2GEOM_SEEN_CONCEPTS_H | ||
| 199 | |||
| 200 | /* | ||
| 201 | Local Variables: | ||
| 202 | mode:c++ | ||
| 203 | c-file-style:"stroustrup" | ||
| 204 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) | ||
| 205 | indent-tabs-mode:nil | ||
| 206 | fill-column:99 | ||
| 207 | End: | ||
| 208 | */ | ||
| 209 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : | ||
| 210 |