Blender V5.0
BLI_convexhull_2d_test.cc File Reference
#include "testing/testing.h"
#include "BLI_array.hh"
#include "BLI_convexhull_2d.hh"
#include "BLI_math_angle_types.hh"
#include "BLI_math_geom.h"
#include "BLI_math_matrix.h"
#include "BLI_math_matrix_types.hh"
#include "BLI_math_rotation.h"
#include "BLI_math_rotation.hh"
#include "BLI_math_vector.h"
#include "BLI_math_vector.hh"
#include "BLI_math_vector_types.hh"
#include "BLI_rand.hh"

Go to the source code of this file.

Macros

#define DEFAULT_TEST_ITER   8
#define DEFAULT_TEST_POLY_NUM   12
#define DEFAULT_TEST_RANDOM_SEED   123
#define ROTATION_EPS   1e-6

Functions

Internal Utilities
static blender::Array< float2convexhull_points_from_map (blender::Span< float2 > points, blender::Span< int > points_map)
static blender::Array< float2convexhull_2d_as_array (blender::Span< float2 > points)
static float mod_inline (float a, float b)
static float convexhull_aabb_canonical_angle (float angle)
Tests
 TEST (convexhull_2d, IsConvex)
 TEST (convexhull_2d, IsCCW)
 TEST (convexhull_2d, NOP)
 TEST (convexhull_2d, Lines_AxisAligned)
 TEST (convexhull_2d, Lines_Diagonal)
 TEST (convexhull_2d, Simple)
 TEST (convexhull_2d, Octagon)
 TEST (convexhull_2d, OctagonAxisAligned)
 TEST (convexhull_2d, OctagonNearDuplicates)
 TEST (convexhull_2d, Complex)

Detailed Description

Test that convex hull calculation and fitting convex hulls to a bounding box is working properly.

Note
Bounding box fitting checks compare against exact values. In this case there are multiple correct angles since both 45 degrees & -45 degrees will give the desired outcome. Keep using exact value matches so any changes to the return values are detected. If this becomes a problem for maintaining tests then values could be normalized for comparison.

Definition in file BLI_convexhull_2d_test.cc.

Macro Definition Documentation

◆ DEFAULT_TEST_ITER

#define DEFAULT_TEST_ITER   8

Increase to a large number (8k or so) to test many permutations, too slow for regular tests.

Definition at line 37 of file BLI_convexhull_2d_test.cc.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ DEFAULT_TEST_POLY_NUM

#define DEFAULT_TEST_POLY_NUM   12

The size of a polygon when generating data.

Definition at line 40 of file BLI_convexhull_2d_test.cc.

Referenced by TEST(), TEST(), and TEST().

◆ DEFAULT_TEST_RANDOM_SEED

#define DEFAULT_TEST_RANDOM_SEED   123

Definition at line 42 of file BLI_convexhull_2d_test.cc.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ ROTATION_EPS

#define ROTATION_EPS   1e-6

The epsilon to use when comparing floating point rotations (as radians).

Definition at line 45 of file BLI_convexhull_2d_test.cc.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

Function Documentation

◆ convexhull_2d_as_array()

◆ convexhull_aabb_canonical_angle()

float convexhull_aabb_canonical_angle ( float angle)
static

Returns an angle mapped from 0-90 degrees (in radians). Use this is cases the exact angle isn't important.

Definition at line 80 of file BLI_convexhull_2d_test.cc.

References angle(), M_PI, and mod_inline().

Referenced by TEST().

◆ convexhull_points_from_map()

blender::Array< float2 > convexhull_points_from_map ( blender::Span< float2 > points,
blender::Span< int > points_map )
static

Definition at line 51 of file BLI_convexhull_2d_test.cc.

References blender::Span< T >::size().

Referenced by convexhull_2d_as_array().

◆ mod_inline()

float mod_inline ( float a,
float b )
static

Definition at line 71 of file BLI_convexhull_2d_test.cc.

References b, and floorf.

Referenced by convexhull_aabb_canonical_angle().

◆ TEST() [1/10]

TEST ( convexhull_2d ,
Complex  )

Generate complex rotated/translated shapes with a known size. Check the rotation returned by BLI_convexhull_aabb_fit_points_2d rotates the points into a bounding box with an area no larger than generated size.

Definition at line 413 of file BLI_convexhull_2d_test.cc.

References angle(), BLI_assert, BLI_convexhull_aabb_fit_points_2d(), DEFAULT_TEST_ITER, DEFAULT_TEST_POLY_NUM, DEFAULT_TEST_RANDOM_SEED, blender::math::from_rotation(), blender::RandomNumberGenerator::get_float(), blender::RandomNumberGenerator::get_int32(), i, INIT_MINMAX2, M_PI, blender::math::min(), blender::math::min_max(), and size().

◆ TEST() [2/10]

◆ TEST() [3/10]

◆ TEST() [4/10]

◆ TEST() [5/10]

TEST ( convexhull_2d ,
Lines_Diagonal  )

◆ TEST() [6/10]

TEST ( convexhull_2d ,
NOP  )

Definition at line 128 of file BLI_convexhull_2d_test.cc.

References BLI_convexhull_aabb_fit_points_2d(), and ROTATION_EPS.

◆ TEST() [7/10]

◆ TEST() [8/10]

◆ TEST() [9/10]

◆ TEST() [10/10]