diff options
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/BLI_mempool_private.h | 5 | ||||
-rw-r--r-- | source/blender/blenlib/intern/delaunay_2d.cc | 45 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_boolean.cc | 7 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vec.cc | 133 | ||||
-rw-r--r-- | source/blender/blenlib/intern/mesh_boolean.cc | 51 | ||||
-rw-r--r-- | source/blender/blenlib/intern/mesh_intersect.cc | 88 | ||||
-rw-r--r-- | source/blender/blenlib/intern/noise.cc | 79 |
7 files changed, 242 insertions, 166 deletions
diff --git a/source/blender/blenlib/intern/BLI_mempool_private.h b/source/blender/blenlib/intern/BLI_mempool_private.h index 90569d87c41..03b0b11297b 100644 --- a/source/blender/blenlib/intern/BLI_mempool_private.h +++ b/source/blender/blenlib/intern/BLI_mempool_private.h @@ -54,8 +54,9 @@ typedef struct ParallelMempoolTaskData { * * See #BLI_task_parallel_mempool implementation for detailed usage example. */ -ParallelMempoolTaskData *mempool_iter_threadsafe_create(BLI_mempool *pool, const size_t num_iter) - ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +ParallelMempoolTaskData *mempool_iter_threadsafe_create(BLI_mempool *pool, + 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 842e6cb6135..53e881a9fc7 100644 --- a/source/blender/blenlib/intern/delaunay_2d.cc +++ b/source/blender/blenlib/intern/delaunay_2d.cc @@ -25,10 +25,11 @@ #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_math_vec_mpq_types.hh" +#include "BLI_mpq2.hh" #include "BLI_set.hh" #include "BLI_task.hh" #include "BLI_vector.hh" @@ -37,8 +38,6 @@ 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. */ @@ -789,11 +788,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 (dot(exact_ab, exact_ac) < 0) { + if (vec2<mpq_class>::dot(exact_ab, exact_ac) < 0) { return false; } vec2<mpq_class> exact_bc = c.exact - b.exact; - return dot(exact_bc, exact_ac) >= 0; + return vec2<mpq_class>::dot(exact_bc, exact_ac) >= 0; } #endif @@ -802,11 +801,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 (dot(ab, ac) < 0) { + if (vec2<double>::dot(ab, ac) < 0) { return false; } vec2<double> bc = c.approx - b.approx; - return dot(bc, ac) >= 0; + return vec2<double>::dot(bc, ac) >= 0; } template<> CDTVert<double>::CDTVert(const vec2<double> &pt) @@ -1082,7 +1081,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(interpolate(*a, *b, lambda)); + CDTVert<T> *v = this->add_vert(vec2<T>::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]; @@ -1705,16 +1704,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 = isect_seg_seg<vec2<T>>(va->co.exact, vb->co.exact, curco.exact, v2->co.exact); + auto isect = vec2<T>::isect_seg_seg(va->co.exact, vb->co.exact, curco.exact, v2->co.exact); T &lambda = isect.lambda; switch (isect.kind) { - case isect_result<vec2<T>>::LINE_LINE_CROSS: { + case vec2<T>::isect_result::LINE_LINE_CROSS: { #ifdef WITH_GMP if (!std::is_same<T, mpq_class>::value) { #else if (true) { #endif - double len_ab = distance(va->co.approx, vb->co.approx); + double len_ab = vec2<double>::distance(va->co.approx, vb->co.approx); if (lambda * len_ab <= epsilon) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } @@ -1736,7 +1735,7 @@ void fill_crossdata_for_intersect(const FatCo<T> &curco, } break; } - case isect_result<vec2<T>>::LINE_LINE_EXACT: { + case vec2<T>::isect_result::LINE_LINE_EXACT: { if (lambda == 0) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } @@ -1751,7 +1750,7 @@ void fill_crossdata_for_intersect(const FatCo<T> &curco, } break; } - case isect_result<vec2<T>>::LINE_LINE_NONE: { + case vec2<T>::isect_result::LINE_LINE_NONE: { #ifdef WITH_GMP if (std::is_same<T, mpq_class>::value) { BLI_assert(false); @@ -1767,9 +1766,9 @@ void fill_crossdata_for_intersect(const FatCo<T> &curco, } break; } - 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)) { + 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)) { fill_crossdata_for_through_vert(va, se_vcva, cd, cd_next); } else { @@ -1846,7 +1845,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 = interpolate(va->co.exact, vb->co.exact, cd->lambda); + vec2<T> curco = vec2<T>::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; @@ -2387,7 +2386,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 = distance_squared(co1, co2); + dissolvable_edges[i].len_squared = vec2<double>::distance_squared(co1, co2); i++; } } @@ -2570,18 +2569,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 = isect_seg_seg<vec2<T>>(ray_end.exact, + auto isect = vec2<T>::isect_seg_seg(ray_end.exact, mid.exact, e->symedges[0].vert->co.exact, e->symedges[1].vert->co.exact); switch (isect.kind) { - case isect_result<vec2<T>>::LINE_LINE_CROSS: { + case vec2<T>::isect_result::LINE_LINE_CROSS: { hits++; break; } - case isect_result<vec2<T>>::LINE_LINE_EXACT: - case isect_result<vec2<T>>::LINE_LINE_NONE: - case isect_result<vec2<T>>::LINE_LINE_COLINEAR: + case vec2<T>::isect_result::LINE_LINE_EXACT: + case vec2<T>::isect_result::LINE_LINE_NONE: + case vec2<T>::isect_result::LINE_LINE_COLINEAR: break; } } diff --git a/source/blender/blenlib/intern/math_boolean.cc b/source/blender/blenlib/intern/math_boolean.cc index 0bae3c23f79..c16755868aa 100644 --- a/source/blender/blenlib/intern/math_boolean.cc +++ b/source/blender/blenlib/intern/math_boolean.cc @@ -18,10 +18,15 @@ * \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_math_vec_types.hh" +#include "BLI_mpq2.hh" +#include "BLI_mpq3.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 6fab6c9a383..223c0e273f0 100644 --- a/source/blender/blenlib/intern/math_vec.cc +++ b/source/blender/blenlib/intern/math_vec.cc @@ -18,83 +18,89 @@ * \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_vec_mpq_types.hh" -#include "BLI_math_vector.hh" +#include "BLI_math_mpq.hh" +#include "BLI_mpq2.hh" +#include "BLI_mpq3.hh" #include "BLI_span.hh" #include "BLI_utildefines.h" -namespace blender::math { +namespace blender { -template<> -isect_result<float2> isect_seg_seg(const float2 &v1, - const float2 &v2, - const float2 &v3, - const float2 &v4) +float2::isect_result float2::isect_seg_seg(const float2 &v1, + const float2 &v2, + const float2 &v3, + const float2 &v4) { - isect_result<float2> ans; + float2::isect_result 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.kind = isect_result<float2>::LINE_LINE_COLINEAR; + ans.mu = 0.0f; + ans.kind = float2::isect_result::LINE_LINE_COLINEAR; } else { ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; - 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; + 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; } else { - ans.kind = isect_result<float2>::LINE_LINE_CROSS; + ans.kind = float2::isect_result::LINE_LINE_CROSS; } } else { - ans.kind = isect_result<float2>::LINE_LINE_NONE; + ans.kind = float2::isect_result::LINE_LINE_NONE; } } return ans; } -template<> -isect_result<double2> isect_seg_seg(const double2 &v1, - const double2 &v2, - const double2 &v3, - const double2 &v4) +double2::isect_result double2::isect_seg_seg(const double2 &v1, + const double2 &v2, + const double2 &v3, + const double2 &v4) { - isect_result<double2> ans; + double2::isect_result 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 = isect_result<double2>::LINE_LINE_COLINEAR; + ans.kind = double2::isect_result::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 = isect_result<double2>::LINE_LINE_EXACT; + ans.kind = double2::isect_result::LINE_LINE_EXACT; } else { - ans.kind = isect_result<double2>::LINE_LINE_CROSS; + ans.kind = double2::isect_result::LINE_LINE_CROSS; } } else { - ans.kind = isect_result<double2>::LINE_LINE_NONE; + ans.kind = double2::isect_result::LINE_LINE_NONE; } } return ans; } #ifdef WITH_GMP -template<> -isect_result<mpq2> isect_seg_seg(const mpq2 &v1, const mpq2 &v2, const mpq2 &v3, const mpq2 &v4) +mpq2::isect_result mpq2::isect_seg_seg(const mpq2 &v1, + const mpq2 &v2, + const mpq2 &v3, + const mpq2 &v4) { - isect_result<mpq2> ans; + mpq2::isect_result 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 = isect_result<mpq2>::LINE_LINE_COLINEAR; + ans.kind = mpq2::isect_result::LINE_LINE_COLINEAR; } else { ans.lambda = ((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; @@ -103,21 +109,66 @@ isect_result<mpq2> isect_seg_seg(const mpq2 &v1, const mpq2 &v2, const mpq2 &v3, 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 = isect_result<mpq2>::LINE_LINE_EXACT; + ans.kind = mpq2::isect_result::LINE_LINE_EXACT; } else { - ans.kind = isect_result<mpq2>::LINE_LINE_CROSS; + ans.kind = mpq2::isect_result::LINE_LINE_CROSS; } } else { - ans.kind = isect_result<mpq2>::LINE_LINE_NONE; + ans.kind = mpq2::isect_result::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) { @@ -125,6 +176,20 @@ 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::math +} // namespace blender diff --git a/source/blender/blenlib/intern/mesh_boolean.cc b/source/blender/blenlib/intern/mesh_boolean.cc index a3eae1896d3..ce4db0c6b9d 100644 --- a/source/blender/blenlib/intern/mesh_boolean.cc +++ b/source/blender/blenlib/intern/mesh_boolean.cc @@ -28,6 +28,8 @@ # 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" @@ -35,9 +37,8 @@ # 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" @@ -1632,13 +1633,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 = math::cross(abscissa, ordinate); + mpq3 normal = mpq3::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 = math::length_squared(normal); + mpq_class nlen2 = normal.length_squared(); mpq_class max_abs_slope = -1; Edge esort; const Vector<Edge> &edges = tmtopo.vert_edges(closestp); @@ -1647,12 +1648,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 - (math::dot(evec, normal) / nlen2) * normal; + mpq3 proj_evec = evec - (mpq3::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 = math::dot(proj_evec, abscissa); - mpq_class evec_o = math::dot(proj_evec, ordinate); + mpq_class evec_a = mpq3::dot(proj_evec, abscissa); + mpq_class evec_o = mpq3::dot(proj_evec, ordinate); if (dbg_level > 0) { std::cout << "e = " << e << "\n"; std::cout << "v_other = " << v_other << "\n"; @@ -1790,8 +1791,8 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, ap = p; ap -= a; - mpq_class d1 = math::dot_with_buffer(ab, ap, m); - mpq_class d2 = math::dot_with_buffer(ac, ap, m); + mpq_class d1 = mpq3::dot_with_buffer(ab, ap, m); + mpq_class d2 = mpq3::dot_with_buffer(ac, ap, m); if (d1 <= 0 && d2 <= 0) { /* Barycentric coordinates (1,0,0). */ *r_edge = -1; @@ -1799,13 +1800,13 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = a\n"; } - return math::distance_squared_with_buffer(p, a, m); + return mpq3::distance_squared_with_buffer(p, a, m); } /* Check if p in vertex region outside b. */ bp = p; bp -= b; - mpq_class d3 = math::dot_with_buffer(ab, bp, m); - mpq_class d4 = math::dot_with_buffer(ac, bp, m); + mpq_class d3 = mpq3::dot_with_buffer(ab, bp, m); + mpq_class d4 = mpq3::dot_with_buffer(ac, bp, m); if (d3 >= 0 && d4 <= d3) { /* Barycentric coordinates (0,1,0). */ *r_edge = -1; @@ -1813,7 +1814,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = b\n"; } - return math::distance_squared_with_buffer(p, b, m); + return mpq3::distance_squared_with_buffer(p, b, m); } /* Check if p in region of ab. */ mpq_class vc = d1 * d4 - d3 * d2; @@ -1828,13 +1829,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 math::distance_squared_with_buffer(p, r, m); + return mpq3::distance_squared_with_buffer(p, r, m); } /* Check if p in vertex region outside c. */ cp = p; cp -= c; - mpq_class d5 = math::dot_with_buffer(ab, cp, m); - mpq_class d6 = math::dot_with_buffer(ac, cp, m); + mpq_class d5 = mpq3::dot_with_buffer(ab, cp, m); + mpq_class d6 = mpq3::dot_with_buffer(ac, cp, m); if (d6 >= 0 && d5 <= d6) { /* Barycentric coordinates (0,0,1). */ *r_edge = -1; @@ -1842,7 +1843,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = c\n"; } - return math::distance_squared_with_buffer(p, c, m); + return mpq3::distance_squared_with_buffer(p, c, m); } /* Check if p in edge region of ac. */ mpq_class vb = d5 * d2 - d1 * d6; @@ -1857,7 +1858,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 math::distance_squared_with_buffer(p, r, m); + return mpq3::distance_squared_with_buffer(p, r, m); } /* Check if p in edge region of bc. */ mpq_class va = d3 * d6 - d5 * d4; @@ -1873,7 +1874,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 math::distance_squared_with_buffer(p, r, m); + return mpq3::distance_squared_with_buffer(p, r, m); } /* p inside face region. Compute barycentric coordinates (u,v,w). */ mpq_class denom = 1 / (va + vb + vc); @@ -1889,7 +1890,7 @@ static mpq_class closest_on_tri_to_point(const mpq3 &p, if (dbg_level > 0) { std::cout << " answer = inside at " << r << "\n"; } - return math::distance_squared_with_buffer(p, r, m); + return mpq3::distance_squared_with_buffer(p, r, m); } static float closest_on_tri_to_point_float_dist_squared(const float3 &p, @@ -2609,7 +2610,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 = math::normalize(tri_test.plane->norm); + double3 norm = tri_test.plane->norm.normalized(); const double offset_amount = 1e-5; double3 offset_test_point = test_point + offset_amount * norm; if (dbg_level > 0) { @@ -3001,7 +3002,7 @@ static void init_face_merge_state(FaceMergeState *fms, std::cout << "process tri = " << &tri << "\n"; } BLI_assert(tri.plane_populated()); - if (math::dot(norm, tri.plane->norm) <= 0.0) { + if (double3::dot(norm, tri.plane->norm) <= 0.0) { if (dbg_level > 0) { std::cout << "triangle has wrong orientation, skipping\n"; } @@ -3026,7 +3027,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 = math::length_squared(vec); + new_me.len_squared = vec.length_squared(); 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); @@ -3266,7 +3267,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 && math::dot(first_tri_normal, second_tri_normal) > 0.0) { + if (tris.size() == 2 && double3::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]); @@ -3331,7 +3332,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 = math::dot(math::normalize(vec1), math::normalize(vec2)); + double cos_ang = double3::dot(vec1.normalized(), vec2.normalized()); 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 982759ffcff..1f150137ba3 100644 --- a/source/blender/blenlib/intern/mesh_intersect.cc +++ b/source/blender/blenlib/intern/mesh_intersect.cc @@ -30,13 +30,15 @@ # 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_math_vec_mpq_types.hh" -# include "BLI_math_vec_types.hh" +# include "BLI_mpq2.hh" +# include "BLI_mpq3.hh" # include "BLI_polyfill_2d.h" # include "BLI_set.hh" # include "BLI_span.hh" @@ -196,14 +198,14 @@ void Face::populate_plane(bool need_exact) for (int i : index_range()) { co[i] = vert[i]->co_exact; } - normal_exact = math::cross_poly(co.as_span()); + normal_exact = mpq3::cross_poly(co); } else { mpq3 tr02 = vert[0]->co_exact - vert[2]->co_exact; mpq3 tr12 = vert[1]->co_exact - vert[2]->co_exact; - normal_exact = math::cross(tr02, tr12); + normal_exact = mpq3::cross(tr02, tr12); } - mpq_class d_exact = -math::dot(normal_exact, vert[0]->co_exact); + mpq_class d_exact = -mpq3::dot(normal_exact, vert[0]->co_exact); plane = new Plane(normal_exact, d_exact); } else { @@ -213,14 +215,14 @@ void Face::populate_plane(bool need_exact) for (int i : index_range()) { co[i] = vert[i]->co; } - normal = math::cross_poly(co.as_span()); + normal = double3::cross_poly(co); } else { double3 tr02 = vert[0]->co - vert[2]->co; double3 tr12 = vert[1]->co - vert[2]->co; - normal = math::cross(tr02, tr12); + normal = double3::cross_high_precision(tr02, tr12); } - double d = -math::dot(normal, vert[0]->co); + double d = -double3::dot(normal, vert[0]->co); plane = new Plane(normal, d); } } @@ -1096,15 +1098,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 = math::abs(a); - double3 abs_b = math::abs(b); + double3 abs_a = double3::abs(a); + double3 abs_b = double3::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 math::dot(c, c); + return double3::dot(c, c); } /* The index of dot when inputs are plane_coords with index 1 is much higher. @@ -1141,11 +1143,11 @@ static int filter_plane_side(const double3 &p, const double3 &abs_plane_p, const double3 &abs_plane_no) { - double d = math::dot(p - plane_p, plane_no); + double d = double3::dot(p - plane_p, plane_no); if (d == 0.0) { return 0; } - double supremum = math::dot(abs_p + abs_plane_p, abs_plane_no); + double supremum = double3::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; @@ -1176,9 +1178,9 @@ static inline mpq3 tti_interp( ab -= b; ac = a; ac -= c; - mpq_class den = math::dot_with_buffer(ab, n, dotbuf); + mpq_class den = mpq3::dot_with_buffer(ab, n, dotbuf); BLI_assert(den != 0); - mpq_class alpha = math::dot_with_buffer(ac, n, dotbuf) / den; + mpq_class alpha = mpq3::dot_with_buffer(ac, n, dotbuf) / den; return a - alpha * ab; } @@ -1207,7 +1209,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(math::dot_with_buffer(ad, n, dotbuf)); + return sgn(mpq3::dot_with_buffer(ad, n, dotbuf)); } /** @@ -1426,11 +1428,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 = 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); + 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); 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); @@ -1446,9 +1448,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 = math::abs(d_p2); - const double3 &abs_d_q2 = math::abs(d_q2); - const double3 &abs_d_n1 = math::abs(d_n1); + 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); 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); @@ -1475,17 +1477,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(math::dot_with_buffer(buf[0], n2, buf[1])); + sp1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1])); } if (sq1 == 0) { buf[0] = q1; buf[0] -= r2; - sq1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1])); + sq1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1])); } if (sr1 == 0) { buf[0] = r1; buf[0] -= r2; - sr1 = sgn(math::dot_with_buffer(buf[0], n2, buf[1])); + sr1 = sgn(mpq3::dot_with_buffer(buf[0], n2, buf[1])); } if (dbg_level > 1) { @@ -1507,17 +1509,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(math::dot_with_buffer(buf[0], n1, buf[1])); + sp2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1])); } if (sq2 == 0) { buf[0] = q2; buf[0] -= r1; - sq2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1])); + sq2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1])); } if (sr2 == 0) { buf[0] = r2; buf[0] -= r1; - sr2 = sgn(math::dot_with_buffer(buf[0], n1, buf[1])); + sr2 = sgn(mpq3::dot_with_buffer(buf[0], n1, buf[1])); } if (dbg_level > 1) { @@ -1719,7 +1721,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 = math::dominant_axis(ans.t_plane->norm_exact); + ans.proj_axis = mpq3::dominant_axis(ans.t_plane->norm_exact); prepare_need_tri(ans, tm, t); for (const ITT_value &itt : itts) { switch (itt.kind) { @@ -1755,7 +1757,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 = math::dominant_axis(ans.t_plane->norm_exact); + ans.proj_axis = mpq3::dominant_axis(ans.t_plane->norm_exact); for (const int t : cl) { prepare_need_tri(ans, tm, t); } @@ -2002,9 +2004,9 @@ static bool is_quad_flip_first_third(const double3 &v1, const double3 &normal) { double3 dir_v3v1 = v3 - v1; - double3 tangent = math::cross(dir_v3v1, normal); - double dot = math::dot(v1, tangent); - return (math::dot(v4, tangent) >= dot) || (math::dot(v2, tangent) <= dot); + 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); } /** @@ -2122,7 +2124,7 @@ static Array<Face *> exact_triangulate_poly(Face *f, IMeshArena *arena) f->populate_plane(false); } const double3 &poly_normal = f->plane->norm; - int axis = math::dominant_axis(poly_normal); + int axis = double3::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 @@ -2201,15 +2203,15 @@ static bool face_is_degenerate(const Face *f) } double3 da = v2->co - v0->co; double3 db = v2->co - v1->co; - double3 dab = math::cross(da, db); - double dab_length_squared = math::length_squared(dab); + double3 dab = double3::cross_high_precision(da, db); + double dab_length_squared = dab.length_squared(); 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 = math::cross(a, b); + mpq3 ab = mpq3::cross(a, b); if (ab.x == 0 && ab.y == 0 && ab.z == 0) { return true; } @@ -2229,8 +2231,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 = math::length_squared(da); - double db_length_squared = math::length_squared(db); + double da_length_squared = da.length_squared(); + double db_length_squared = db.length_squared(); if (da_length_squared == 0.0 || db_length_squared == 0.0) { return true; } @@ -2238,8 +2240,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 = math::cross(da, db); - double dab_length_squared = math::length_squared(dab); + double3 dab = double3::cross_high_precision(da, db); + double dab_length_squared = dab.length_squared(); 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 3460c1284fc..a6ad18801fd 100644 --- a/source/blender/blenlib/intern/noise.cc +++ b/source/blender/blenlib/intern/noise.cc @@ -50,7 +50,9 @@ #include <cmath> #include <cstdint> -#include "BLI_math_vec_types.hh" +#include "BLI_float2.hh" +#include "BLI_float3.hh" +#include "BLI_float4.hh" #include "BLI_math_base_safe.h" #include "BLI_noise.hh" #include "BLI_utildefines.h" @@ -1467,7 +1469,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 = math::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_w != nullptr) { smoothPosition = mix(smoothPosition, pointPosition, h) - correctionFactor; @@ -1590,7 +1592,7 @@ static float voronoi_distance(const float2 a, { switch (metric) { case NOISE_SHD_VORONOI_EUCLIDEAN: - return math::distance(a, b); + return float2::distance(a, b); case NOISE_SHD_VORONOI_MANHATTAN: return fabsf(a.x - b.x) + fabsf(a.y - b.y); case NOISE_SHD_VORONOI_CHEBYCHEV: @@ -1613,7 +1615,7 @@ void voronoi_f1(const float2 coord, float3 *r_color, float2 *r_position) { - const float2 cellPosition = math::floor(coord); + const float2 cellPosition = float2::floor(coord); const float2 localPosition = coord - cellPosition; float minDistance = 8.0f; @@ -1652,7 +1654,7 @@ void voronoi_smooth_f1(const float2 coord, float3 *r_color, float2 *r_position) { - const float2 cellPosition = math::floor(coord); + const float2 cellPosition = float2::floor(coord); const float2 localPosition = coord - cellPosition; const float smoothness_clamped = max_ff(smoothness, FLT_MIN); @@ -1674,10 +1676,11 @@ 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 = math::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_position != nullptr) { - smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - correctionFactor; + smoothPosition = float2::interpolate(smoothPosition, pointPosition, h) - + correctionFactor; } } } @@ -1701,7 +1704,7 @@ void voronoi_f2(const float2 coord, float3 *r_color, float2 *r_position) { - const float2 cellPosition = math::floor(coord); + const float2 cellPosition = float2::floor(coord); const float2 localPosition = coord - cellPosition; float distanceF1 = 8.0f; @@ -1745,7 +1748,7 @@ void voronoi_f2(const float2 coord, void voronoi_distance_to_edge(const float2 coord, const float randomness, float *r_distance) { - const float2 cellPosition = math::floor(coord); + const float2 cellPosition = float2::floor(coord); const float2 localPosition = coord - cellPosition; float2 vectorToClosest = float2(0.0f, 0.0f); @@ -1774,7 +1777,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, - math::normalize(perpendicularToEdge)); + perpendicularToEdge.normalized()); minDistance = std::min(minDistance, distanceToEdge); } } @@ -1784,7 +1787,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 = math::floor(coord); + const float2 cellPosition = float2::floor(coord); const float2 localPosition = coord - cellPosition; float2 closestPoint = float2(0.0f, 0.0f); @@ -1795,7 +1798,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 = math::distance(pointPosition, localPosition); + const float distanceToPoint = float2::distance(pointPosition, localPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPoint = pointPosition; @@ -1814,14 +1817,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 = math::distance(closestPoint, pointPosition); + const float distanceToPoint = float2::distance(closestPoint, pointPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPointToClosestPoint = pointPosition; } } } - *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f; + *r_radius = float2::distance(closestPointToClosestPoint, closestPoint) / 2.0f; } /* **** 3D Voronoi **** */ @@ -1833,7 +1836,7 @@ static float voronoi_distance(const float3 a, { switch (metric) { case NOISE_SHD_VORONOI_EUCLIDEAN: - return math::distance(a, b); + return float3::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: @@ -1857,7 +1860,7 @@ void voronoi_f1(const float3 coord, float3 *r_color, float3 *r_position) { - const float3 cellPosition = math::floor(coord); + const float3 cellPosition = float3::floor(coord); const float3 localPosition = coord - cellPosition; float minDistance = 8.0f; @@ -1899,7 +1902,7 @@ void voronoi_smooth_f1(const float3 coord, float3 *r_color, float3 *r_position) { - const float3 cellPosition = math::floor(coord); + const float3 cellPosition = float3::floor(coord); const float3 localPosition = coord - cellPosition; const float smoothness_clamped = max_ff(smoothness, FLT_MIN); @@ -1922,10 +1925,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 = math::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_position != nullptr) { - smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - + smoothPosition = float3::interpolate(smoothPosition, pointPosition, h) - correctionFactor; } } @@ -1951,7 +1954,7 @@ void voronoi_f2(const float3 coord, float3 *r_color, float3 *r_position) { - const float3 cellPosition = math::floor(coord); + const float3 cellPosition = float3::floor(coord); const float3 localPosition = coord - cellPosition; float distanceF1 = 8.0f; @@ -1997,7 +2000,7 @@ void voronoi_f2(const float3 coord, void voronoi_distance_to_edge(const float3 coord, const float randomness, float *r_distance) { - const float3 cellPosition = math::floor(coord); + const float3 cellPosition = float3::floor(coord); const float3 localPosition = coord - cellPosition; float3 vectorToClosest = float3(0.0f, 0.0f, 0.0f); @@ -2029,7 +2032,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, - math::normalize(perpendicularToEdge)); + perpendicularToEdge.normalized()); minDistance = std::min(minDistance, distanceToEdge); } } @@ -2040,7 +2043,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 = math::floor(coord); + const float3 cellPosition = float3::floor(coord); const float3 localPosition = coord - cellPosition; float3 closestPoint = float3(0.0f, 0.0f, 0.0f); @@ -2052,7 +2055,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 = math::distance(pointPosition, localPosition); + const float distanceToPoint = float3::distance(pointPosition, localPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPoint = pointPosition; @@ -2073,7 +2076,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 = math::distance(closestPoint, pointPosition); + const float distanceToPoint = float3::distance(closestPoint, pointPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPointToClosestPoint = pointPosition; @@ -2081,7 +2084,7 @@ void voronoi_n_sphere_radius(const float3 coord, const float randomness, float * } } } - *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f; + *r_radius = float3::distance(closestPointToClosestPoint, closestPoint) / 2.0f; } /* **** 4D Voronoi **** */ @@ -2093,7 +2096,7 @@ static float voronoi_distance(const float4 a, { switch (metric) { case NOISE_SHD_VORONOI_EUCLIDEAN: - return math::distance(a, b); + return float4::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: @@ -2118,7 +2121,7 @@ void voronoi_f1(const float4 coord, float3 *r_color, float4 *r_position) { - const float4 cellPosition = math::floor(coord); + const float4 cellPosition = float4::floor(coord); const float4 localPosition = coord - cellPosition; float minDistance = 8.0f; @@ -2163,7 +2166,7 @@ void voronoi_smooth_f1(const float4 coord, float3 *r_color, float4 *r_position) { - const float4 cellPosition = math::floor(coord); + const float4 cellPosition = float4::floor(coord); const float4 localPosition = coord - cellPosition; const float smoothness_clamped = max_ff(smoothness, FLT_MIN); @@ -2188,10 +2191,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 = math::interpolate(smoothColor, cellColor, h) - correctionFactor; + smoothColor = float3::interpolate(smoothColor, cellColor, h) - correctionFactor; } if (r_position != nullptr) { - smoothPosition = math::interpolate(smoothPosition, pointPosition, h) - + smoothPosition = float4::interpolate(smoothPosition, pointPosition, h) - correctionFactor; } } @@ -2218,7 +2221,7 @@ void voronoi_f2(const float4 coord, float3 *r_color, float4 *r_position) { - const float4 cellPosition = math::floor(coord); + const float4 cellPosition = float4::floor(coord); const float4 localPosition = coord - cellPosition; float distanceF1 = 8.0f; @@ -2267,7 +2270,7 @@ void voronoi_f2(const float4 coord, void voronoi_distance_to_edge(const float4 coord, const float randomness, float *r_distance) { - const float4 cellPosition = math::floor(coord); + const float4 cellPosition = float4::floor(coord); const float4 localPosition = coord - cellPosition; float4 vectorToClosest = float4(0.0f, 0.0f, 0.0f, 0.0f); @@ -2304,7 +2307,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, - math::normalize(perpendicularToEdge)); + float4::normalize(perpendicularToEdge)); minDistance = std::min(minDistance, distanceToEdge); } } @@ -2316,7 +2319,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 = math::floor(coord); + const float4 cellPosition = float4::floor(coord); const float4 localPosition = coord - cellPosition; float4 closestPoint = float4(0.0f, 0.0f, 0.0f, 0.0f); @@ -2330,7 +2333,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 = math::distance(pointPosition, localPosition); + const float distanceToPoint = float4::distance(pointPosition, localPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPoint = pointPosition; @@ -2354,7 +2357,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 = math::distance(closestPoint, pointPosition); + const float distanceToPoint = float4::distance(closestPoint, pointPosition); if (distanceToPoint < minDistance) { minDistance = distanceToPoint; closestPointToClosestPoint = pointPosition; @@ -2363,7 +2366,7 @@ void voronoi_n_sphere_radius(const float4 coord, const float randomness, float * } } } - *r_radius = math::distance(closestPointToClosestPoint, closestPoint) / 2.0f; + *r_radius = float4::distance(closestPointToClosestPoint, closestPoint) / 2.0f; } /** \} */ |