Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r--source/blender/blenlib/intern/BLI_mempool_private.h5
-rw-r--r--source/blender/blenlib/intern/delaunay_2d.cc45
-rw-r--r--source/blender/blenlib/intern/math_boolean.cc7
-rw-r--r--source/blender/blenlib/intern/math_vec.cc133
-rw-r--r--source/blender/blenlib/intern/mesh_boolean.cc51
-rw-r--r--source/blender/blenlib/intern/mesh_intersect.cc88
-rw-r--r--source/blender/blenlib/intern/noise.cc79
7 files changed, 166 insertions, 242 deletions
diff --git a/source/blender/blenlib/intern/BLI_mempool_private.h b/source/blender/blenlib/intern/BLI_mempool_private.h
index 03b0b11297b..90569d87c41 100644
--- a/source/blender/blenlib/intern/BLI_mempool_private.h
+++ b/source/blender/blenlib/intern/BLI_mempool_private.h
@@ -54,9 +54,8 @@ typedef struct ParallelMempoolTaskData {
*
* See #BLI_task_parallel_mempool implementation for detailed usage example.
*/
-ParallelMempoolTaskData *mempool_iter_threadsafe_create(BLI_mempool *pool,
- size_t num_iter) ATTR_WARN_UNUSED_RESULT
- ATTR_NONNULL();
+ParallelMempoolTaskData *mempool_iter_threadsafe_create(BLI_mempool *pool, const size_t num_iter)
+ ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
void mempool_iter_threadsafe_destroy(ParallelMempoolTaskData *iter_arr) ATTR_NONNULL();
/**
diff --git a/source/blender/blenlib/intern/delaunay_2d.cc b/source/blender/blenlib/intern/delaunay_2d.cc
index 53e881a9fc7..842e6cb6135 100644
--- a/source/blender/blenlib/intern/delaunay_2d.cc
+++ b/source/blender/blenlib/intern/delaunay_2d.cc
@@ -25,11 +25,10 @@
#include <sstream>
#include "BLI_array.hh"
-#include "BLI_double2.hh"
#include "BLI_linklist.h"
#include "BLI_math_boolean.hh"
#include "BLI_math_mpq.hh"
-#include "BLI_mpq2.hh"
+#include "BLI_math_vec_mpq_types.hh"
#include "BLI_set.hh"
#include "BLI_task.hh"
#include "BLI_vector.hh"
@@ -38,6 +37,8 @@
namespace blender::meshintersect {
+using namespace blender::math;
+
/* Throughout this file, template argument T will be an
* arithmetic-like type, like float, double, or mpq_class. */
@@ -788,11 +789,11 @@ bool in_line<mpq_class>(const FatCo<mpq_class> &a,
}
vec2<mpq_class> exact_ab = b.exact - a.exact;
vec2<mpq_class> exact_ac = c.exact - a.exact;
- if (vec2<mpq_class>::dot(exact_ab, exact_ac) < 0) {
+ if (dot(exact_ab, exact_ac) < 0) {
return false;
}
vec2<mpq_class> exact_bc = c.exact - b.exact;
- return vec2<mpq_class>::dot(exact_bc, exact_ac) >= 0;
+ return dot(exact_bc, exact_ac) >= 0;
}
#endif
@@ -801,11 +802,11 @@ bool in_line<double>(const FatCo<double> &a, const FatCo<double> &b, const FatCo
{
vec2<double> ab = b.approx - a.approx;
vec2<double> ac = c.approx - a.approx;
- if (vec2<double>::dot(ab, ac) < 0) {
+ if (dot(ab, ac) < 0) {
return false;
}
vec2<double> bc = c.approx - b.approx;
- return vec2<double>::dot(bc, ac) >= 0;
+ return dot(bc, ac) >= 0;
}
template<> CDTVert<double>::CDTVert(const vec2<double> &pt)
@@ -1081,7 +1082,7 @@ template<typename T> CDTEdge<T> *CDTArrangement<T>::split_edge(SymEdge<T> *se, T
SymEdge<T> *sesymprev = prev(sesym);
SymEdge<T> *sesymprevsym = sym(sesymprev);
SymEdge<T> *senext = se->next;
- CDTVert<T> *v = this->add_vert(vec2<T>::interpolate(*a, *b, lambda));
+ CDTVert<T> *v = this->add_vert(interpolate(*a, *b, lambda));
CDTEdge<T> *e = this->add_edge(v, se->next->vert, se->face, sesym->face);
sesym->vert = v;
SymEdge<T> *newse = &e->symedges[0];
@@ -1704,16 +1705,16 @@ void fill_crossdata_for_intersect(const FatCo<T> &curco,
BLI_assert(se_vcva->vert == vc && se_vcva->next->vert == va);
BLI_assert(se_vcvb->vert == vc && se_vcvb->next->vert == vb);
UNUSED_VARS_NDEBUG(vc);
- auto isect = vec2<T>::isect_seg_seg(va->co.exact, vb->co.exact, curco.exact, v2->co.exact);
+ auto isect = isect_seg_seg<vec2<T>>(va->co.exact, vb->co.exact, curco.exact, v2->co.exact);
T &lambda = isect.lambda;
switch (isect.kind) {
- case vec2<T>::isect_result::LINE_LINE_CROSS: {
+ case isect_result<vec2<T>>::LINE_LINE_CROSS: {
#ifdef WITH_GMP
if (!std::is_same<T, mpq_class>::value) {
#else
if (true) {
#endif
- double len_ab = vec2<double>::distance(va->co.approx, vb->co.approx);
+ double len_ab = distance(va->co.approx, vb->co.approx);
if (lambda * len_ab <= epsilon) {
fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next);
}
@@ -1735,7 +1736,7 @@ void fill_crossdata_for_intersect(const FatCo<T> &curco,
}
break;
}
- case vec2<T>::isect_result::LINE_LINE_EXACT: {
+ case isect_result<vec2<T>>::LINE_LINE_EXACT: {
if (lambda == 0) {
fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next);
}
@@ -1750,7 +1751,7 @@ void fill_crossdata_for_intersect(const FatCo<T> &curco,
}
break;
}
- case vec2<T>::isect_result::LINE_LINE_NONE: {
+ case isect_result<vec2<T>>::LINE_LINE_NONE: {
#ifdef WITH_GMP
if (std::is_same<T, mpq_class>::value) {
BLI_assert(false);
@@ -1766,9 +1767,9 @@ void fill_crossdata_for_intersect(const FatCo<T> &curco,
}
break;
}
- case vec2<T>::isect_result::LINE_LINE_COLINEAR: {
- if (vec2<double>::distance_squared(va->co.approx, v2->co.approx) <=
- vec2<double>::distance_squared(vb->co.approx, v2->co.approx)) {
+ case isect_result<vec2<T>>::LINE_LINE_COLINEAR: {
+ if (distance_squared(va->co.approx, v2->co.approx) <=
+ distance_squared(vb->co.approx, v2->co.approx)) {
fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next);
}
else {
@@ -1845,7 +1846,7 @@ void get_next_crossing_from_edge(CrossData<T> *cd,
{
CDTVert<T> *va = cd->in->vert;
CDTVert<T> *vb = cd->in->next->vert;
- vec2<T> curco = vec2<T>::interpolate(va->co.exact, vb->co.exact, cd->lambda);
+ vec2<T> curco = interpolate(va->co.exact, vb->co.exact, cd->lambda);
FatCo<T> fat_curco(curco);
SymEdge<T> *se_ac = sym(cd->in)->next;
CDTVert<T> *vc = se_ac->next->vert;
@@ -2386,7 +2387,7 @@ template<typename T> void remove_non_constraint_edges_leave_valid_bmesh(CDT_stat
dissolvable_edges[i].e = e;
const vec2<double> &co1 = e->symedges[0].vert->co.approx;
const vec2<double> &co2 = e->symedges[1].vert->co.approx;
- dissolvable_edges[i].len_squared = vec2<double>::distance_squared(co1, co2);
+ dissolvable_edges[i].len_squared = distance_squared(co1, co2);
i++;
}
}
@@ -2569,18 +2570,18 @@ template<typename T> void detect_holes(CDT_state<T> *cdt_state)
if (e->symedges[0].face->visit_index == e->symedges[1].face->visit_index) {
continue; /* Don't count hits on edges between faces in same region. */
}
- auto isect = vec2<T>::isect_seg_seg(ray_end.exact,
+ auto isect = isect_seg_seg<vec2<T>>(ray_end.exact,
mid.exact,
e->symedges[0].vert->co.exact,
e->symedges[1].vert->co.exact);
switch (isect.kind) {
- case vec2<T>::isect_result::LINE_LINE_CROSS: {
+ case isect_result<vec2<T>>::LINE_LINE_CROSS: {
hits++;
break;
}
- case vec2<T>::isect_result::LINE_LINE_EXACT:
- case vec2<T>::isect_result::LINE_LINE_NONE:
- case vec2<T>::isect_result::LINE_LINE_COLINEAR:
+ case isect_result<vec2<T>>::LINE_LINE_EXACT:
+ case isect_result<vec2<T>>::LINE_LINE_NONE:
+ case isect_result<vec2<T>>::LINE_LINE_COLINEAR:
break;
}
}
diff --git a/source/blender/blenlib/intern/math_boolean.cc b/source/blender/blenlib/intern/math_boolean.cc
index c16755868aa..0bae3c23f79 100644
--- a/source/blender/blenlib/intern/math_boolean.cc
+++ b/source/blender/blenlib/intern/math_boolean.cc
@@ -18,15 +18,10 @@
* \ingroup bli
*/
-#include "BLI_double2.hh"
-#include "BLI_double3.hh"
-#include "BLI_float2.hh"
-#include "BLI_float3.hh"
#include "BLI_hash.hh"
#include "BLI_math_boolean.hh"
#include "BLI_math_mpq.hh"
-#include "BLI_mpq2.hh"
-#include "BLI_mpq3.hh"
+#include "BLI_math_vec_types.hh"
#include "BLI_span.hh"
#include "BLI_utildefines.h"
diff --git a/source/blender/blenlib/intern/math_vec.cc b/source/blender/blenlib/intern/math_vec.cc
index 223c0e273f0..6fab6c9a383 100644
--- a/source/blender/blenlib/intern/math_vec.cc
+++ b/source/blender/blenlib/intern/math_vec.cc
@@ -18,89 +18,83 @@
* \ingroup bli
*/
-#include "BLI_double2.hh"
-#include "BLI_double3.hh"
-#include "BLI_float2.hh"
-#include "BLI_float3.hh"
#include "BLI_hash.hh"
-#include "BLI_math_mpq.hh"
-#include "BLI_mpq2.hh"
-#include "BLI_mpq3.hh"
+#include "BLI_math_vec_mpq_types.hh"
+#include "BLI_math_vector.hh"
#include "BLI_span.hh"
#include "BLI_utildefines.h"
-namespace blender {
+namespace blender::math {
-float2::isect_result float2::isect_seg_seg(const float2 &v1,
- const float2 &v2,
- const float2 &v3,
- const float2 &v4)
+template<>
+isect_result<float2> isect_seg_seg(const float2 &v1,
+ const float2 &v2,
+ const float2 &v3,
+ const float2 &v4)
{
- float2::isect_result ans;
+ isect_result<float2> ans;
float div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]);
if (div == 0.0f) {
ans.lambda = 0.0f;
- ans.mu = 0.0f;
- ans.kind = float2::isect_result::LINE_LINE_COLINEAR;
+ ans.kind = isect_result<float2>::LINE_LINE_COLINEAR;
}
else {
ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div;
- ans.mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div;
- if (ans.lambda >= 0.0f && ans.lambda <= 1.0f && ans.mu >= 0.0f && ans.mu <= 1.0f) {
- if (ans.lambda == 0.0f || ans.lambda == 1.0f || ans.mu == 0.0f || ans.mu == 1.0f) {
- ans.kind = float2::isect_result::LINE_LINE_EXACT;
+ float mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div;
+ if (ans.lambda >= 0.0f && ans.lambda <= 1.0f && mu >= 0.0f && mu <= 1.0f) {
+ if (ans.lambda == 0.0f || ans.lambda == 1.0f || mu == 0.0f || mu == 1.0f) {
+ ans.kind = isect_result<float2>::LINE_LINE_EXACT;
}
else {
- ans.kind = float2::isect_result::LINE_LINE_CROSS;
+ ans.kind = isect_result<float2>::LINE_LINE_CROSS;
}
}
else {
- ans.kind = float2::isect_result::LINE_LINE_NONE;
+ ans.kind = isect_result<float2>::LINE_LINE_NONE;
}
}
return ans;
}
-double2::isect_result double2::isect_seg_seg(const double2 &v1,
- const double2 &v2,
- const double2 &v3,
- const double2 &v4)
+template<>
+isect_result<double2> isect_seg_seg(const double2 &v1,
+ const double2 &v2,
+ const double2 &v3,
+ const double2 &v4)
{
- double2::isect_result ans;
+ isect_result<double2> ans;
double div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]);
if (div == 0.0) {
ans.lambda = 0.0;
- ans.kind = double2::isect_result::LINE_LINE_COLINEAR;
+ ans.kind = isect_result<double2>::LINE_LINE_COLINEAR;
}
else {
ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div;
double mu = ((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div;
if (ans.lambda >= 0.0 && ans.lambda <= 1.0 && mu >= 0.0 && mu <= 1.0) {
if (ans.lambda == 0.0 || ans.lambda == 1.0 || mu == 0.0 || mu == 1.0) {
- ans.kind = double2::isect_result::LINE_LINE_EXACT;
+ ans.kind = isect_result<double2>::LINE_LINE_EXACT;
}
else {
- ans.kind = double2::isect_result::LINE_LINE_CROSS;
+ ans.kind = isect_result<double2>::LINE_LINE_CROSS;
}
}
else {
- ans.kind = double2::isect_result::LINE_LINE_NONE;
+ ans.kind = isect_result<double2>::LINE_LINE_NONE;
}
}
return ans;
}
#ifdef WITH_GMP
-mpq2::isect_result mpq2::isect_seg_seg(const mpq2 &v1,
- const mpq2 &v2,
- const mpq2 &v3,
- const mpq2 &v4)
+template<>
+isect_result<mpq2> isect_seg_seg(const mpq2 &v1, const mpq2 &v2, const mpq2 &v3, const mpq2 &v4)
{
- mpq2::isect_result ans;
+ isect_result<mpq2> ans;
mpq_class div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]);
if (div == 0.0) {
ans.lambda = 0.0;
- ans.kind = mpq2::isect_result::LINE_LINE_COLINEAR;
+ ans.kind = isect_result<mpq2>::LINE_LINE_COLINEAR;
}
else {
ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div;
@@ -109,66 +103,21 @@ mpq2::isect_result mpq2::isect_seg_seg(const mpq2 &v1,
if (ans.lambda >= 0 && ans.lambda <= 1 &&
((div > 0 && mudiv >= 0 && mudiv <= div) || (div < 0 && mudiv <= 0 && mudiv >= div))) {
if (ans.lambda == 0 || ans.lambda == 1 || mudiv == 0 || mudiv == div) {
- ans.kind = mpq2::isect_result::LINE_LINE_EXACT;
+ ans.kind = isect_result<mpq2>::LINE_LINE_EXACT;
}
else {
- ans.kind = mpq2::isect_result::LINE_LINE_CROSS;
+ ans.kind = isect_result<mpq2>::LINE_LINE_CROSS;
}
}
else {
- ans.kind = mpq2::isect_result::LINE_LINE_NONE;
+ ans.kind = isect_result<mpq2>::LINE_LINE_NONE;
}
}
return ans;
}
#endif
-double3 double3::cross_poly(Span<double3> poly)
-{
- /* Newell's Method. */
- int nv = static_cast<int>(poly.size());
- if (nv < 3) {
- return double3(0, 0, 0);
- }
- const double3 *v_prev = &poly[nv - 1];
- const double3 *v_curr = &poly[0];
- double3 n(0, 0, 0);
- for (int i = 0; i < nv;) {
- n[0] = n[0] + ((*v_prev)[1] - (*v_curr)[1]) * ((*v_prev)[2] + (*v_curr)[2]);
- n[1] = n[1] + ((*v_prev)[2] - (*v_curr)[2]) * ((*v_prev)[0] + (*v_curr)[0]);
- n[2] = n[2] + ((*v_prev)[0] - (*v_curr)[0]) * ((*v_prev)[1] + (*v_curr)[1]);
- v_prev = v_curr;
- ++i;
- if (i < nv) {
- v_curr = &poly[i];
- }
- }
- return n;
-}
-
#ifdef WITH_GMP
-mpq3 mpq3::cross_poly(Span<mpq3> poly)
-{
- /* Newell's Method. */
- int nv = static_cast<int>(poly.size());
- if (nv < 3) {
- return mpq3(0);
- }
- const mpq3 *v_prev = &poly[nv - 1];
- const mpq3 *v_curr = &poly[0];
- mpq3 n(0);
- for (int i = 0; i < nv;) {
- n[0] = n[0] + ((*v_prev)[1] - (*v_curr)[1]) * ((*v_prev)[2] + (*v_curr)[2]);
- n[1] = n[1] + ((*v_prev)[2] - (*v_curr)[2]) * ((*v_prev)[0] + (*v_curr)[0]);
- n[2] = n[2] + ((*v_prev)[0] - (*v_curr)[0]) * ((*v_prev)[1] + (*v_curr)[1]);
- v_prev = v_curr;
- ++i;
- if (i < nv) {
- v_curr = &poly[i];
- }
- }
- return n;
-}
uint64_t hash_mpq_class(const mpq_class &value)
{
@@ -176,20 +125,6 @@ uint64_t hash_mpq_class(const mpq_class &value)
return get_default_hash(static_cast<float>(value.get_d()));
}
-uint64_t mpq2::hash() const
-{
- uint64_t hashx = hash_mpq_class(this->x);
- uint64_t hashy = hash_mpq_class(this->y);
- return hashx ^ (hashy * 33);
-}
-
-uint64_t mpq3::hash() const
-{
- uint64_t hashx = hash_mpq_class(this->x);
- uint64_t hashy = hash_mpq_class(this->y);
- uint64_t hashz = hash_mpq_class(this->z);
- return hashx ^ (hashy * 33) ^ (hashz * 33 * 37);
-}
#endif
-} // namespace blender
+} // namespace blender::math
diff --git a/source/blender/blenlib/intern/mesh_boolean.cc b/source/blender/blenlib/intern/mesh_boolean.cc
index ce4db0c6b9d..a3eae1896d3 100644
--- a/source/blender/blenlib/intern/mesh_boolean.cc
+++ b/source/blender/blenlib/intern/mesh_boolean.cc
@@ -28,8 +28,6 @@
# include "BLI_array.hh"
# include "BLI_assert.h"
# include "BLI_delaunay_2d.h"
-# include "BLI_double3.hh"
-# include "BLI_float3.hh"
# include "BLI_hash.hh"
# include "BLI_kdopbvh.h"
# include "BLI_map.hh"
@@ -37,8 +35,9 @@
# include "BLI_math_boolean.hh"
# include "BLI_math_geom.h"
# include "BLI_math_mpq.hh"
+# include "BLI_math_vec_mpq_types.hh"
+# include "BLI_math_vec_types.hh"
# include "BLI_mesh_intersect.hh"
-# include "BLI_mpq3.hh"
# include "BLI_set.hh"
# include "BLI_span.hh"
# include "BLI_stack.hh"
@@ -1633,13 +1632,13 @@ static Edge find_good_sorting_edge(const Vert *testp,
ordinate[axis_next] = -abscissa[axis];
ordinate[axis_next_next] = 0;
/* By construction, dot(abscissa, ordinate) == 0, so they are perpendicular. */
- mpq3 normal = mpq3::cross(abscissa, ordinate);
+ mpq3 normal = math::cross(abscissa, ordinate);
if (dbg_level > 0) {
std::cout << "abscissa = " << abscissa << "\n";
std::cout << "ordinate = " << ordinate << "\n";
std::cout << "normal = " << normal << "\n";
}
- mpq_class nlen2 = normal.length_squared();
+ mpq_class nlen2 = math::length_squared(normal);
mpq_class max_abs_slope = -1;
Edge esort;
const Vector<Edge> &edges = tmtopo.vert_edges(closestp);
@@ -1648,12 +1647,12 @@ static Edge find_good_sorting_edge(const Vert *testp,
const mpq3 &co_other = v_other->co_exact;
mpq3 evec = co_other - co_closest;
/* Get projection of evec onto plane of abscissa and ordinate. */
- mpq3 proj_evec = evec - (mpq3::dot(evec, normal) / nlen2) * normal;
+ mpq3 proj_evec = evec - (math::dot(evec, normal) / nlen2) * normal;
/* The projection calculations along the abscissa and ordinate should
* be scaled by 1/abscissa and 1/ordinate respectively,
* but we can skip: it won't affect which `evec` has the maximum slope. */
- mpq_class evec_a = mpq3::dot(proj_evec, abscissa);
- mpq_class evec_o = mpq3::dot(proj_evec, ordinate);
+ mpq_class evec_a = math::dot(proj_evec, abscissa);
+ mpq_class evec_o = math::dot(proj_evec, ordinate);
if (dbg_level > 0) {
std::cout << "e = " << e << "\n";
std::cout << "v_other = " << v_other << "\n";
@@ -1791,8 +1790,8 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p,
ap = p;
ap -= a;
- mpq_class d1 = mpq3::dot_with_buffer(ab, ap, m);
- mpq_class d2 = mpq3::dot_with_buffer(ac, ap, m);
+ mpq_class d1 = math::dot_with_buffer(ab, ap, m);
+ mpq_class d2 = math::dot_with_buffer(ac, ap, m);
if (d1 <= 0 && d2 <= 0) {
/* Barycentric coordinates (1,0,0). */
*r_edge = -1;
@@ -1800,13 +1799,13 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p,
if (dbg_level > 0) {
std::cout << " answer = a\n";
}
- return mpq3::distance_squared_with_buffer(p, a, m);
+ return math::distance_squared_with_buffer(p, a, m);
}
/* Check if p in vertex region outside b. */
bp = p;
bp -= b;
- mpq_class d3 = mpq3::dot_with_buffer(ab, bp, m);
- mpq_class d4 = mpq3::dot_with_buffer(ac, bp, m);
+ mpq_class d3 = math::dot_with_buffer(ab, bp, m);
+ mpq_class d4 = math::dot_with_buffer(ac, bp, m);
if (d3 >= 0 && d4 <= d3) {
/* Barycentric coordinates (0,1,0). */
*r_edge = -1;
@@ -1814,7 +1813,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p,
if (dbg_level > 0) {
std::cout << " answer = b\n";
}
- return mpq3::distance_squared_with_buffer(p, b, m);
+ return math::distance_squared_with_buffer(p, b, m);
}
/* Check if p in region of ab. */
mpq_class vc = d1 * d4 - d3 * d2;
@@ -1829,13 +1828,13 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p,
if (dbg_level > 0) {
std::cout << " answer = on ab at " << r << "\n";
}
- return mpq3::distance_squared_with_buffer(p, r, m);
+ return math::distance_squared_with_buffer(p, r, m);
}
/* Check if p in vertex region outside c. */
cp = p;
cp -= c;
- mpq_class d5 = mpq3::dot_with_buffer(ab, cp, m);
- mpq_class d6 = mpq3::dot_with_buffer(ac, cp, m);
+ mpq_class d5 = math::dot_with_buffer(ab, cp, m);
+ mpq_class d6 = math::dot_with_buffer(ac, cp, m);
if (d6 >= 0 && d5 <= d6) {
/* Barycentric coordinates (0,0,1). */
*r_edge = -1;
@@ -1843,7 +1842,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p,
if (dbg_level > 0) {
std::cout << " answer = c\n";
}
- return mpq3::distance_squared_with_buffer(p, c, m);
+ return math::distance_squared_with_buffer(p, c, m);
}
/* Check if p in edge region of ac. */
mpq_class vb = d5 * d2 - d1 * d6;
@@ -1858,7 +1857,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p,
if (dbg_level > 0) {
std::cout << " answer = on ac at " << r << "\n";
}
- return mpq3::distance_squared_with_buffer(p, r, m);
+ return math::distance_squared_with_buffer(p, r, m);
}
/* Check if p in edge region of bc. */
mpq_class va = d3 * d6 - d5 * d4;
@@ -1874,7 +1873,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p,
if (dbg_level > 0) {
std::cout << " answer = on bc at " << r << "\n";
}
- return mpq3::distance_squared_with_buffer(p, r, m);
+ return math::distance_squared_with_buffer(p, r, m);
}
/* p inside face region. Compute barycentric coordinates (u,v,w). */
mpq_class denom = 1 / (va + vb + vc);
@@ -1890,7 +1889,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p,
if (dbg_level > 0) {
std::cout << " answer = inside at " << r << "\n";
}
- return mpq3::distance_squared_with_buffer(p, r, m);
+ return math::distance_squared_with_buffer(p, r, m);
}
static float closest_on_tri_to_point_float_dist_squared(const float3 &p,
@@ -2610,7 +2609,7 @@ static void test_tri_inside_shapes(const IMesh &tm,
double3 test_point = calc_point_inside_tri_db(tri_test);
/* Offset the test point a tiny bit in the tri_test normal direction. */
tri_test.populate_plane(false);
- double3 norm = tri_test.plane->norm.normalized();
+ double3 norm = math::normalize(tri_test.plane->norm);
const double offset_amount = 1e-5;
double3 offset_test_point = test_point + offset_amount * norm;
if (dbg_level > 0) {
@@ -3002,7 +3001,7 @@ static void init_face_merge_state(FaceMergeState *fms,
std::cout << "process tri = " << &tri << "\n";
}
BLI_assert(tri.plane_populated());
- if (double3::dot(norm, tri.plane->norm) <= 0.0) {
+ if (math::dot(norm, tri.plane->norm) <= 0.0) {
if (dbg_level > 0) {
std::cout << "triangle has wrong orientation, skipping\n";
}
@@ -3027,7 +3026,7 @@ static void init_face_merge_state(FaceMergeState *fms,
}
if (me_index == -1) {
double3 vec = new_me.v2->co - new_me.v1->co;
- new_me.len_squared = vec.length_squared();
+ new_me.len_squared = math::length_squared(vec);
new_me.orig = tri.edge_orig[i];
new_me.is_intersect = tri.is_intersect[i];
new_me.dissolvable = (new_me.orig == NO_INDEX && !new_me.is_intersect);
@@ -3267,7 +3266,7 @@ static Vector<Face *> merge_tris_for_face(Vector<int> tris,
bool done = false;
double3 first_tri_normal = tm.face(tris[0])->plane->norm;
double3 second_tri_normal = tm.face(tris[1])->plane->norm;
- if (tris.size() == 2 && double3::dot(first_tri_normal, second_tri_normal) > 0.0) {
+ if (tris.size() == 2 && math::dot(first_tri_normal, second_tri_normal) > 0.0) {
/* Is this a case where quad with one diagonal remained unchanged?
* Worth special handling because this case will be very common. */
Face &tri1 = *tm.face(tris[0]);
@@ -3332,7 +3331,7 @@ static bool approx_in_line(const double3 &a, const double3 &b, const double3 &c)
{
double3 vec1 = b - a;
double3 vec2 = c - b;
- double cos_ang = double3::dot(vec1.normalized(), vec2.normalized());
+ double cos_ang = math::dot(math::normalize(vec1), math::normalize(vec2));
return fabs(cos_ang - 1.0) < 1e-4;
}
diff --git a/source/blender/blenlib/intern/mesh_intersect.cc b/source/blender/blenlib/intern/mesh_intersect.cc
index 1f150137ba3..982759ffcff 100644
--- a/source/blender/blenlib/intern/mesh_intersect.cc
+++ b/source/blender/blenlib/intern/mesh_intersect.cc
@@ -30,15 +30,13 @@
# include "BLI_array.hh"
# include "BLI_assert.h"
# include "BLI_delaunay_2d.h"
-# include "BLI_double3.hh"
-# include "BLI_float3.hh"
# include "BLI_hash.hh"
# include "BLI_kdopbvh.h"
# include "BLI_map.hh"
# include "BLI_math_boolean.hh"
# include "BLI_math_mpq.hh"
-# include "BLI_mpq2.hh"
-# include "BLI_mpq3.hh"
+# include "BLI_math_vec_mpq_types.hh"
+# include "BLI_math_vec_types.hh"
# include "BLI_polyfill_2d.h"
# include "BLI_set.hh"
# include "BLI_span.hh"
@@ -198,14 +196,14 @@ void Face::populate_plane(bool need_exact)
for (int i : index_range()) {
co[i] = vert[i]->co_exact;
}
- normal_exact = mpq3::cross_poly(co);
+ normal_exact = math::cross_poly(co.as_span());
}
else {
mpq3 tr02 = vert[0]->co_exact - vert[2]->co_exact;
mpq3 tr12 = vert[1]->co_exact - vert[2]->co_exact;
- normal_exact = mpq3::cross(tr02, tr12);
+ normal_exact = math::cross(tr02, tr12);
}
- mpq_class d_exact = -mpq3::dot(normal_exact, vert[0]->co_exact);
+ mpq_class d_exact = -math::dot(normal_exact, vert[0]->co_exact);
plane = new Plane(normal_exact, d_exact);
}
else {
@@ -215,14 +213,14 @@ void Face::populate_plane(bool need_exact)
for (int i : index_range()) {
co[i] = vert[i]->co;
}
- normal = double3::cross_poly(co);
+ normal = math::cross_poly(co.as_span());
}
else {
double3 tr02 = vert[0]->co - vert[2]->co;
double3 tr12 = vert[1]->co - vert[2]->co;
- normal = double3::cross_high_precision(tr02, tr12);
+ normal = math::cross(tr02, tr12);
}
- double d = -double3::dot(normal, vert[0]->co);
+ double d = -math::dot(normal, vert[0]->co);
plane = new Plane(normal, d);
}
}
@@ -1098,15 +1096,15 @@ static mpq2 project_3d_to_2d(const mpq3 &p3d, int proj_axis)
*/
static double supremum_dot_cross(const double3 &a, const double3 &b)
{
- double3 abs_a = double3::abs(a);
- double3 abs_b = double3::abs(b);
+ double3 abs_a = math::abs(a);
+ double3 abs_b = math::abs(b);
double3 c;
/* This is dot(cross(a, b), cross(a,b)) but using absolute values for a and b
* and always using + when operation is + or -. */
c[0] = abs_a[1] * abs_b[2] + abs_a[2] * abs_b[1];
c[1] = abs_a[2] * abs_b[0] + abs_a[0] * abs_b[2];
c[2] = abs_a[0] * abs_b[1] + abs_a[1] * abs_b[0];
- return double3::dot(c, c);
+ return math::dot(c, c);
}
/* The index of dot when inputs are plane_coords with index 1 is much higher.
@@ -1143,11 +1141,11 @@ static int filter_plane_side(const double3 &p,
const double3 &abs_plane_p,
const double3 &abs_plane_no)
{
- double d = double3::dot(p - plane_p, plane_no);
+ double d = math::dot(p - plane_p, plane_no);
if (d == 0.0) {
return 0;
}
- double supremum = double3::dot(abs_p + abs_plane_p, abs_plane_no);
+ double supremum = math::dot(abs_p + abs_plane_p, abs_plane_no);
double err_bound = supremum * index_plane_side * DBL_EPSILON;
if (fabs(d) > err_bound) {
return d > 0 ? 1 : -1;
@@ -1178,9 +1176,9 @@ static inline mpq3 tti_interp(
ab -= b;
ac = a;
ac -= c;
- mpq_class den = mpq3::dot_with_buffer(ab, n, dotbuf);
+ mpq_class den = math::dot_with_buffer(ab, n, dotbuf);
BLI_assert(den != 0);
- mpq_class alpha = mpq3::dot_with_buffer(ac, n, dotbuf) / den;
+ mpq_class alpha = math::dot_with_buffer(ac, n, dotbuf) / den;
return a - alpha * ab;
}
@@ -1209,7 +1207,7 @@ static inline int tti_above(const mpq3 &a,
n.y = ba.z * ca.x - ba.x * ca.z;
n.z = ba.x * ca.y - ba.y * ca.x;
- return sgn(mpq3::dot_with_buffer(ad, n, dotbuf));
+ return sgn(math::dot_with_buffer(ad, n, dotbuf));
}
/**
@@ -1428,11 +1426,11 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2)
const double3 &d_r2 = vr2->co;
const double3 &d_n2 = tri2.plane->norm;
- const double3 &abs_d_p1 = double3::abs(d_p1);
- const double3 &abs_d_q1 = double3::abs(d_q1);
- const double3 &abs_d_r1 = double3::abs(d_r1);
- const double3 &abs_d_r2 = double3::abs(d_r2);
- const double3 &abs_d_n2 = double3::abs(d_n2);
+ const double3 &abs_d_p1 = math::abs(d_p1);
+ const double3 &abs_d_q1 = math::abs(d_q1);
+ const double3 &abs_d_r1 = math::abs(d_r1);
+ const double3 &abs_d_r2 = math::abs(d_r2);
+ const double3 &abs_d_n2 = math::abs(d_n2);
int sp1 = filter_plane_side(d_p1, d_r2, d_n2, abs_d_p1, abs_d_r2, abs_d_n2);
int sq1 = filter_plane_side(d_q1, d_r2, d_n2, abs_d_q1, abs_d_r2, abs_d_n2);
@@ -1448,9 +1446,9 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2)
}
const double3 &d_n1 = tri1.plane->norm;
- const double3 &abs_d_p2 = double3::abs(d_p2);
- const double3 &abs_d_q2 = double3::abs(d_q2);
- const double3 &abs_d_n1 = double3::abs(d_n1);
+ const double3 &abs_d_p2 = math::abs(d_p2);
+ const double3 &abs_d_q2 = math::abs(d_q2);
+ const double3 &abs_d_n1 = math::abs(d_n1);
int sp2 = filter_plane_side(d_p2, d_r1, d_n1, abs_d_p2, abs_d_r1, abs_d_n1);
int sq2 = filter_plane_side(d_q2, d_r1, d_n1, abs_d_q2, abs_d_r1, abs_d_n1);
@@ -1477,17 +1475,17 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2)
if (sp1 == 0) {
buf[0] = p1;
buf[0] -= r2;
- sp1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1]));
+ sp1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1]));
}
if (sq1 == 0) {
buf[0] = q1;
buf[0] -= r2;
- sq1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1]));
+ sq1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1]));
}
if (sr1 == 0) {
buf[0] = r1;
buf[0] -= r2;
- sr1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1]));
+ sr1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1]));
}
if (dbg_level > 1) {
@@ -1509,17 +1507,17 @@ static ITT_value intersect_tri_tri(const IMesh &tm, int t1, int t2)
if (sp2 == 0) {
buf[0] = p2;
buf[0] -= r1;
- sp2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1]));
+ sp2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1]));
}
if (sq2 == 0) {
buf[0] = q2;
buf[0] -= r1;
- sq2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1]));
+ sq2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1]));
}
if (sr2 == 0) {
buf[0] = r2;
buf[0] -= r1;
- sr2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1]));
+ sr2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1]));
}
if (dbg_level > 1) {
@@ -1721,7 +1719,7 @@ static CDT_data prepare_cdt_input(const IMesh &tm, int t, const Vector<ITT_value
BLI_assert(tm.face(t)->plane_populated());
ans.t_plane = tm.face(t)->plane;
BLI_assert(ans.t_plane->exact_populated());
- ans.proj_axis = mpq3::dominant_axis(ans.t_plane->norm_exact);
+ ans.proj_axis = math::dominant_axis(ans.t_plane->norm_exact);
prepare_need_tri(ans, tm, t);
for (const ITT_value &itt : itts) {
switch (itt.kind) {
@@ -1757,7 +1755,7 @@ static CDT_data prepare_cdt_input_for_cluster(const IMesh &tm,
BLI_assert(tm.face(t0)->plane_populated());
ans.t_plane = tm.face(t0)->plane;
BLI_assert(ans.t_plane->exact_populated());
- ans.proj_axis = mpq3::dominant_axis(ans.t_plane->norm_exact);
+ ans.proj_axis = math::dominant_axis(ans.t_plane->norm_exact);
for (const int t : cl) {
prepare_need_tri(ans, tm, t);
}
@@ -2004,9 +2002,9 @@ static bool is_quad_flip_first_third(const double3 &v1,
const double3 &normal)
{
double3 dir_v3v1 = v3 - v1;
- double3 tangent = double3::cross_high_precision(dir_v3v1, normal);
- double dot = double3::dot(v1, tangent);
- return (double3::dot(v4, tangent) >= dot) || (double3::dot(v2, tangent) <= dot);
+ double3 tangent = math::cross(dir_v3v1, normal);
+ double dot = math::dot(v1, tangent);
+ return (math::dot(v4, tangent) >= dot) || (math::dot(v2, tangent) <= dot);
}
/**
@@ -2124,7 +2122,7 @@ static Array<Face *> exact_triangulate_poly(Face *f, IMeshArena *arena)
f->populate_plane(false);
}
const double3 &poly_normal = f->plane->norm;
- int axis = double3::dominant_axis(poly_normal);
+ int axis = math::dominant_axis(poly_normal);
/* If project down y axis as opposed to x or z, the orientation
* of the polygon will be reversed.
* Yet another reversal happens if the poly normal in the dominant
@@ -2203,15 +2201,15 @@ static bool face_is_degenerate(const Face *f)
}
double3 da = v2->co - v0->co;
double3 db = v2->co - v1->co;
- double3 dab = double3::cross_high_precision(da, db);
- double dab_length_squared = dab.length_squared();
+ double3 dab = math::cross(da, db);
+ double dab_length_squared = math::length_squared(dab);
double err_bound = supremum_dot_cross(dab, dab) * index_dot_cross * DBL_EPSILON;
if (dab_length_squared > err_bound) {
return false;
}
mpq3 a = v2->co_exact - v0->co_exact;
mpq3 b = v2->co_exact - v1->co_exact;
- mpq3 ab = mpq3::cross(a, b);
+ mpq3 ab = math::cross(a, b);
if (ab.x == 0 && ab.y == 0 && ab.z == 0) {
return true;
}
@@ -2231,8 +2229,8 @@ static bool any_degenerate_tris_fast(const Array<Face *> triangulation)
}
double3 da = v2->co - v0->co;
double3 db = v2->co - v1->co;
- double da_length_squared = da.length_squared();
- double db_length_squared = db.length_squared();
+ double da_length_squared = math::length_squared(da);
+ double db_length_squared = math::length_squared(db);
if (da_length_squared == 0.0 || db_length_squared == 0.0) {
return true;
}
@@ -2240,8 +2238,8 @@ static bool any_degenerate_tris_fast(const Array<Face *> triangulation)
* The triangle is almost degenerate if sin t is almost 0.
* sin^2 t = |da x db|^2 / (|da|^2 |db|^2)
*/
- double3 dab = double3::cross_high_precision(da, db);
- double dab_length_squared = dab.length_squared();
+ double3 dab = math::cross(da, db);
+ double dab_length_squared = math::length_squared(dab);
double sin_squared_t = dab_length_squared / (da_length_squared * db_length_squared);
if (sin_squared_t < 1e-8) {
return true;
diff --git a/source/blender/blenlib/intern/noise.cc b/source/blender/blenlib/intern/noise.cc
index a6ad18801fd..3460c1284fc 100644
--- a/source/blender/blenlib/intern/noise.cc
+++ b/source/blender/blenlib/intern/noise.cc
@@ -50,9 +50,7 @@
#include <cmath>
#include <cstdint>
-#include "BLI_float2.hh"
-#include "BLI_float3.hh"
-#include "BLI_float4.hh"
+#include "BLI_math_vec_types.hh"
#include "BLI_math_base_safe.h"
#include "BLI_noise.hh"
#include "BLI_utildefines.h"
@@ -1469,7 +1467,7 @@ void voronoi_smooth_f1(const float w,
correctionFactor /= 1.0f + 3.0f * smoothness;
if (r_color != nullptr) {
const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset);
- smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor;
+ smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor;
}
if (r_w != nullptr) {
smoothPosition = mix(smoothPosition, pointPosition, h) - correctionFactor;
@@ -1592,7 +1590,7 @@ static float voronoi_distance(const float2 a,
{
switch (metric) {
case NOISE_SHD_VORONOI_EUCLIDEAN:
- return float2::distance(a, b);
+ return math::distance(a, b);
case NOISE_SHD_VORONOI_MANHATTAN:
return fabsf(a.x - b.x) + fabsf(a.y - b.y);
case NOISE_SHD_VORONOI_CHEBYCHEV:
@@ -1615,7 +1613,7 @@ void voronoi_f1(const float2 coord,
float3 *r_color,
float2 *r_position)
{
- const float2 cellPosition = float2::floor(coord);
+ const float2 cellPosition = math::floor(coord);
const float2 localPosition = coord - cellPosition;
float minDistance = 8.0f;
@@ -1654,7 +1652,7 @@ void voronoi_smooth_f1(const float2 coord,
float3 *r_color,
float2 *r_position)
{
- const float2 cellPosition = float2::floor(coord);
+ const float2 cellPosition = math::floor(coord);
const float2 localPosition = coord - cellPosition;
const float smoothness_clamped = max_ff(smoothness, FLT_MIN);
@@ -1676,11 +1674,10 @@ void voronoi_smooth_f1(const float2 coord,
correctionFactor /= 1.0f + 3.0f * smoothness;
if (r_color != nullptr) {
const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset);
- smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor;
+ smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor;
}
if (r_position != nullptr) {
- smoothPosition = float2::interpolate(smoothPosition, pointPosition, h) -
- correctionFactor;
+ smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - correctionFactor;
}
}
}
@@ -1704,7 +1701,7 @@ void voronoi_f2(const float2 coord,
float3 *r_color,
float2 *r_position)
{
- const float2 cellPosition = float2::floor(coord);
+ const float2 cellPosition = math::floor(coord);
const float2 localPosition = coord - cellPosition;
float distanceF1 = 8.0f;
@@ -1748,7 +1745,7 @@ void voronoi_f2(const float2 coord,
void voronoi_distance_to_edge(const float2 coord, const float randomness, float *r_distance)
{
- const float2 cellPosition = float2::floor(coord);
+ const float2 cellPosition = math::floor(coord);
const float2 localPosition = coord - cellPosition;
float2 vectorToClosest = float2(0.0f, 0.0f);
@@ -1777,7 +1774,7 @@ void voronoi_distance_to_edge(const float2 coord, const float randomness, float
const float2 perpendicularToEdge = vectorToPoint - vectorToClosest;
if (dot_v2v2(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {
const float distanceToEdge = dot_v2v2((vectorToClosest + vectorToPoint) / 2.0f,
- perpendicularToEdge.normalized());
+ math::normalize(perpendicularToEdge));
minDistance = std::min(minDistance, distanceToEdge);
}
}
@@ -1787,7 +1784,7 @@ void voronoi_distance_to_edge(const float2 coord, const float randomness, float
void voronoi_n_sphere_radius(const float2 coord, const float randomness, float *r_radius)
{
- const float2 cellPosition = float2::floor(coord);
+ const float2 cellPosition = math::floor(coord);
const float2 localPosition = coord - cellPosition;
float2 closestPoint = float2(0.0f, 0.0f);
@@ -1798,7 +1795,7 @@ void voronoi_n_sphere_radius(const float2 coord, const float randomness, float *
const float2 cellOffset = float2(i, j);
const float2 pointPosition = cellOffset +
hash_float_to_float2(cellPosition + cellOffset) * randomness;
- const float distanceToPoint = float2::distance(pointPosition, localPosition);
+ const float distanceToPoint = math::distance(pointPosition, localPosition);
if (distanceToPoint < minDistance) {
minDistance = distanceToPoint;
closestPoint = pointPosition;
@@ -1817,14 +1814,14 @@ void voronoi_n_sphere_radius(const float2 coord, const float randomness, float *
const float2 cellOffset = float2(i, j) + closestPointOffset;
const float2 pointPosition = cellOffset +
hash_float_to_float2(cellPosition + cellOffset) * randomness;
- const float distanceToPoint = float2::distance(closestPoint, pointPosition);
+ const float distanceToPoint = math::distance(closestPoint, pointPosition);
if (distanceToPoint < minDistance) {
minDistance = distanceToPoint;
closestPointToClosestPoint = pointPosition;
}
}
}
- *r_radius = float2::distance(closestPointToClosestPoint, closestPoint) / 2.0f;
+ *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f;
}
/* **** 3D Voronoi **** */
@@ -1836,7 +1833,7 @@ static float voronoi_distance(const float3 a,
{
switch (metric) {
case NOISE_SHD_VORONOI_EUCLIDEAN:
- return float3::distance(a, b);
+ return math::distance(a, b);
case NOISE_SHD_VORONOI_MANHATTAN:
return fabsf(a.x - b.x) + fabsf(a.y - b.y) + fabsf(a.z - b.z);
case NOISE_SHD_VORONOI_CHEBYCHEV:
@@ -1860,7 +1857,7 @@ void voronoi_f1(const float3 coord,
float3 *r_color,
float3 *r_position)
{
- const float3 cellPosition = float3::floor(coord);
+ const float3 cellPosition = math::floor(coord);
const float3 localPosition = coord - cellPosition;
float minDistance = 8.0f;
@@ -1902,7 +1899,7 @@ void voronoi_smooth_f1(const float3 coord,
float3 *r_color,
float3 *r_position)
{
- const float3 cellPosition = float3::floor(coord);
+ const float3 cellPosition = math::floor(coord);
const float3 localPosition = coord - cellPosition;
const float smoothness_clamped = max_ff(smoothness, FLT_MIN);
@@ -1925,10 +1922,10 @@ void voronoi_smooth_f1(const float3 coord,
correctionFactor /= 1.0f + 3.0f * smoothness;
if (r_color != nullptr) {
const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset);
- smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor;
+ smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor;
}
if (r_position != nullptr) {
- smoothPosition = float3::interpolate(smoothPosition, pointPosition, h) -
+ smoothPosition = math::interpolate(smoothPosition, pointPosition, h) -
correctionFactor;
}
}
@@ -1954,7 +1951,7 @@ void voronoi_f2(const float3 coord,
float3 *r_color,
float3 *r_position)
{
- const float3 cellPosition = float3::floor(coord);
+ const float3 cellPosition = math::floor(coord);
const float3 localPosition = coord - cellPosition;
float distanceF1 = 8.0f;
@@ -2000,7 +1997,7 @@ void voronoi_f2(const float3 coord,
void voronoi_distance_to_edge(const float3 coord, const float randomness, float *r_distance)
{
- const float3 cellPosition = float3::floor(coord);
+ const float3 cellPosition = math::floor(coord);
const float3 localPosition = coord - cellPosition;
float3 vectorToClosest = float3(0.0f, 0.0f, 0.0f);
@@ -2032,7 +2029,7 @@ void voronoi_distance_to_edge(const float3 coord, const float randomness, float
const float3 perpendicularToEdge = vectorToPoint - vectorToClosest;
if (dot_v3v3(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {
const float distanceToEdge = dot_v3v3((vectorToClosest + vectorToPoint) / 2.0f,
- perpendicularToEdge.normalized());
+ math::normalize(perpendicularToEdge));
minDistance = std::min(minDistance, distanceToEdge);
}
}
@@ -2043,7 +2040,7 @@ void voronoi_distance_to_edge(const float3 coord, const float randomness, float
void voronoi_n_sphere_radius(const float3 coord, const float randomness, float *r_radius)
{
- const float3 cellPosition = float3::floor(coord);
+ const float3 cellPosition = math::floor(coord);
const float3 localPosition = coord - cellPosition;
float3 closestPoint = float3(0.0f, 0.0f, 0.0f);
@@ -2055,7 +2052,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float *
const float3 cellOffset = float3(i, j, k);
const float3 pointPosition = cellOffset +
hash_float_to_float3(cellPosition + cellOffset) * randomness;
- const float distanceToPoint = float3::distance(pointPosition, localPosition);
+ const float distanceToPoint = math::distance(pointPosition, localPosition);
if (distanceToPoint < minDistance) {
minDistance = distanceToPoint;
closestPoint = pointPosition;
@@ -2076,7 +2073,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float *
const float3 cellOffset = float3(i, j, k) + closestPointOffset;
const float3 pointPosition = cellOffset +
hash_float_to_float3(cellPosition + cellOffset) * randomness;
- const float distanceToPoint = float3::distance(closestPoint, pointPosition);
+ const float distanceToPoint = math::distance(closestPoint, pointPosition);
if (distanceToPoint < minDistance) {
minDistance = distanceToPoint;
closestPointToClosestPoint = pointPosition;
@@ -2084,7 +2081,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float *
}
}
}
- *r_radius = float3::distance(closestPointToClosestPoint, closestPoint) / 2.0f;
+ *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f;
}
/* **** 4D Voronoi **** */
@@ -2096,7 +2093,7 @@ static float voronoi_distance(const float4 a,
{
switch (metric) {
case NOISE_SHD_VORONOI_EUCLIDEAN:
- return float4::distance(a, b);
+ return math::distance(a, b);
case NOISE_SHD_VORONOI_MANHATTAN:
return fabsf(a.x - b.x) + fabsf(a.y - b.y) + fabsf(a.z - b.z) + fabsf(a.w - b.w);
case NOISE_SHD_VORONOI_CHEBYCHEV:
@@ -2121,7 +2118,7 @@ void voronoi_f1(const float4 coord,
float3 *r_color,
float4 *r_position)
{
- const float4 cellPosition = float4::floor(coord);
+ const float4 cellPosition = math::floor(coord);
const float4 localPosition = coord - cellPosition;
float minDistance = 8.0f;
@@ -2166,7 +2163,7 @@ void voronoi_smooth_f1(const float4 coord,
float3 *r_color,
float4 *r_position)
{
- const float4 cellPosition = float4::floor(coord);
+ const float4 cellPosition = math::floor(coord);
const float4 localPosition = coord - cellPosition;
const float smoothness_clamped = max_ff(smoothness, FLT_MIN);
@@ -2191,10 +2188,10 @@ void voronoi_smooth_f1(const float4 coord,
correctionFactor /= 1.0f + 3.0f * smoothness;
if (r_color != nullptr) {
const float3 cellColor = hash_float_to_float3(cellPosition + cellOffset);
- smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor;
+ smoothColor = math::interpolate(smoothColor, cellColor, h) - correctionFactor;
}
if (r_position != nullptr) {
- smoothPosition = float4::interpolate(smoothPosition, pointPosition, h) -
+ smoothPosition = math::interpolate(smoothPosition, pointPosition, h) -
correctionFactor;
}
}
@@ -2221,7 +2218,7 @@ void voronoi_f2(const float4 coord,
float3 *r_color,
float4 *r_position)
{
- const float4 cellPosition = float4::floor(coord);
+ const float4 cellPosition = math::floor(coord);
const float4 localPosition = coord - cellPosition;
float distanceF1 = 8.0f;
@@ -2270,7 +2267,7 @@ void voronoi_f2(const float4 coord,
void voronoi_distance_to_edge(const float4 coord, const float randomness, float *r_distance)
{
- const float4 cellPosition = float4::floor(coord);
+ const float4 cellPosition = math::floor(coord);
const float4 localPosition = coord - cellPosition;
float4 vectorToClosest = float4(0.0f, 0.0f, 0.0f, 0.0f);
@@ -2307,7 +2304,7 @@ void voronoi_distance_to_edge(const float4 coord, const float randomness, float
const float4 perpendicularToEdge = vectorToPoint - vectorToClosest;
if (dot_v4v4(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {
const float distanceToEdge = dot_v4v4((vectorToClosest + vectorToPoint) / 2.0f,
- float4::normalize(perpendicularToEdge));
+ math::normalize(perpendicularToEdge));
minDistance = std::min(minDistance, distanceToEdge);
}
}
@@ -2319,7 +2316,7 @@ void voronoi_distance_to_edge(const float4 coord, const float randomness, float
void voronoi_n_sphere_radius(const float4 coord, const float randomness, float *r_radius)
{
- const float4 cellPosition = float4::floor(coord);
+ const float4 cellPosition = math::floor(coord);
const float4 localPosition = coord - cellPosition;
float4 closestPoint = float4(0.0f, 0.0f, 0.0f, 0.0f);
@@ -2333,7 +2330,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float *
const float4 pointPosition = cellOffset +
hash_float_to_float4(cellPosition + cellOffset) *
randomness;
- const float distanceToPoint = float4::distance(pointPosition, localPosition);
+ const float distanceToPoint = math::distance(pointPosition, localPosition);
if (distanceToPoint < minDistance) {
minDistance = distanceToPoint;
closestPoint = pointPosition;
@@ -2357,7 +2354,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float *
const float4 pointPosition = cellOffset +
hash_float_to_float4(cellPosition + cellOffset) *
randomness;
- const float distanceToPoint = float4::distance(closestPoint, pointPosition);
+ const float distanceToPoint = math::distance(closestPoint, pointPosition);
if (distanceToPoint < minDistance) {
minDistance = distanceToPoint;
closestPointToClosestPoint = pointPosition;
@@ -2366,7 +2363,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float *
}
}
}
- *r_radius = float4::distance(closestPointToClosestPoint, closestPoint) / 2.0f;
+ *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f;
}
/** \} */