Blender V4.3
BLI_convexhull_2d_test.cc File Reference
#include "testing/testing.h"
#include "BLI_array.hh"
#include "BLI_convexhull_2d.h"
#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)
 
Wrap Public API's
static float convexhull_2d_aabb_fit_points_2d (blender::Span< float2 > points)
 
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, 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(), and TEST().

Function Documentation

◆ convexhull_2d_aabb_fit_points_2d()

static float convexhull_2d_aabb_fit_points_2d ( blender::Span< float2 > points)
static

Definition at line 78 of file BLI_convexhull_2d_test.cc.

References BLI_convexhull_aabb_fit_points_2d().

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

◆ convexhull_2d_as_array()

static blender::Array< float2 > convexhull_2d_as_array ( blender::Span< float2 > points)
static

◆ convexhull_points_from_map()

static 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().

◆ TEST() [1/9]

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 321 of file BLI_convexhull_2d_test.cc.

References BLI_assert, convexhull_2d_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(), INIT_MINMAX2, M_PI, blender::math::min(), blender::math::min_max(), and size().

◆ TEST() [2/9]

◆ TEST() [3/9]

◆ TEST() [4/9]

◆ TEST() [5/9]

TEST ( convexhull_2d ,
Lines_Diagonal  )

◆ TEST() [6/9]

TEST ( convexhull_2d ,
NOP  )

Definition at line 127 of file BLI_convexhull_2d_test.cc.

References convexhull_2d_aabb_fit_points_2d(), and ROTATION_EPS.

◆ TEST() [7/9]

◆ TEST() [8/9]

◆ TEST() [9/9]

TEST ( convexhull_2d ,
Simple  )