45#define CROSS(v0, v1, v2) (((v1).x - (v0).x)*((v2).y - (v0).y) - \
46 ((v1).y - (v0).y)*((v2).x - (v0).x))
113 else if (v0->
y < v1->
y -
C_EPS)
116 return v0->
x >= v1->
x;
221 s->is_inserted =
true;
252 area =
CROSS(
s->v0,
s->v1, *v);
271 area =
CROSS(
s->v1,
s->v0, (*v));
336 fprintf(stderr,
"unexpected case in locate_endpoint\n");
362 cond = ((tnext = tr->
data[t].
d0) > 0 && tr->
data[tnext].
rseg == segnum) ||
365 cond = ((tnext = tr->
data[t].
d0) > 0 && tr->
data[tnext].
lseg == segnum) ||
454 int tmp_u = tr->
data[t].
u0;
456 if ((td0 = tr->
data[tmp_u].
d0) > 0 && (td1 = tr->
data[tmp_u].
d1) > 0)
488 int tu, tl, sk, tfirst, tlast;
489 int tfirstr = 0, tlastr = 0, tfirstl = 0, tlastl = 0;
508 else is_swapped =
false;
528 if ((tmp_d = tr->
data[tl].
d0) > 0 && tr->
data[tmp_d].
u0 == tu)
530 if ((tmp_d = tr->
data[tl].
d0) > 0 && tr->
data[tmp_d].
u1 == tu)
533 if ((tmp_d = tr->
data[tl].
d1) > 0 && tr->
data[tmp_d].
u0 == tu)
535 if ((tmp_d = tr->
data[tl].
d1) > 0 && tr->
data[tmp_d].
u1 == tu)
586 if ((tmp_d = tr->
data[tl].
d0) > 0 && tr->
data[tmp_d].
u0 == tu)
588 if ((tmp_d = tr->
data[tl].
d0) > 0 && tr->
data[tmp_d].
u1 == tu)
591 if ((tmp_d = tr->
data[tl].
d1) > 0 && tr->
data[tmp_d].
u0 == tu)
593 if ((tmp_d = tr->
data[tl].
d1) > 0 && tr->
data[tmp_d].
u1 == tu)
670 fprintf(stderr,
"add_segment: error\n");
687 tmptriseg = seg[segnum].
prev;
689 tmptriseg = seg[segnum].
next;
691 if (tmptriseg > 0 &&
is_left_of(tmptriseg, seg, &
s.v0))
738 tmptriseg = seg[segnum].
prev;
740 tmptriseg = seg[segnum].
next;
742 if (tmptriseg > 0 &&
is_left_of(tmptriseg, seg, &
s.v0))
800 yt = (y0 -
s.v0.y)/(
s.v1.y -
s.v0.y);
801 tmppt.
x =
s.v0.x + yt * (
s.v1.x -
s.v0.x);
891 if (
s->is_inserted)
return;
906 for (i = 0, v = (
double) n; v >= 1; i++)
917 for (i = 0, v = (
double) n; i < h; i++)
920 return (
int) ceil((
double) 1.0*n/v);
942 for (i = 1; i <= nseg; i++)
943 seg[i].root0 = seg[i].root1 = root;
946 for (i =
math_N(nseg, h -1) + 1; i <=
math_N(nseg, h); i++)
950 for (i = 1; i <= nseg; i++)
Memory allocation wrappers that exit on failure.
static void * gv_recalloc(void *ptr, size_t old_nmemb, size_t new_nmemb, size_t size)
static void * gv_calloc(size_t nmemb, size_t size)
geometric types and macros (e.g. points and boxes)
trapezoid elements and utilities for partition.c
#define _equal_to(v0, v1)
#define _greater_than(v0, v1)
static bool _less_than(pointf *v0, pointf *v1)
static void merge_trapezoids(int segnum, int tfirst, int tlast, int side, traps_t *tr, qnodes_t *qs)
static void _max(pointf *yval, pointf *v0, pointf *v1)
static int newnode(qnodes_t *qs)
static int math_logstar_n(int n)
static int math_N(int n, int h)
static void update_trapezoid(segment_t *s, segment_t *seg, traps_t *tr, int t, int tn)
static bool _greater_than_equal_to(pointf *v0, pointf *v1)
#define CROSS(v0, v1, v2)
static void find_new_roots(int segnum, segment_t *seg, traps_t *tr, qnodes_t *qs)
static int newtrap(traps_t *tr)
traps_t construct_trapezoids(int nseg, segment_t *seg, int *permute)
static int init_query_structure(int segnum, segment_t *seg, traps_t *tr, qnodes_t *qs)
static bool inserted(int segnum, segment_t *seg, int whichpt)
static bool is_left_of(int segnum, segment_t *seg, pointf *v)
static int locate_endpoint(pointf *v, pointf *vo, int r, segment_t *seg, qnodes_t *qs)
static void add_segment(int segnum, segment_t *seg, traps_t *tr, qnodes_t *qs)
static void _min(pointf *yval, pointf *v0, pointf *v1)
graphs, nodes and edges info: Agraphinfo_t, Agnodeinfo_t and Agedgeinfo_t