Itasca C++ Interface
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
dim.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "base/src/base.h"
4 namespace itasca {
5  class Accumulator3;
6  class Accumulator2;
7  class Accumulator;
8 }
9 
25 #ifndef DIM
26 # error DIM must be defined as 2 or 3 to compile this module.
27 #endif
28 
29 #if DIM==2
30  template <class T>
32  class Vector : public Vector2<T> {
33  public:
35  Vector() { }
37  Vector(const Vector<T> &v) : Vector2<T>(v) { }
39  Vector(const Vector2<T> &v) : Vector2<T>(v) { }
41  explicit Vector(const T &t) : Vector2<T>(t) { }
42  };
44  template <class T>
45  class AVector : public AVector2<T> {
46  public:
48  AVector() { }
50  AVector(const AVector &av) : AVector2<T>(av) { }
52  AVector(const AVector2<T> &av) : AVector2<T>(av) { }
53  };
55  template <class T>
56  class Extent : public Extent2<T> {
57  public:
59  Extent() { }
61  Extent(const Vector<T> &v11,const Vector<T> &v22) : Extent2<T>(v11,v22) { }
63  Extent(const Extent &r) : Extent2<T>(r) { }
64  Extent(const Extent2<T> &r) : Extent2<T>(r) { }
65  };
67  using DVect = DVect2;
68  using FVect = FVect2;
69  using IVect = IVect2;
70  using UVect = UVect2;
71  using DExtent = DExtent2;
72  using IExtent = IExtent2;
73  using DAVect = DAVect2;
74  using FAVect = FAVect2;
75  using Axes = Axes2D;
76  using CAxes = CAxes2D;
77  using Orientation = Orientation2;
78  using Quat = Quat2;
79  using VAccum = itasca::Accumulator2;
80  using AVAccum = itasca::Accumulator;
81 
82 # ifndef TWOD
83 # define TWOD
84 # endif
85 # define DIMSTR "2d"
86 # define CDIMSTR "2D"
87 # undef itascaxd
88 # define itascaxd itasca2d
89 # define DIMRET(x,y) x
90  template <class T> inline const Vector2<T> & toVect(const Vector2<T> &in) { return toVect2(in); }
91  template <class T> inline Vector<T> toVect(const Vector3<T> &in) { return toVect2(in); }
92  template <class T> inline Vector<T> toVect(const AVector2<T> &) { return Vector2<T>(0); }
93  template <class T> inline AVector<T> toAVect(const AVector2<T> &in) { return in; }
94  template <class T> inline AVector<T> toAVect(const AVector3<T> &in) { return AVector2<T>(in.z()); }
95  template <class T> inline AVector<T> toAVect(const Vector2<T> &) { return AVector2<T>(0.0); }
96  template <class T> inline AVector<T> toAVect(const Vector3<T> &in) { return AVector2<T>(in.z()); }
97  template <class T> inline const Extent<T> & toExtent(const Extent2<T> &t) { return t; }
98  template <class T> inline Extent<T> toExtent(const Extent3<T> &t) { return Extent2<T>(t.x1(),t.x2(),t.y1(),t.y2()); }
99  template <class T> inline IVect toIVect(const Vector2<T> &in) { IVect iv(to<Int>(in.x()),to<Int>(in.y())); return iv; }
100  template <class T> inline FVect toFVect(const Vector2<T> &in) { FVect fv(to<Float>(in.x()),to<Float>(in.y())); return fv; }
101  template <class T> inline DVect toDVect(const Vector2<T> &in) { DVect dv(to<Double>(in.x()),to<Double>(in.y())); return dv; }
102  template <class T> inline DVect toDVect(const Vector3<T> &in) { DVect dv(to<Double>(in.x()),to<Double>(in.y())); return dv; }
103  template <class T,class U> inline constexpr const T &dimval(const T &val2,const U &) { return val2; }
104  static const unsigned int totdof = 3;
105 #else // DIM==3
106  template <class T>
108  class Vector : public Vector3<T> {
109  public:
111  Vector() { }
113  Vector(const Vector<T> &v) : Vector3<T>(v) { }
115  Vector(const Vector3<T> &v) : Vector3<T>(v) { }
117  Vector(const T &x,const T &y,const T &z) : Vector3<T>(x,y,z) { }
119  explicit Vector(const T &t) : Vector3<T>(t) { }
120  };
122  template <class T>
123  class AVector : public AVector3<T> {
124  public:
126  AVector() { }
128  AVector(const AVector &av) : AVector3<T>(av) { }
130  AVector(const AVector3<T> &av) : AVector3<T>(av) { }
131  };
133  template <class T>
134  class Extent : public Extent3<T> {
135  public:
137  Extent() { }
139  Extent(const Vector<T> &v11,const Vector<T> &v22) : Extent3<T>(v11,v22) { }
141  Extent(const Extent &r) : Extent3<T>(r) { }
143  Extent(const Extent3<T> &r) : Extent3<T>(r) { }
144  };
145  using DVect = DVect3;
146  using FVect = FVect3;
147  using IVect = IVect3;
148  using UVect = UVect3;
149  using DExtent = DExtent3;
150  using IExtent = IExtent3;
151  using DAVect = DAVect3;
152  using FAVect = FAVect3;
153  using Axes = Axes3D;
154  using CAxes = CAxes3D;
156  using Quat = Quat3;
157  using VAccum = itasca::Accumulator3;
158  using AVAccum = itasca::Accumulator3;
159 # ifndef THREED
160 # define THREED
161 # endif
162 # define DIMSTR "3d"
163 # define CDIMSTR "3D"
164 # undef itascaxd
165 # define itascaxd itasca3d
166 # define DIMRET(x,y) y
167  template <class T> inline Vector3<T> toVect(const Vector2<T> &in) { return toVect3(in); }
168  template <class T> inline const Vector3<T> & toVect(const Vector3<T> &in) { return in; }
169  template <class T> inline Vector3<T> toVect(const AVector2<T> &in) { return Vector3<T>(0,0,in.z()); }
170  template <class T> inline AVector3<T> toAVect(const AVector2<T> &in) { return AVector3<T>(in); }
171  template <class T> inline const AVector3<T> &toAVect(const AVector3<T> &in) { return in; }
172  template <class T> inline AVector3<T> toAVect(const Vector2<T> &in) { return AVector3<T>(in.x(),in.y(),0.0); }
173  template <class T> inline AVector3<T> toAVect(const Vector3<T> &in) { return AVector3<T>(in.x(),in.y(),in.z()); }
174  template <class T> inline Extent<T> toExtent(const Extent2<T> &t) { return Extent3<T>(t.x1(),t.x2(),t.y1(),t.y2(),0,1); }
175  template <class T> inline Extent<T> toExtent(const Extent3<T> &t) { return t; }
176  template <class T> inline IVect toIVect(const Vector3<T> &in) { IVect iv(to<Int>(in.x()),to<Int>(in.y()),to<Int>(in.z())); return iv; }
177  template <class T> inline FVect toFVect(const Vector3<T> &in) { FVect fv(to<Float>(in.x()),to<Float>(in.y()),to<Float>(in.z())); return fv; }
178  template <class T> inline DVect toDVect(const Vector3<T> &in) { DVect dv(to<Double>(in.x()),to<Double>(in.y()),to<Double>(in.z())); return dv; }
179  template <class T,class U> inline constexpr const U &dimval(const T &,const U &val3) { return val3; }
180  static const unsigned int totdof = 6;
181 #endif // DIM==2
182 
183 static constexpr unsigned int dim = DIM;
184 static constexpr bool is2D = dimval(true,false);
185 static constexpr bool is3D = dimval(false,true);
186 
188 // EoF
Class for specifying a particular 2D cartesian axes system, and converting to and from it.
Definition: caxes.h:25
constexpr const U & dimval(const T &, const U &val3)
Returns the first argument in a 2D compile, and the second in a 3D compile.
Definition: dim.h:179
Vector2< Int > IVect2
Definition: vect.h:284
Class for specifying a particular 3D cartesian axes system, and converting to and from it.
Definition: caxes.h:103
AVector3< Double > DAVect3
Definition: avect.h:196
const T & x2() const
Returns the upper bound of the extent in the x-direction.
Definition: extent3.h:43
2D quaternion-like utility class. In this case only the angle (in radians) is stored as opposed to th...
Definition: quat.h:20
IVect toIVect(const Vector3< T > &in)
Converts a Vector3<T> to an IVect.
Definition: dim.h:176
namespace Itasca
Definition: basememory.cpp:9
IExtent3 IExtent
An IExtent2 in 2D, an IExtent3 in 3D.
Definition: dim.h:150
UVect3 UVect
Vector of uints, either 2D or 3D.
Definition: dim.h:148
itasca::Accumulator3 VAccum
3D vector accumulator
Definition: dim.h:157
Vector(const T &x, const T &y, const T &z)
From three.
Definition: dim.h:117
AVector2< Float > FAVect2
Definition: avect.h:192
Extent(const Extent &r)
Copy constructor.
Definition: dim.h:141
FVect toFVect(const Vector3< T > &in)
Converts a Vector3<T> to a FVect.
Definition: dim.h:177
AVector(const AVector &av)
Copy constructor.
Definition: dim.h:128
Class for specifying a particular 3D cartesian axes system, and converting to and from it.
Definition: axes.h:120
Extent()
Default constructor, not data initialization.
Definition: dim.h:137
Class for specifying a particular 2D cartesian axes system, and converting to and from it.
Definition: axes.h:20
Vector3< T > toVect(const Vector2< T > &in)
Converts a Vector2 to a Vector.
Definition: dim.h:167
Vector3< Float > FVect3
Definition: vect.h:290
AVector2< Double > DAVect2
Definition: avect.h:191
Class for storing an "orientation", or a direction in 2D or 3D space.
Definition: orientation.h:94
Extent< T > toExtent(const Extent2< T > &t)
Converts Extent2 to an Extent.
Definition: dim.h:174
Vector2< UInt > UVect2
Definition: vect.h:285
Extent2< Double > DExtent2
Definition: extent2.h:251
const T & y1() const
Returns the lower bound of the extent in the y-direction.
Definition: extent3.h:45
DExtent3 DExtent
A DExtent2 in 2D, a DExtent3 in 3D.
Definition: dim.h:149
const T & y() const
Y component access.
Definition: vect.h:56
FAVect3 FAVect
Angular vector of floats, either 2D or 3D.
Definition: dim.h:152
2D vector utility class.
Definition: vect.h:31
const T & z() const
The z-component of the vector.
Definition: vect.h:186
Extent(const Vector< T > &v11, const Vector< T > &v22)
Explicit constructor, given the lower and upper bound as two Vector.
Definition: dim.h:139
Extent3< Double > DExtent3
Definition: extent3.h:331
IVect3 IVect
Vector of ints, either 2D or 3D.
Definition: dim.h:147
FVect3 FVect
Vector of floats, either 2D or 3D.
Definition: dim.h:146
const T & x1() const
Returns the lower bound of the extent in the x-direction.
Definition: extent3.h:41
Vector(const Vector< T > &v)
Copy constructor.
Definition: dim.h:113
Vector3< UInt > UVect3
Definition: vect.h:292
DAVect3 DAVect
Angular vector of doubles, either 2D or 3D.
Definition: dim.h:151
itasca::Accumulator3 AVAccum
3D angular accumulator
Definition: dim.h:158
Vector(const Vector3< T > &v)
Copy constructor.
Definition: dim.h:115
Vector2< T > toVect2(const AVector2< T > &)
Definition: avect.h:245
An AVector2 in 2D, an AVector3 in 3D.
Definition: dim.h:123
2D cartesian region in space.
Definition: extent2.h:12
One stop include for all objects defined as part of base interface.
3D vector utility class.
Definition: vect.h:161
Extent(const Extent3< T > &r)
Copy constructor.
Definition: dim.h:143
DVect3 DVect
Vector of doubles, either 2D or 3D.
Definition: dim.h:145
AVector3< Float > FAVect3
Definition: avect.h:197
Class for storing an "orientation", or a direction in 2D or 3D space.
Definition: orientation.h:45
Vector3< Double > DVect3
Definition: vect.h:289
Vector3< Int > IVect3
Definition: vect.h:291
const T & x() const
X component access.
Definition: vect.h:54
Vector2< Double > DVect2
Definition: vect.h:282
Vector2< Float > FVect2
Definition: vect.h:283
A Vector2 in 2D, a Vector3 in 3D.
Definition: dim.h:108
2D Angular vector class.
Definition: avect.h:43
3D quaternion utility class.
Definition: quat.h:103
AVector(const AVector3< T > &av)
Copy constructor.
Definition: dim.h:130
Vector()
Default constructor, no data initialization.
Definition: dim.h:111
Vector(const T &t)
Single component constructor.
Definition: dim.h:119
DVect toDVect(const Vector3< T > &in)
Converts a Vector3<T> to a DVect.
Definition: dim.h:178
3D Angular vector class.
Definition: avect.h:176
Extent3< Int > IExtent3
Definition: extent3.h:333
A Extent2<T> in 2D, and a Extent3<T> in 2D.
Definition: dim.h:134
Extent2< Int > IExtent2
Definition: extent2.h:253
A Class representing a cartesian extent in 3D.
Definition: extent3.h:16
const T & y() const
The y-component of the vector.
Definition: vect.h:184
const T & x() const
The x-component of the vector.
Definition: vect.h:182
const T & y2() const
Returns the upper bound of the extent in the y-direction.
Definition: extent3.h:47
AVector3< T > toAVect(const AVector2< T > &in)
Converts an AVector2 to an AVector.
Definition: dim.h:170
AVector()
Default constructor, no data initialization.
Definition: dim.h:126