Vector types
EBGeometry implements its own 2D and 3D vector types, Vec2T and Vec3T. Like nearly every
other class in the library, both are templated on a floating-point precision T (float or
double), so a single header defines both precisions with no code duplication and no runtime
precision switch.
Vec2T is a two-dimensional Cartesian vector. Most of EBGeometry is written as
three-dimensional code, but Vec2T is needed where a computation is reduced to two dimensions:
for determining whether a point projects onto the interior or exterior of a planar DCEL polygon (see
Half-edge meshes (DCEL)), and in the cross-sections of a few analytic shapes. Its main
features are:
Element access through
operator[](indices 0, 1), plus a two-argument constructor.Named static factories for common vectors:
zeros(),ones(),min(),max(), andinfinity().The usual arithmetic operators (
+,-, unary-, scalar*//, and their in-place+=/-=/*=//=counterparts), plus a scalar-left multiplication and division as free functions, which take a scalar of any arithmetic type (2.0 * uwith aVec2T<float>u) and convert it toTfirst.dot,length, andlength2member functions, mirrored by free-function equivalents (dot,length) and free-function component-wisemin/max.lengthis notconstexpr, since it callsstd::sqrt.
Vec3T is a three-dimensional Cartesian vector, likewise templated on precision T. As in
Vec2T, its components are stored internally and reached only through operator[] (mutable
and const overloads), not as public named fields. Its main features are:
Element access through
operator[](indices 0, 1, 2), plus a three-argument constructor.Named static factories:
zeros(),ones(),unit(dir)(a basis vector along a given axis),min(),max(), andinfinity().The usual arithmetic operators, including both scalar and component-wise
*//, and their in-place counterparts, plus a scalar-left multiplication/division as free functions that take any arithmetic scalar, as forVec2T.crossanddotproducts, mirrored by free-function equivalents, plus free-function component-wisemin,max, andclamp.Equality
==/!=, and a lexicographiclessLXfor use in ordered containers. The ordering operators<,>,<=and>=are deleted: a component-wise comparison is not a strict weak ordering.minDir/maxDirto find the index of the smallest/largest component (optionally by magnitude), andlength/length2.A stream insertion operator (
operator<<) for printing, inSource/EBGeometry_StreamOperators.hpp(with those for the bounding volumes), so thatEBGeometry_Vec.hppdoes not include<ostream>.EBGeometry.hppincludes it.
Both types are trivially default constructible, like a plain T: Vec3T<T> v; leaves the
components uninitialized, while Vec3T<T> v{};, Vec3T<T>() and Vec3T<T>::zeros() give the
zero vector (and the same for Vec2T). A defaulted constructor is what lets either type be the
element type of a CUDA/HIP __shared__ array, which may not have an initializer.
For the full API – every constructor, operator, and free function – see the Doxygen reference for Vec2T and Vec3T.