Cleanup: Remove C header from C++ math header

Remove some redundancy between headers, more fully
separate the C++ headers from the older C headers.

Pull Request: https://projects.blender.org/blender/blender/pulls/114705
This commit is contained in:
Hans Goudey
2023-11-11 21:09:54 +01:00
committed by Hans Goudey
parent 8b4c9b294a
commit 583bd9662e
14 changed files with 23 additions and 20 deletions
@@ -46,7 +46,7 @@ AxisAngleBase<T, AngleT>::AxisAngleBase(const VecBase<T, 3> &from, const VecBase
T cos = dot(from, to);
axis_ = normalize_and_get_length(cross(from, to), sin);
if (sin <= FLT_EPSILON) {
if (sin <= std::numeric_limits<T>::epsilon()) {
if (cos > T(0)) {
/* Same vectors, zero rotation... */
*this = identity();
-1
View File
@@ -12,7 +12,6 @@
#include <cmath>
#include <type_traits>
#include "BLI_math_base_safe.h"
#include "BLI_utildefines.h"
namespace blender::math {
+3 -3
View File
@@ -758,7 +758,7 @@ void normalized_to_eul2(const MatBase<T, 3, 3> &mat, EulerXYZBase<T> &eul1, Eule
BLI_assert(math::is_unit_scale(mat));
const T cy = math::hypot(mat[0][0], mat[0][1]);
if (cy > T(16) * FLT_EPSILON) {
if (cy > T(16) * std::numeric_limits<T>::epsilon()) {
eul1.x() = math::atan2(mat[1][2], mat[2][2]);
eul1.y() = math::atan2(-mat[0][2], cy);
eul1.z() = math::atan2(mat[0][1], mat[0][0]);
@@ -784,7 +784,7 @@ void normalized_to_eul2(const MatBase<T, 3, 3> &mat, Euler3Base<T> &eul1, Euler3
const int k_index = eul1.k_index();
const T cy = math::hypot(mat[i_index][i_index], mat[i_index][j_index]);
if (cy > T(16) * FLT_EPSILON) {
if (cy > T(16) * std::numeric_limits<T>::epsilon()) {
eul1.i() = math::atan2(mat[j_index][k_index], mat[k_index][k_index]);
eul1.j() = math::atan2(-mat[i_index][k_index], cy);
eul1.k() = math::atan2(mat[i_index][j_index], mat[i_index][i_index]);
@@ -910,7 +910,7 @@ template<typename T> QuaternionBase<T> normalized_to_quat_fast(const MatBase<T,
template<typename T> QuaternionBase<T> normalized_to_quat_with_checks(const MatBase<T, 3, 3> &mat)
{
const T det = math::determinant(mat);
if (UNLIKELY(!isfinite(det))) {
if (UNLIKELY(!std::isfinite(det))) {
return QuaternionBase<T>::identity();
}
else if (UNLIKELY(det < T(0))) {
@@ -569,7 +569,7 @@ template<typename T>
Mat4T R, scale;
const bool has_scale = !is_orthonormal(mat) || is_negative(mat) ||
length_squared(to_scale(baseRS) - T(1)) > square_f(1e-4f);
length_squared(to_scale(baseRS) - T(1)) > square(1e-4f);
if (has_scale) {
/* Extract Rotation and Scale. */
const Mat4T baseinv = invert(basemat);
@@ -5,6 +5,7 @@
#include "testing/testing.h"
#include "BLI_math_base.hh"
#include "BLI_math_base_safe.h"
#include "BLI_math_vector.hh"
namespace blender::tests {
+3 -2
View File
@@ -306,6 +306,7 @@ DRWShadingGroup *DRW_shgroup_curves_create_sub(Object *object,
DRWShadingGroup *shgrp_parent,
GPUMaterial *gpu_material)
{
using namespace blender;
const DRWContextState *draw_ctx = DRW_context_state_get();
const Scene *scene = draw_ctx->scene;
CurvesUniformBufPool *pool = DST.vmempool->curves_ubos;
@@ -346,7 +347,7 @@ DRWShadingGroup *DRW_shgroup_curves_create_sub(Object *object,
hair_rad_root = radii[first_curve_points.first()];
hair_rad_tip = radii[first_curve_points.last()];
hair_rad_shape = std::clamp(
safe_divide(middle_radius - first_radius, last_radius - first_radius) * 2.0f - 1.0f,
math::safe_divide(middle_radius - first_radius, last_radius - first_radius) * 2.0f - 1.0f,
-1.0f,
1.0f);
}
@@ -692,7 +693,7 @@ GPUBatch *curves_sub_pass_setup_implementation(PassT &sub_ps,
hair_rad_root = radii[first_curve_points.first()];
hair_rad_tip = radii[first_curve_points.last()];
hair_rad_shape = std::clamp(
safe_divide(middle_radius - first_radius, last_radius - first_radius) * 2.0f - 1.0f,
math::safe_divide(middle_radius - first_radius, last_radius - first_radius) * 2.0f - 1.0f,
-1.0f,
1.0f);
}
@@ -376,7 +376,7 @@ void move_last_point_and_resample(MoveAndResampleBuffers &buffer,
/* Find the factor by which the new curve is shorter or longer than the original. */
const float new_last_segment_length = math::distance(positions.last(1), new_last_position);
const float new_total_length = buffer.orig_lengths.last(1) + new_last_segment_length;
const float length_factor = safe_divide(new_total_length, orig_total_length);
const float length_factor = math::safe_divide(new_total_length, orig_total_length);
/* Calculate the lengths to sample the original curve with by scaling the original lengths. */
buffer.new_lengths.reinitialize(positions.size() - 1);
@@ -228,7 +228,7 @@ struct CombOperationExecutor {
const IndexRange points = points_by_curve[curve_i];
const float total_length = self_->curve_lengths_[curve_i];
const float total_length_inv = safe_divide(1.0f, total_length);
const float total_length_inv = math::safe_rcp(total_length);
float current_length = 0.0f;
for (const int point_i : points.drop_front(1)) {
current_length += segment_lengths[point_i - 1];
@@ -347,7 +347,7 @@ struct CombOperationExecutor {
const IndexRange points = points_by_curve[curve_i];
const float total_length = self_->curve_lengths_[curve_i];
const float total_length_inv = safe_divide(1.0f, total_length);
const float total_length_inv = math::safe_rcp(total_length);
float current_length = 0.0f;
for (const int point_i : points.drop_front(1)) {
current_length += segment_lengths[point_i - 1];
@@ -191,7 +191,7 @@ class ScaleCurvesEffect : public CurvesEffect {
const float length_diff = scale_up_ ? move_distance_cu : -move_distance_cu;
const float min_length = brush_.curves_sculpt_settings->minimum_length;
const float new_length = std::max(min_length, old_length + length_diff);
const float scale_factor = safe_divide(new_length, old_length);
const float scale_factor = math::safe_divide(new_length, old_length);
const float3 &root_pos_cu = positions_cu[points[0]];
for (float3 &pos_cu : positions_cu.slice(points.drop_front(1))) {
@@ -192,7 +192,7 @@ struct PinchOperationExecutor {
}
const float dist_to_brush_re = std::sqrt(dist_to_brush_sq_re);
const float t = safe_divide(dist_to_brush_re, brush_radius_base_re_);
const float t = math::safe_divide(dist_to_brush_re, brush_radius_base_re_);
const float radius_falloff = t * BKE_brush_curve_strength(brush_, t, 1.0f);
const float weight = invert_factor_ * 0.1f * brush_strength_ * radius_falloff *
point_factors_[point_i];
@@ -261,7 +261,7 @@ struct PinchOperationExecutor {
}
const float dist_to_brush_cu = std::sqrt(dist_to_brush_sq_cu);
const float t = safe_divide(dist_to_brush_cu, brush_radius_cu);
const float t = math::safe_divide(dist_to_brush_cu, brush_radius_cu);
const float radius_falloff = t * BKE_brush_curve_strength(brush_, t, 1.0f);
const float weight = invert_factor_ * 0.1f * brush_strength_ * radius_falloff *
point_factors_[point_i];
@@ -1709,7 +1709,7 @@ static void calculate_inner_link_bezier_points(std::array<float2, 4> &points)
const float dist_y = math::distance(points[0].y, points[3].y);
/* Reduce the handle offset when the link endpoints are close to horizontal. */
const float slope = safe_divide(dist_y, dist_x);
const float slope = math::safe_divide(dist_y, dist_x);
const float clamp_factor = math::min(1.0f, slope * (4.5f - 0.25f * float(curving)));
const float handle_offset = curving * 0.1f * dist_x * clamp_factor;
@@ -145,13 +145,13 @@ static float limit_radius(const float3 &position_prev,
const float segment_length_prev = math::distance(position, position_prev);
const float total_displacement_prev = displacement_prev + displacement;
const float factor_prev = std::clamp(
safe_divide(segment_length_prev, total_displacement_prev), 0.0f, 1.0f);
math::safe_divide(segment_length_prev, total_displacement_prev), 0.0f, 1.0f);
const float displacement_next = radius_next * std::tan(angle_next / 2.0f);
const float segment_length_next = math::distance(position, position_next);
const float total_displacement_next = displacement_next + displacement;
const float factor_next = std::clamp(
safe_divide(segment_length_next, total_displacement_next), 0.0f, 1.0f);
math::safe_divide(segment_length_next, total_displacement_next), 0.0f, 1.0f);
return radius * std::min(factor_prev, factor_next);
}
@@ -51,7 +51,7 @@ static openvdb::FloatGrid::Ptr points_to_sdf_grid(const Span<float3> positions,
openvdb::tools::ParticlesToLevelSet op{*new_grid};
/* Don't ignore particles based on their radius. */
op.setRmin(0.0f);
op.setRmax(FLT_MAX);
op.setRmax(std::numeric_limits<float>::max());
OpenVDBParticleList particles{positions, radii};
op.rasterizeSpheres(particles);
op.finalize();
@@ -409,7 +409,8 @@ static void interpolate_curve_shapes(bke::CurvesGeometry &child_curves,
const float neighbor_length = lengths.last();
sample_lengths.reinitialize(points.size());
const float sample_length_factor = safe_divide(neighbor_length, points.size() - 1);
const float sample_length_factor = math::safe_divide(neighbor_length,
float(points.size() - 1));
for (const int i : sample_lengths.index_range()) {
sample_lengths[i] = i * sample_length_factor;
}
@@ -563,7 +564,8 @@ static void interpolate_curve_attributes(bke::CurvesGeometry &child_curves,
const float neighbor_length = lengths.last();
sample_lengths.reinitialize(points.size());
const float sample_length_factor = safe_divide(neighbor_length, points.size() - 1);
const float sample_length_factor = math::safe_divide(neighbor_length,
float(points.size() - 1));
for (const int i : sample_lengths.index_range()) {
sample_lengths[i] = i * sample_length_factor;
}