26 #include "../vmisc/diagnostic.h"
30 QT_WARNING_DISABLE_GCC(
"-Wold-style-cast")
31 QT_WARNING_DISABLE_CLANG("-Wold-style-cast")
32 QT_WARNING_DISABLE_GCC("-Wcast-qual")
34 #if PREDICATE == EXACT_PREDICATE
54 # define REAL_ZERO 0.0
57 # define REAL_FOUR 4.0
58 # define TOLERANCE (1024.0 * 1024.0)
60 # define REAL_ZERO 0.0f
61 # define REAL_ONE 1.0f
62 # define REAL_TWO 2.0f
63 # define REAL_FOUR 4.0f
64 # define TOLERANCE (16.0f )
67 #define EPSILON (REAL_ONE / TOLERANCE)
135 assert( p !=
nullptr );
147 assert( p !=
nullptr );
159 assert( d !=
nullptr );
170 assert( d !=
nullptr );
185 if( del->
points ==
nullptr )
234 if( pt0->
x < pt1->
x )
236 else if( pt0->
x > pt1->
x )
238 else if( pt0->
y < pt1->
y )
240 else if( pt0->
y > pt1->
y )
242 assert(0 &&
"2 or more points share the same exact coordinate");
257 spt.
x = pt->
x - s->
x;
258 spt.
y = pt->
y - s->
y;
260 res = (( se.
x * spt.
y ) - ( se.
y * spt.
x ));
295 #if PREDICATE == LOOSE_PREDICATE
299 real x0y0, x1y1, x2y2;
303 x0y0 = pt0->
x * pt0->
x + pt0->
y * pt0->
y;
304 x1y1 = pt1->
x * pt1->
x + pt1->
y * pt1->
y;
305 x2y2 = pt2->
x * pt2->
x + pt2->
y * pt2->
y;
314 ma[0][2] = ma[1][2] = ma[2][2] =
REAL_ONE;
323 mbx[0][2] = mbx[1][2] = mbx[2][2] =
REAL_ONE;
332 mby[0][2] = mby[1][2] = mby[2][2] =
REAL_ONE;
362 #if PREDICATE == EXACT_PREDICATE
371 #if PREDICATE == LOOSE_PREDICATE
373 compute_circle(pt0, pt1, pt2, &cx, &cy, &radius);
375 real distance = sqrt((p->
x - cx) * (p->
x - cx) + (p->
y - cy) * (p->
y - cy));
376 if( distance < radius -
EPSILON )
378 else if(distance > radius +
EPSILON )
382 #if PREDICATE == FAST_PREDICATE
384 real x0y0, x1y1, x2y2;
385 real a, bx, by, c, res;
388 x0y0 = pt0->
x * pt0->
x + pt0->
y * pt0->
y;
389 x1y1 = pt1->
x * pt1->
x + pt1->
y * pt1->
y;
390 x2y2 = pt2->
x * pt2->
x + pt2->
y * pt2->
y;
399 ma[0][2] = ma[1][2] = ma[2][2] =
REAL_ONE;
408 mbx[0][2] = mbx[1][2] = mbx[2][2] =
REAL_ONE;
417 mby[0][2] = mby[1][2] = mby[2][2] =
REAL_ONE;
436 res = a * (p->
x * p->
x + p->
y * p->
y ) - bx * p->
x - by * p->
y + c;
458 del->
end_point =
static_cast<quint32
>(start + 1);
462 pt1 = del->
points[start + 1];
497 del->
end_point =
static_cast<quint32
>(start + 2);
501 pt1 = del->
points[start + 1];
502 pt2 = del->
points[start + 2];
625 assert(next !=
nullptr);
626 assert(prev !=
nullptr);
634 pair->
pair =
nullptr;
645 next = orig_pair->
next;
646 prev = orig_pair->
prev;
647 pair = orig_pair->
pair;
649 assert(next !=
nullptr);
650 assert(prev !=
nullptr);
658 pair->
pair =
nullptr;
661 if( orig_pair->
vertex->
he == orig_pair )
664 orig_pair->
vertex =
nullptr;
665 orig_pair->
next =
nullptr;
666 orig_pair->
prev =
nullptr;
667 orig_pair->
pair =
nullptr;
698 assert( v != u &&
"1: floating point precision error");
709 assert( v != u &&
"2: floating point precision error");
742 assert( v != u &&
"1: floating point precision error");
753 assert( v != u &&
"1: floating point precision error");
785 if( g != g_p && d != d_p )
811 new_gd->
pair = new_dd;
818 new_dd->
pair = new_gd;
832 halfedge_t *right_d, *left_d, *new_ld, *new_rd;
858 new_ld->
pair = new_rd;
861 new_ld->
next = left_d;
862 left_d->
prev = new_ld;
865 new_rd->
pair = new_ld;
868 new_rd->
next = right_d;
869 right_d->
prev = new_rd;
926 int n = (end - start + 1);
930 int i = (n / 2) + (n & 1);
949 if( d->
face !=
nullptr )
962 }
while( curr != d );
990 del->
faces =
nullptr;
995 for( i = del->
start_point; i <= del->end_point; i++ )
1002 }
while( curr != del->
points[i]->
he );
1012 quint32* faces =
nullptr;
1016 #if PREDICATE == EXACT_PREDICATE
1022 assert( del.
points !=
nullptr );
1026 for( i = 0; i < num_points; i++ )
1036 if( num_points >= 3 ) {
1037 quint32 fbuff_size = 0;
1046 faces = (quint32*)malloc(
sizeof(quint32) * fbuff_size);
1060 }
while( curr != del.
faces[i].
he );
1066 for( i = 0; i < num_points; i++ )
void del_free_halfedges(delaunay_t *del)
real incircle(real *pa, real *pb, real *pc, real *pd)
void delaunay2d_release(delaunay2d_t *del)
static halfedge_t * del_valid_link(halfedge_t *b)
static int del_classify_point(halfedge_t *d, point2d_t *pt)
static halfedge_t * halfedge_alloc()
static int in_circle(point2d_t *pt0, point2d_t *pt1, point2d_t *pt2, point2d_t *p)
static void del_remove_edge(halfedge_t *d)
static halfedge_t * del_valid_right(halfedge_t *b)
static int classify_point_seg(point2d_t *s, point2d_t *e, point2d_t *pt)
static void point_free(point2d_t *p)
static halfedge_t * del_valid_left(halfedge_t *b)
static void halfedge_free(halfedge_t *d)
static int del_init_seg(delaunay_t *del, int start)
static void del_link(delaunay_t *result, delaunay_t *left, delaunay_t *right)
delaunay2d_t * delaunay2d_from(del_point2d_t *points, quint32 num_points)
void del_divide_and_conquer(delaunay_t *del, int start, int end)
void del_build_faces(delaunay_t *del)
static int cmp_points(const void *_pt0, const void *_pt1)
static halfedge_t * del_get_lower_tangent(delaunay_t *left, delaunay_t *right)
static int del_init_tri(delaunay_t *del, int start)
static void build_halfedge_face(delaunay_t *del, halfedge_t *d)
QT_WARNING_PUSH void exactinit()
static point2d_t * point_alloc()
halfedge_t * rightmost_he