14#include "testing/testing.h"
26TEST(math_geom_hh, NormalQuad)
28 const float3 v1(0, 0, 0),
v2(1, 0, 0), v3(1, 1, 0), v4(0, 1, 0);
42 const float3 v1(0, 0, 0),
v2(1, 0, 0), v3(0, 1, 0);
49 const float3 degen(1, 2, 3);
53TEST(math_geom_hh, CotangentTriWeight)
56 const float sq3 = std::sqrt(3.0f);
57 const float3 v1(0, 0, 0),
v2(1, 0, 0), v3(0.5f, sq3 * 0.5f, 0);
62 const float3 degen(1, 0, 0);
72TEST(math_geom_hh, PlaneFromPointNormal)
74 const float3 co(1, 2, 3), no(0, 0, 1);
86TEST(math_geom_hh, PlanePointSide)
89 const float4 plane(0, 0, 1, 0);
96 const float c_plane[4] = {plane.x, plane.y, plane.z, plane.w};
106TEST(math_geom_hh, DistSquaredToLineSegment2D)
109 const float2 p(3, 1), l1(0, 0), l2(2, 0);
115 const float2 p2(1, 2), l3(0, 0), l4(2, 0);
121 const float2 p3(1, 1), degen(0, 0);
125TEST(math_geom_hh, DistSquaredToLineSegment3D)
127 const float3 p(0, 1, 0), l1(0, 0, 0), l2(1, 0, 0);
133TEST(math_geom_hh, ClosestToLineSegment3D)
135 const float3 p(0.5f, 1.0f, 0.0f), l1(0, 0, 0), l2(1, 0, 0);
146 const float3 degen(1, 1, 1);
153TEST(math_geom_hh, ClosestToPlaneNormalized)
156 const float4 plane(0, 0, 1, -1);
168TEST(math_geom_hh, ClosestToPlane)
171 const float4 plane(0, 0, 2, -2);
185TEST(math_geom_hh, DistSquaredToPlane)
188 const float4 unit_plane(0, 0, 1, 0);
196 const float4 scaled_plane(0, 0, 2, 0);
208TEST(math_geom_hh, LinePointFactor3D)
210 const float3 p(0.5f, 1.0f, 0.0f), l1(0, 0, 0), l2(1, 0, 0);
217TEST(math_geom_hh, LinePointFactor2D)
219 const float2 p(0.5f, 1.0f), l1(0, 0), l2(1, 0);
229TEST(math_geom_hh, AxisDominantToM3)
236 for (
int col = 0; col < 3; col++) {
237 for (
int row = 0; row < 3; row++) {
238 EXPECT_NEAR(c_mat[col][row], mat[col][row], 1e-6f);
249TEST(math_geom_hh, IsectLineLine3D)
252 const float3 v1(-1, 0, 0),
v2(1, 0, 0), v3(0, -1, 0), v4(0, 1, 0);
260TEST(math_geom_hh, IsectLinePlane)
263 const float3 l1(0, 0, 0), l2(0, 0, 2);
264 const float3 plane_co(0, 0, 1), plane_no(0, 0, 1);
265 const std::optional<float3> hit =
isect_line_plane(l1, l2, plane_co, plane_no);
266 ASSERT_TRUE(hit.has_value());
272 const float3 l3(0, 0, 0), l4(1, 0, 0);
276TEST(math_geom_hh, IsectPointTri2D)
278 const float2 v1(-1, 0),
v2(1, 0), v3(0, 2);
288TEST(math_geom_hh, IsectPointQuad2D)
290 const float2 v1(0, 0),
v2(2, 0), v3(2, 2), v4(0, 2);
300 const float2 p_inside(1, 1);
305TEST(math_geom_hh, IsectPointPoly)
313 const float2 pt_in(0.5f, 0.5f);
315 &pt_in.x,
reinterpret_cast<const float (*)[2]
>(verts.
data()),
uint(verts.
size())),
325TEST(math_geom_hh, BarycentricWeights)
327 const float2 v1(0, 0),
v2(1, 0), v3(0, 1);
330 const float2 centroid(1.0f / 3.0f, 1.0f / 3.0f);
348TEST(math_geom_hh, PolyToTriCount)
374TEST(math_geom_hh, InterpWeightsPoly)
380 for (
int i = 0; i < 4; i++) {
387 c_w,
reinterpret_cast<float (*)[2]
>(verts.
data()),
int(verts.
size()),
float2(0.5f, 0.5f));
388 for (
int i = 0; i < 4; i++) {
399TEST(math_geom_hh, InterpBilinearQuad)
406 const float3 v0(0, 0, 0), v1(1, 0, 0),
v2(1, 1, 0), v3(0, 1, 0);
416 {v0.x, v0.y, v0.z}, {v1.x, v1.y, v1.z}, {
v2.x,
v2.y,
v2.z}, {v3.x, v3.y, v3.z}};
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
constexpr MutableSpan()=default
#define EXPECT_FALSE(result)
#define EXPECT_TRUE(result)
#define EXPECT_NEAR(result, expect, threshold)
int isect_point_tri(const VecBase< T, 2 > &pt, const VecBase< T, 2 > &v1, const VecBase< T, 2 > &v2, const VecBase< T, 2 > &v3)
int isect_point_quad(const VecBase< T, 2 > &p, const VecBase< T, 2 > &v1, const VecBase< T, 2 > &v2, const VecBase< T, 2 > &v3, const VecBase< T, 2 > &v4)
T cotangent_tri_weight(const VecBase< T, 3 > &v1, const VecBase< T, 3 > &v2, const VecBase< T, 3 > &v3)
TEST(math_geom_hh, NormalQuad)
float3x3 axis_dominant_to_m3(const float3 &normal)
T dist_squared_to_line_segment(const VecBase< T, Size > &p, const VecBase< T, Size > &l1, const VecBase< T, Size > &l2)
VecBase< T, Size > closest_to_line_segment(const VecBase< T, Size > &p, const VecBase< T, Size > &l1, const VecBase< T, Size > &l2)
VecBase< T, 3 > interp_bilinear_quad(const VecBase< T, 3 > &v0, const VecBase< T, 3 > &v1, const VecBase< T, 3 > &v2, const VecBase< T, 3 > &v3, const T u, const T v)
T dist_squared_to_plane(const VecBase< T, 3 > &p, const VecBase< T, 4 > &plane)
float2 map_to_sphere(const float3 &co)
T plane_point_side(const VecBase< T, 4 > &plane, const VecBase< T, 3 > &co)
std::optional< float3 > isect_line_plane(const float3 &l1, const float3 &l2, const float3 &plane_co, const float3 &plane_no)
constexpr int poly_to_tri_count(const int poly_count, const int corner_count)
T area_tri(const VecBase< T, 3 > &v1, const VecBase< T, 3 > &v2, const VecBase< T, 3 > &v3)
VecBase< T, 3 > closest_to_plane_normalized(const VecBase< T, 4 > &plane, const VecBase< T, 3 > &pt)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
VecBase< T, 3 > normal_quad(const VecBase< T, 3 > &v1, const VecBase< T, 3 > &v2, const VecBase< T, 3 > &v3, const VecBase< T, 3 > &v4)
float3 barycentric_weights(const float2 &v1, const float2 &v2, const float2 &v3, const float2 &co)
float area_poly(Span< float2 > verts)
int isect_line_line(const float3 &v1, const float3 &v2, const float3 &v3, const float3 &v4, float3 &r_i1, float3 &r_i2)
VecBase< T, 4 > plane_from_point_normal(const VecBase< T, 3 > &co, const VecBase< T, 3 > &no)
T line_point_factor(const VecBase< T, Size > &p, const VecBase< T, Size > &l1, const VecBase< T, Size > &l2)
VecBase< T, 3 > closest_to_plane(const VecBase< T, 4 > &plane, const VecBase< T, 3 > &pt)
void interp_weights_poly(MutableSpan< float > r_weights, Span< float2 > verts, const float2 &co)
bool isect_point_poly(const float2 &pt, Span< float2 > verts)
void closest_to_plane_v3(float r_close[3], const float plane[4], const float pt[3])
float line_point_factor_v3(const float p[3], const float l1[3], const float l2[3])
float closest_to_line_segment_v3(float r_close[3], const float p[3], const float l1[3], const float l2[3])
bool map_to_sphere(float *r_u, float *r_v, float x, float y, float z)
void closest_to_plane_normalized_v3(float r_close[3], const float plane[4], const float pt[3])
void plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3])
float dist_squared_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2])
VecBase< float, 4 > float4
float area_poly_v2(const float verts[][2], unsigned int nr)
VecBase< float, 2 > float2
float line_point_factor_v2(const float p[2], const float l1[2], const float l2[2])
float normal_quad_v3(float n[3], const float v1[3], const float v2[3], const float v3[3], const float v4[3])
bool isect_point_poly_v2(const float pt[2], const float verts[][2], unsigned int nr)
MINLINE float plane_point_side_v3(const float plane[4], const float co[3])
int isect_point_quad_v2(const float p[2], const float v1[2], const float v2[2], const float v3[2], const float v4[2])
float dist_squared_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3])
MINLINE int poly_to_tri_count(int poly_count, int corner_count)
MatBase< float, 3, 3 > float3x3
void interp_weights_poly_v2(float w[], float v[][2], int n, const float co[2])
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
float cotangent_tri_weight_v3(const float v1[3], const float v2[3], const float v3[3])
float dist_squared_to_plane_v3(const float p[3], const float plane[4])
ATTR_WARN_UNUSED_RESULT const BMVert * v2
void interp_bilinear_quad_v3(float data[4][3], float u, float v, float res[3])
float area_tri_v3(const float v1[3], const float v2[3], const float v3[3])
VecBase< float, 3 > float3
void barycentric_weights_v2(const float v1[2], const float v2[2], const float v3[2], const float co[2], float w[3])
void axis_dominant_v3_to_m3(float r_mat[3][3], const float normal[3])
Normal to x,y matrix.