clutter/point: Add ClutterPoint quarilateral testing API
Add a function to check whether a point is inside a quadrilateral by checking the cross product of vectors with the quadrilateral points, and the point being checked. If the passed quadrilateral is zero-sized, no point is ever reported to be inside it. This will be used by the next commit when comparing the transformed actor vertices. [feaneron: add a commit message and remove unecessary code] https://gitlab.gnome.org/GNOME/mutter/merge_requests/189
This commit is contained in:

committed by
Jonas Ådahl

parent
fdda8adfcf
commit
a70823dd1c
@ -33,6 +33,7 @@ clutter_conform_tests_general_tests = [
|
||||
'interval',
|
||||
'script-parser',
|
||||
'units',
|
||||
'point',
|
||||
]
|
||||
|
||||
clutter_conform_tests_deprecated_tests = [
|
||||
|
84
src/tests/clutter/conform/point.c
Normal file
84
src/tests/clutter/conform/point.c
Normal file
@ -0,0 +1,84 @@
|
||||
#include "tests/clutter-test-utils.h"
|
||||
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
static void
|
||||
point_on_nonempty_quadrilateral (void)
|
||||
{
|
||||
int p;
|
||||
static const ClutterPoint vertices[4] =
|
||||
{
|
||||
{ 1.f, 2.f },
|
||||
{ 6.f, 3.f },
|
||||
{ 7.f, 6.f },
|
||||
{ 0.f, 5.f }
|
||||
};
|
||||
static const ClutterPoint points_inside[] =
|
||||
{
|
||||
{ 2.f, 3.f },
|
||||
{ 1.f, 4.f },
|
||||
{ 5.f, 5.f },
|
||||
{ 4.f, 3.f },
|
||||
};
|
||||
static const ClutterPoint points_outside[] =
|
||||
{
|
||||
{ 3.f, 1.f },
|
||||
{ 7.f, 4.f },
|
||||
{ 4.f, 6.f },
|
||||
{ 99.f, -77.f },
|
||||
{ -1.f, 3.f },
|
||||
{ -8.f, -8.f },
|
||||
{ 11.f, 4.f },
|
||||
{ -7.f, 4.f },
|
||||
};
|
||||
|
||||
for (p = 0; p < G_N_ELEMENTS (points_inside); p++)
|
||||
{
|
||||
const ClutterPoint *point = &points_inside[p];
|
||||
|
||||
g_assert_true (clutter_point_inside_quadrilateral (point, vertices));
|
||||
}
|
||||
|
||||
for (p = 0; p < G_N_ELEMENTS (points_outside); p++)
|
||||
{
|
||||
const ClutterPoint *point = &points_outside[p];
|
||||
|
||||
g_assert_false (clutter_point_inside_quadrilateral (point, vertices));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
point_on_empty_quadrilateral (void)
|
||||
{
|
||||
int p;
|
||||
static const ClutterPoint vertices[4] =
|
||||
{
|
||||
{ 5.f, 6.f },
|
||||
{ 5.f, 6.f },
|
||||
{ 5.f, 6.f },
|
||||
{ 5.f, 6.f },
|
||||
};
|
||||
static const ClutterPoint points_outside[] =
|
||||
{
|
||||
{ 3.f, 1.f },
|
||||
{ 7.f, 4.f },
|
||||
{ 4.f, 6.f },
|
||||
{ 99.f, -77.f },
|
||||
{ -1.f, 3.f },
|
||||
{ -8.f, -8.f },
|
||||
};
|
||||
|
||||
for (p = 0; p < G_N_ELEMENTS (points_outside); p++)
|
||||
{
|
||||
const ClutterPoint *point = &points_outside[p];
|
||||
|
||||
g_assert_false (clutter_point_inside_quadrilateral (point, vertices));
|
||||
}
|
||||
|
||||
g_assert_false (clutter_point_inside_quadrilateral (&vertices[0], vertices));
|
||||
}
|
||||
|
||||
CLUTTER_TEST_SUITE (
|
||||
CLUTTER_TEST_UNIT ("/point/on_nonempty_quadrilateral", point_on_nonempty_quadrilateral)
|
||||
CLUTTER_TEST_UNIT ("/point/on_empty_quadrilateral", point_on_empty_quadrilateral)
|
||||
)
|
Reference in New Issue
Block a user