1#ifndef UNITTESTS_COMMON_DUMMYTRAITS
2#define UNITTESTS_COMMON_DUMMYTRAITS
3#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
4#include <OpenMesh/Core/Utils/color_cast.hh>
11template <
int DIM>
class Vec {
14 Vec(
float x) : data({ x }) {}
15 Vec(
float x,
float y) : data({ x, y }) {}
16 Vec(
float x,
float y,
float z) : data({{ x, y, z }}) {}
17 Vec(
float x,
float y,
float z,
float w) : data({ x, y, z, w }) {}
22 float &operator[](
int i) {
return data[i]; }
23 float operator[](
int i)
const {
return data[i]; }
26 std::array<float, DIM> data;
29template <
int DIM>
bool operator==(
Vec<DIM> const &lhs,
Vec<DIM> const &rhs) {
30 for (
int i = 0; i < DIM; i++)
31 if (lhs[i] != rhs[i])
return false;
36Vec<DIM> operator+(Vec<DIM>
const &lhs, Vec<DIM>
const &rhs) {
38 for (
int i = 0; i < DIM; i++)
39 result[i] = lhs[i] + rhs[i];
44Vec<DIM> operator-(Vec<DIM>
const &lhs, Vec<DIM>
const &rhs) {
46 for (
int i = 0; i < DIM; i++)
47 result[i] = lhs[i] - rhs[i];
51template <
int DIM> Vec<DIM>
operator*(Vec<DIM>
const &lhs,
float rhs) {
53 for (
int i = 0; i < DIM; i++)
54 result[i] = lhs[i] * rhs;
58template <
int DIM> Vec<DIM>
operator*(
float lhs, Vec<DIM>
const &rhs) {
62template <
int DIM> Vec<DIM> operator/(Vec<DIM>
const &lhs,
float rhs) {
64 for (
int i = 0; i < DIM; i++)
65 result[i] = lhs[i] / rhs;
69template <
int DIM> Vec<DIM> &operator+=(Vec<DIM> &lhs, Vec<DIM>
const &rhs) {
70 return lhs = lhs + rhs;
72template <
int DIM> Vec<DIM> &operator-=(Vec<DIM> &lhs, Vec<DIM>
const &rhs) {
73 return lhs = lhs - rhs;
75template <
int DIM> Vec<DIM> &operator*=(Vec<DIM> &lhs,
float rhs) {
76 return lhs = lhs * rhs;
78template <
int DIM> Vec<DIM> &operator/=(Vec<DIM> &lhs,
float rhs) {
79 return lhs = lhs / rhs;
82template <
int DIM>
float norm(Vec<DIM>
const &v) {
84 for (
int i = 0; i < DIM; i++)
86 return std::sqrt(sum);
89template <
int DIM> Vec<DIM> &normalize(Vec<DIM> &v) {
return v /= norm(v); }
90template <
int DIM> Vec<DIM> &vectorize(Vec<DIM> &v,
float val) {
91 for (
int i = 0; i < DIM; i++)
96template <
int DIM> Vec<DIM> &minimize(Vec<DIM> &v1, Vec<DIM>
const &v2) {
97 for (
int i = 0; i < DIM; i++)
98 v1[i] = std::min(v1[i], v2[i]);
102template <
int DIM> Vec<DIM> &maximize(Vec<DIM> &v1, Vec<DIM>
const &v2) {
103 for (
int i = 0; i < DIM; i++)
104 v1[i] = std::max(v1[i], v2[i]);
108template <
int DIM>
float dot(Vec<DIM>
const &v1, Vec<DIM>
const &v2) {
110 for (
int i = 0; i < DIM; i++)
111 sum += v1[i] * v2[i];
115inline Vec<3> cross(Vec<3>
const &v1, Vec<3>
const &v2) {
116 return {v1[1] * v2[2] - v1[2] * v2[1],
117 v1[2] * v2[0] - v1[0] * v2[2],
118 v1[0] * v2[1] - v1[1] * v2[0]};
125 using value_type = float;
126 static const size_t size_ = DIM;
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
auto operator*(const OtherScalar &_s, const VectorT< Scalar, DIM > &rhs) -> decltype(rhs.operator*(_s))
Component wise multiplication from the left.
Definition: Vector11T.hh:693
Base class for all traits.
Definition: Traits.hh:122
Helper class providing information about a vector type.
Definition: vector_traits.hh:89
static const size_t size_
size/dimension of the vector
Definition: vector_traits.hh:97
static size_t size()
size/dimension of the vector
Definition: vector_traits.hh:100
Definition: unittests_common.hh:17
A Vector class with the absolute minimum of built-in methods to test the interface expected from Vect...
Definition: unittests_common_customtraits.hh:11