-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathDataStructs.h
84 lines (68 loc) · 1.27 KB
/
DataStructs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#pragma once
#include <cmath>
#include <vector>
#include <functional>
#include <array>
#include <boost/assert.hpp>
namespace MeshSdf
{
struct Vec3
{
double x, y, z;
void operator+=(Vec3 const& o)
{
x += o.x;
y += o.y;
z += o.z;
}
double Norm() const
{
return sqrt(x*x + y*y + z*z);
}
double NormSq() const
{
return x * x + y * y + z * z;
}
Vec3 Cross(Vec3 const& o) const
{
return {
y*o.z - z*o.y,
z*o.x - x*o.z,
x*o.y - y*o.x };
}
double Dot(Vec3 const& o) const
{
return x*o.x + y*o.y + z*o.z;
}
Vec3 Normalized() const
{
BOOST_ASSERT_MSG(Norm() > 0.0, "Cannot normalize zero vector");
auto n = Norm();
return { x / n, y / n, z / n };
}
};
inline Vec3 operator+(Vec3 const& a, Vec3 const& b)
{
return { a.x + b.x, a.y + b.y, a.z + b.z };
}
inline Vec3 operator-(Vec3 const& a, Vec3 const& b)
{
return { a.x - b.x, a.y - b.y, a.z - b.z };
}
inline Vec3 operator*(Vec3 const& v, double c)
{
return { c*v.x, c*v.y, c*v.z };
}
inline Vec3 operator*(double c, Vec3 const& v)
{
return v * c;
}
using Tri = std::array<int, 3>;
using Fun3s = std::function<double(Vec3 const&)>;
struct Mesh
{
std::vector<Vec3> verts;
std::vector<Tri> tris;
std::vector<Vec3> triNormals;
};
}