Commit e9985077 authored by Alexey Botchkov's avatar Alexey Botchkov

GIS library code cleanup.

GCALC_DBUG_OFF and related infrastructure defined so we can enable/disable debugging conveniently.

per-file comments:
  sql/gcalc_slicescan.cc
GIS library code cleanup.
  sql/gcalc_slicescan.h
GIS library code cleanup.
  sql/gcalc_tools.cc
GIS library code cleanup.
  sql/gcalc_tools.h
GIS library code cleanup.
parent 6e7d578b
...@@ -39,6 +39,99 @@ typedef int (*sc_compare_func)(const void*, const void*); ...@@ -39,6 +39,99 @@ typedef int (*sc_compare_func)(const void*, const void*);
#include "plistsort.c" #include "plistsort.c"
#ifndef GCALC_DBUG_OFF
int gcalc_step_counter= 0;
void GCALC_DBUG_CHECK_COUNTER()
{
if (++gcalc_step_counter == 0)
GCALC_DBUG_PRINT(("step_counter_0"));
else
GCALC_DBUG_PRINT(("%d step_counter", gcalc_step_counter));
}
const char *gcalc_ev_name(int ev)
{
switch (ev)
{
case scev_none:
return "n";
case scev_thread:
return "t";
case scev_two_threads:
return "tt";
case scev_end:
return "e";
case scev_two_ends:
return "ee";
case scev_intersection:
return "i";
case scev_point:
return "p";
case scev_single_point:
return "sp";
default:;
};
GCALC_DBUG_ASSERT(0);
return "unk";
}
static void GCALC_DBUG_PRINT_SLICE(const char *header,
const Gcalc_scan_iterator::point *slice)
{
int nbuf1, nbuf2;
char buf1[1024], buf2[1024];
nbuf1= nbuf2= strlen(header);
strcpy(buf1, header);
strcpy(buf2, header);
for (; slice; slice= slice->get_next())
{
nbuf1+= sprintf(buf1+nbuf1, "%d\t", slice->thread);
nbuf2+= sprintf(buf2+nbuf2, "%s\t", gcalc_ev_name(slice->event));
}
buf1[nbuf1]= 0;
buf2[nbuf2]= 0;
GCALC_DBUG_PRINT((buf1));
GCALC_DBUG_PRINT((buf2));
}
static void GCALC_DBUG_PRINT_INTERSECTIONS(
Gcalc_scan_iterator::intersection *isc)
{
for (; isc; isc= isc->get_next())
{
long double ix, iy;
isc->ii->calc_xy_ld(&ix, &iy);
GCALC_DBUG_PRINT(("%d %d %d %.8LG %.8LG", isc->thread_a, isc->thread_b,
isc->n_row, ix, iy));
}
}
static void GCALC_DBUG_PRINT_STATE(Gcalc_scan_iterator::slice_state *s)
{
if (s->event_position)
GCALC_DBUG_PRINT(("%d %d %d", s->event_position->thread,
((Gcalc_scan_iterator::point *) *s->event_position_hook)->thread,
*s->event_end_hook ?
((Gcalc_scan_iterator::point *) *s->event_end_hook)->thread : -1));
else
GCALC_DBUG_PRINT(("position null"));
}
#else
#define GCALC_DBUG_CHECK_COUNTER(a) do { } while(0)
#define GCALC_DBUG_PRINT_SLICE(a, b) do { } while(0)
#define GCALC_DBUG_PRINT_INTERSECTIONS(a) do { } while(0)
#define GCALC_DBUG_PRINT_STATE(a) do { } while(0)
#endif /*GCALC_DBUG_OFF*/
Gcalc_dyn_list::Gcalc_dyn_list(size_t blk_size, size_t sizeof_item): Gcalc_dyn_list::Gcalc_dyn_list(size_t blk_size, size_t sizeof_item):
m_blk_size(blk_size - ALLOC_ROOT_MIN_BLOCK_SIZE), m_blk_size(blk_size - ALLOC_ROOT_MIN_BLOCK_SIZE),
m_sizeof_item(ALIGN_SIZE(sizeof_item)), m_sizeof_item(ALIGN_SIZE(sizeof_item)),
...@@ -52,7 +145,7 @@ Gcalc_dyn_list::Gcalc_dyn_list(size_t blk_size, size_t sizeof_item): ...@@ -52,7 +145,7 @@ Gcalc_dyn_list::Gcalc_dyn_list(size_t blk_size, size_t sizeof_item):
void Gcalc_dyn_list::format_blk(void* block) void Gcalc_dyn_list::format_blk(void* block)
{ {
Item *pi_end, *cur_pi, *first_pi; Item *pi_end, *cur_pi, *first_pi;
DBUG_ASSERT(m_free == NULL); GCALC_DBUG_ASSERT(m_free == NULL);
first_pi= cur_pi= (Item *)(((char *)block) + PH_DATA_OFFSET); first_pi= cur_pi= (Item *)(((char *)block) + PH_DATA_OFFSET);
pi_end= ptr_add(first_pi, m_points_per_blk - 1); pi_end= ptr_add(first_pi, m_points_per_blk - 1);
do { do {
...@@ -170,8 +263,8 @@ static void do_add(Gcalc_internal_coord *result, ...@@ -170,8 +263,8 @@ static void do_add(Gcalc_internal_coord *result,
const Gcalc_internal_coord *a, const Gcalc_internal_coord *a,
const Gcalc_internal_coord *b) const Gcalc_internal_coord *b)
{ {
DBUG_ASSERT(a->n_digits == b->n_digits); GCALC_DBUG_ASSERT(a->n_digits == b->n_digits);
DBUG_ASSERT(a->n_digits == result->n_digits); GCALC_DBUG_ASSERT(a->n_digits == result->n_digits);
int n_digit= a->n_digits-1; int n_digit= a->n_digits-1;
coord_digit_t carry= 0; coord_digit_t carry= 0;
...@@ -186,7 +279,7 @@ static void do_add(Gcalc_internal_coord *result, ...@@ -186,7 +279,7 @@ static void do_add(Gcalc_internal_coord *result,
else else
carry= 0; carry= 0;
} while (n_digit--); } while (n_digit--);
DBUG_ASSERT(carry == 0); GCALC_DBUG_ASSERT(carry == 0);
result->sign= a->sign; result->sign= a->sign;
} }
...@@ -195,8 +288,8 @@ static void do_sub(Gcalc_internal_coord *result, ...@@ -195,8 +288,8 @@ static void do_sub(Gcalc_internal_coord *result,
const Gcalc_internal_coord *a, const Gcalc_internal_coord *a,
const Gcalc_internal_coord *b) const Gcalc_internal_coord *b)
{ {
DBUG_ASSERT(a->n_digits == b->n_digits); GCALC_DBUG_ASSERT(a->n_digits == b->n_digits);
DBUG_ASSERT(a->n_digits == result->n_digits); GCALC_DBUG_ASSERT(a->n_digits == result->n_digits);
int n_digit= a->n_digits-1; int n_digit= a->n_digits-1;
coord_digit_t carry= 0; coord_digit_t carry= 0;
...@@ -211,7 +304,7 @@ static void do_sub(Gcalc_internal_coord *result, ...@@ -211,7 +304,7 @@ static void do_sub(Gcalc_internal_coord *result,
else else
carry= 0; carry= 0;
} while (n_digit--); } while (n_digit--);
DBUG_ASSERT(carry == 0); GCALC_DBUG_ASSERT(carry == 0);
if (a->sign && result->is_zero()) if (a->sign && result->is_zero())
result->sign= 0; result->sign= 0;
else else
...@@ -222,7 +315,7 @@ static void do_sub(Gcalc_internal_coord *result, ...@@ -222,7 +315,7 @@ static void do_sub(Gcalc_internal_coord *result,
static int do_cmp(const Gcalc_internal_coord *a, static int do_cmp(const Gcalc_internal_coord *a,
const Gcalc_internal_coord *b) const Gcalc_internal_coord *b)
{ {
DBUG_ASSERT(a->n_digits == b->n_digits); GCALC_DBUG_ASSERT(a->n_digits == b->n_digits);
int n_digit= 0; int n_digit= 0;
do do
...@@ -243,23 +336,11 @@ static int do_cmp(const Gcalc_internal_coord *a, ...@@ -243,23 +336,11 @@ static int do_cmp(const Gcalc_internal_coord *a,
static int de_check(long double a, long double b) static int de_check(long double a, long double b)
{ {
long double d= a - b; long double d= a - b;
if (d < (long double) 1e-6 && d > (long double) -1e-6) if (d < (long double) 1e-10 && d > (long double) -1e-10)
return 1; return 1;
printf("xxx\n");
return 0;
}
static int de_check1(long double a, long double b) d/= fabsl(a) + fabsl(b);
{ if (d < (long double) 1e-10 && d > (long double) -1e-10)
long double d= a - b;
if (d < (long double) 1e-6 && d > (long double) -1e-6)
return 1;
return 0;
}
static int de_weak(long double a, long double b)
{
long double d= a - b;
if (d < (long double) 1 && d > (long double) -1)
return 1; return 1;
return 0; return 0;
} }
...@@ -270,7 +351,7 @@ void gcalc_mul_coord(Gcalc_internal_coord *result, ...@@ -270,7 +351,7 @@ void gcalc_mul_coord(Gcalc_internal_coord *result,
const Gcalc_internal_coord *a, const Gcalc_internal_coord *a,
const Gcalc_internal_coord *b) const Gcalc_internal_coord *b)
{ {
DBUG_ASSERT(result->n_digits == a->n_digits + b->n_digits); GCALC_DBUG_ASSERT(result->n_digits == a->n_digits + b->n_digits);
int n_a, n_b, n_res; int n_a, n_b, n_res;
coord_digit_t carry= 0; coord_digit_t carry= 0;
...@@ -301,7 +382,7 @@ void gcalc_mul_coord(Gcalc_internal_coord *result, ...@@ -301,7 +382,7 @@ void gcalc_mul_coord(Gcalc_internal_coord *result,
} while (n_a--); } while (n_a--);
result->sign= a->sign != b->sign; result->sign= a->sign != b->sign;
#ifdef GCALC_CHECK_WITH_FLOAT #ifdef GCALC_CHECK_WITH_FLOAT
DBUG_ASSERT(de_check(a->get_double() * b->get_double(), GCALC_DBUG_ASSERT(de_check(a->get_double() * b->get_double(),
result->get_double())); result->get_double()));
#endif /*GCALC_CHECK_WITH_FLOAT*/ #endif /*GCALC_CHECK_WITH_FLOAT*/
} }
...@@ -324,7 +405,7 @@ void gcalc_add_coord(Gcalc_internal_coord *result, ...@@ -324,7 +405,7 @@ void gcalc_add_coord(Gcalc_internal_coord *result,
do_sub(result, b, a); do_sub(result, b, a);
} }
#ifdef GCALC_CHECK_WITH_FLOAT #ifdef GCALC_CHECK_WITH_FLOAT
DBUG_ASSERT(de_check(a->get_double() + b->get_double(), GCALC_DBUG_ASSERT(de_check(a->get_double() + b->get_double(),
result->get_double())); result->get_double()));
#endif /*GCALC_CHECK_WITH_FLOAT*/ #endif /*GCALC_CHECK_WITH_FLOAT*/
} }
...@@ -350,7 +431,7 @@ void gcalc_sub_coord(Gcalc_internal_coord *result, ...@@ -350,7 +431,7 @@ void gcalc_sub_coord(Gcalc_internal_coord *result,
} }
} }
#ifdef GCALC_CHECK_WITH_FLOAT #ifdef GCALC_CHECK_WITH_FLOAT
DBUG_ASSERT(de_check(a->get_double() - b->get_double(), GCALC_DBUG_ASSERT(de_check(a->get_double() - b->get_double(),
result->get_double())); result->get_double()));
#endif /*GCALC_CHECK_WITH_FLOAT*/ #endif /*GCALC_CHECK_WITH_FLOAT*/
} }
...@@ -365,12 +446,12 @@ int gcalc_cmp_coord(const Gcalc_internal_coord *a, ...@@ -365,12 +446,12 @@ int gcalc_cmp_coord(const Gcalc_internal_coord *a,
result= a->sign ? do_cmp(b, a) : do_cmp(a, b); result= a->sign ? do_cmp(b, a) : do_cmp(a, b);
#ifdef GCALC_CHECK_WITH_FLOAT #ifdef GCALC_CHECK_WITH_FLOAT
if (result == 0) if (result == 0)
DBUG_ASSERT(de_check(a->get_double(), b->get_double())); GCALC_DBUG_ASSERT(de_check(a->get_double(), b->get_double()));
else if (result == 1) else if (result == 1)
DBUG_ASSERT(de_check1(a->get_double(), b->get_double()) || GCALC_DBUG_ASSERT(de_check(a->get_double(), b->get_double()) ||
a->get_double() > b->get_double()); a->get_double() > b->get_double());
else else
DBUG_ASSERT(de_check1(a->get_double(), b->get_double()) || GCALC_DBUG_ASSERT(de_check(a->get_double(), b->get_double()) ||
a->get_double() < b->get_double()); a->get_double() < b->get_double());
#endif /*GCALC_CHECK_WITH_FLOAT*/ #endif /*GCALC_CHECK_WITH_FLOAT*/
return result; return result;
...@@ -386,7 +467,7 @@ int Gcalc_coord1::set_double(double d) ...@@ -386,7 +467,7 @@ int Gcalc_coord1::set_double(double d)
c[0]= (coord_digit_t) (ds / (double) DIG_BASE); c[0]= (coord_digit_t) (ds / (double) DIG_BASE);
c[1]= (coord_digit_t) (ds - ((double) c[0]) * DIG_BASE); c[1]= (coord_digit_t) (ds - ((double) c[0]) * DIG_BASE);
#ifdef GCALC_CHECK_WITH_FLOAT #ifdef GCALC_CHECK_WITH_FLOAT
DBUG_ASSERT(de_check(d, get_double())); GCALC_DBUG_ASSERT(de_check(d, get_double()));
#endif /*GCALC_CHECK_WITH_FLOAT*/ #endif /*GCALC_CHECK_WITH_FLOAT*/
return 0; return 0;
} }
...@@ -564,7 +645,7 @@ static inline void trim_node(Gcalc_heap::Info *node, Gcalc_heap::Info *prev_node ...@@ -564,7 +645,7 @@ static inline void trim_node(Gcalc_heap::Info *node, Gcalc_heap::Info *prev_node
{ {
if (!node) if (!node)
return; return;
DBUG_ASSERT((node->left == prev_node) || (node->right == prev_node)); GCALC_DBUG_ASSERT((node->left == prev_node) || (node->right == prev_node));
if (node->left == prev_node) if (node->left == prev_node)
node->left= node->right; node->left= node->right;
node->right= NULL; node->right= NULL;
...@@ -591,7 +672,7 @@ static int compare_point_info(const void *e0, const void *e1) ...@@ -591,7 +672,7 @@ static int compare_point_info(const void *e0, const void *e1)
void Gcalc_heap::prepare_operation() void Gcalc_heap::prepare_operation()
{ {
DBUG_ASSERT(m_hook); GCALC_DBUG_ASSERT(m_hook);
*m_hook= NULL; *m_hook= NULL;
m_first= sort_list(compare_point_info, m_first, m_n_points); m_first= sort_list(compare_point_info, m_first, m_n_points);
m_hook= NULL; /* just to check it's not called twice */ m_hook= NULL; /* just to check it's not called twice */
...@@ -644,7 +725,7 @@ int Gcalc_shape_transporter::int_add_point(gcalc_shape_info Info, ...@@ -644,7 +725,7 @@ int Gcalc_shape_transporter::int_add_point(gcalc_shape_info Info,
double x, double y) double x, double y)
{ {
Gcalc_heap::Info *point; Gcalc_heap::Info *point;
DBUG_ASSERT(!m_prev || m_prev->x != x || m_prev->y != y); GCALC_DBUG_ASSERT(!m_prev || m_prev->x != x || m_prev->y != y);
if (!(point= m_heap->new_point_info(x, y, Info))) if (!(point= m_heap->new_point_info(x, y, Info)))
return 1; return 1;
...@@ -662,7 +743,7 @@ int Gcalc_shape_transporter::int_add_point(gcalc_shape_info Info, ...@@ -662,7 +743,7 @@ int Gcalc_shape_transporter::int_add_point(gcalc_shape_info Info,
void Gcalc_shape_transporter::int_complete() void Gcalc_shape_transporter::int_complete()
{ {
DBUG_ASSERT(m_shape_started == 1 || m_shape_started == 3); GCALC_DBUG_ASSERT(m_shape_started == 1 || m_shape_started == 3);
if (!m_first) if (!m_first)
return; return;
...@@ -683,28 +764,28 @@ void Gcalc_shape_transporter::int_complete() ...@@ -683,28 +764,28 @@ void Gcalc_shape_transporter::int_complete()
return; return;
} }
DBUG_ASSERT(m_prev->x != m_first->x || m_prev->y != m_first->y); GCALC_DBUG_ASSERT(m_prev->x != m_first->x || m_prev->y != m_first->y);
/* polygon */ /* polygon */
m_first->right= m_prev; m_first->right= m_prev;
m_prev->left= m_first; m_prev->left= m_first;
} }
#ifdef TMP_BLOCK
inline int GET_DX_DY(double *dxdy,
const Gcalc_heap::Info *p0, const Gcalc_heap::Info *p1)
{
double dy= p1->y - p0->y;
*dxdy= p1->x - p0->x;
return (dy == 0.0) ||
(*dxdy/= dy)>DBL_MAX ||
(*dxdy)<-DBL_MAX;
}
#endif /*TMP_BLOCK*/
inline void calc_dx_dy(Gcalc_scan_iterator::point *p) inline void calc_dx_dy(Gcalc_scan_iterator::point *p)
{ {
gcalc_sub_coord(&p->dx, &p->next_pi->ix, &p->pi->ix); gcalc_sub_coord(&p->dx, &p->next_pi->ix, &p->pi->ix);
gcalc_sub_coord(&p->dy, &p->next_pi->iy, &p->pi->iy); gcalc_sub_coord(&p->dy, &p->next_pi->iy, &p->pi->iy);
if (p->dx.sign)
{
p->l_border= &p->next_pi->ix;
p->r_border= &p->pi->ix;
}
else
{
p->r_border= &p->next_pi->ix;
p->l_border= &p->pi->ix;
}
p->always_on_left= 0;
} }
...@@ -732,8 +813,8 @@ Gcalc_scan_iterator::point ...@@ -732,8 +813,8 @@ Gcalc_scan_iterator::point
void Gcalc_scan_iterator::init(Gcalc_heap *points) void Gcalc_scan_iterator::init(Gcalc_heap *points)
{ {
DBUG_ASSERT(points->ready()); GCALC_DBUG_ASSERT(points->ready());
DBUG_ASSERT(!state0.slice && !state1.slice); GCALC_DBUG_ASSERT(!state0.slice && !state1.slice);
if (!(m_cur_pi= points->get_first())) if (!(m_cur_pi= points->get_first()))
return; return;
...@@ -746,9 +827,6 @@ void Gcalc_scan_iterator::init(Gcalc_heap *points) ...@@ -746,9 +827,6 @@ void Gcalc_scan_iterator::init(Gcalc_heap *points)
current_state= &state0; current_state= &state0;
next_state= &state1; next_state= &state1;
saved_state= &state_s; saved_state= &state_s;
#ifdef TMP_BLOCK
next_state->y= m_cur_pi->y;
#endif /*TMP_BLOCK*/
next_state->intersection_scan= 0; next_state->intersection_scan= 0;
next_state->pi= m_cur_pi; next_state->pi= m_cur_pi;
} }
...@@ -763,18 +841,13 @@ void Gcalc_scan_iterator::reset() ...@@ -763,18 +841,13 @@ void Gcalc_scan_iterator::reset()
void Gcalc_scan_iterator::point::copy_core(const point *from) void Gcalc_scan_iterator::point::copy_core(const point *from)
{ {
#ifdef TMP_BLOCK
dx_dy= from->dx_dy;
horiz_dir= from->horiz_dir;
#endif /*TMP_BLOCK*/
pi= from->pi; pi= from->pi;
next_pi= from->next_pi; next_pi= from->next_pi;
thread= from->thread; thread= from->thread;
dx.copy(&from->dx); dx.copy(&from->dx);
dy.copy(&from->dy); dy.copy(&from->dy);
#ifdef TO_REMOVE l_border= from->l_border;
from->next_link= this; r_border= from->r_border;
#endif /*TO_REMOVE*/
} }
...@@ -787,35 +860,11 @@ void Gcalc_scan_iterator::point::copy_all(const point *from) ...@@ -787,35 +860,11 @@ void Gcalc_scan_iterator::point::copy_all(const point *from)
dy.copy(&from->dy); dy.copy(&from->dy);
intersection_link= from->intersection_link; intersection_link= from->intersection_link;
event= from->event; event= from->event;
} l_border= from->l_border;
#ifdef TMP_BLOCK r_border= from->r_border;
int Gcalc_scan_iterator::point::cmp_dx_dy(int horiz_dir_a, double dx_dy_a,
int horiz_dir_b, double dx_dy_b)
{
if (!horiz_dir_a && !horiz_dir_b)
{
if (coord_eq(dx_dy_a, dx_dy_b))
return 0;
return dx_dy_a < dx_dy_b ? -1 : 1;
}
if (!horiz_dir_a)
return -1;
if (!horiz_dir_b)
return 1;
return 0;
} }
int Gcalc_scan_iterator::point::cmp_dx_dy(const point *p) const
{
if (is_bottom())
return p->is_bottom() ? 0 : -1;
if (p->is_bottom())
return 1;
return cmp_dx_dy(horiz_dir, dx_dy, p->horiz_dir, p->dx_dy);
}
#endif /*TMP_BLOCK*/
int Gcalc_scan_iterator::point::cmp_dx_dy(const Gcalc_coord1 *dx_a, int Gcalc_scan_iterator::point::cmp_dx_dy(const Gcalc_coord1 *dx_a,
const Gcalc_coord1 *dy_a, const Gcalc_coord1 *dy_a,
const Gcalc_coord1 *dx_b, const Gcalc_coord1 *dx_b,
...@@ -899,15 +948,15 @@ static int cmp_sp_pi(const Gcalc_scan_iterator::point *sp, ...@@ -899,15 +948,15 @@ static int cmp_sp_pi(const Gcalc_scan_iterator::point *sp,
long double sp_x; long double sp_x;
sp->calc_x(&sp_x, pi->y, pi->x); sp->calc_x(&sp_x, pi->y, pi->x);
if (result == 0) if (result == 0)
DBUG_ASSERT(de_check1(sp->dy.get_double(), 0.0) || GCALC_DBUG_ASSERT(de_check(sp->dy.get_double(), 0.0) ||
de_check(sp_x, pi->x)); de_check(sp_x, pi->x));
if (result < 0) if (result < 0)
DBUG_ASSERT(de_check1(sp->dy.get_double(), 0.0) || GCALC_DBUG_ASSERT(de_check(sp->dy.get_double(), 0.0) ||
de_check1(sp_x, pi->x) || de_check(sp_x, pi->x) ||
sp_x < pi->x); sp_x < pi->x);
if (result > 0) if (result > 0)
DBUG_ASSERT(de_check1(sp->dy.get_double(), 0.0) || GCALC_DBUG_ASSERT(de_check(sp->dy.get_double(), 0.0) ||
de_check1(sp_x, pi->x) || de_check(sp_x, pi->x) ||
sp_x > pi->x); sp_x > pi->x);
#endif /*GCALC_CHECK_WITH_FLOAT*/ #endif /*GCALC_CHECK_WITH_FLOAT*/
return result; return result;
...@@ -954,11 +1003,11 @@ static int cmp_sp_sp_cnt(const Gcalc_scan_iterator::point *a, ...@@ -954,11 +1003,11 @@ static int cmp_sp_sp_cnt(const Gcalc_scan_iterator::point *a,
a->calc_x(&a_x, y->get_double(), 0); a->calc_x(&a_x, y->get_double(), 0);
b->calc_x(&b_x, y->get_double(), 0); b->calc_x(&b_x, y->get_double(), 0);
if (result == 0) if (result == 0)
DBUG_ASSERT(de_check(a_x, b_x)); GCALC_DBUG_ASSERT(de_check(a_x, b_x));
if (result < 0) if (result < 0)
DBUG_ASSERT(de_check1(a_x, b_x) || a_x < b_x); GCALC_DBUG_ASSERT(de_check(a_x, b_x) || a_x < b_x);
if (result > 0) if (result > 0)
DBUG_ASSERT(de_check1(a_x, b_x) || a_x > b_x); GCALC_DBUG_ASSERT(de_check(a_x, b_x) || a_x > b_x);
#endif /*GCALC_CHECK_WITH_FLOAT*/ #endif /*GCALC_CHECK_WITH_FLOAT*/
return result; return result;
} }
...@@ -1009,8 +1058,8 @@ int Gcalc_scan_iterator::arrange_event() ...@@ -1009,8 +1058,8 @@ int Gcalc_scan_iterator::arrange_event()
if (m_events) if (m_events)
free_list(m_events); free_list(m_events);
ev_counter= 0; ev_counter= 0;
DBUG_ASSERT(current_state->event_position == GCALC_DBUG_ASSERT(current_state->event_position ==
*current_state->event_position_hook); *current_state->event_position_hook);
for (sp= current_state->event_position; for (sp= current_state->event_position;
sp != *current_state->event_end_hook; sp= sp->get_next()) sp != *current_state->event_end_hook; sp= sp->get_next())
{ {
...@@ -1021,9 +1070,6 @@ int Gcalc_scan_iterator::arrange_event() ...@@ -1021,9 +1070,6 @@ int Gcalc_scan_iterator::arrange_event()
new_sp->copy_all(sp); new_sp->copy_all(sp);
*ae_hook= new_sp; *ae_hook= new_sp;
ae_hook= &new_sp->next; ae_hook= &new_sp->next;
#ifdef TO_REMOVE
sp->intersection_link= new_sp;
#endif /*TO_REMOVE*/
ev_counter++; ev_counter++;
} }
*ae_hook= NULL; *ae_hook= NULL;
...@@ -1036,7 +1082,10 @@ int Gcalc_scan_iterator::arrange_event() ...@@ -1036,7 +1082,10 @@ int Gcalc_scan_iterator::arrange_event()
after_event= (point *) sort_list(compare_events, after_event, ev_counter); after_event= (point *) sort_list(compare_events, after_event, ev_counter);
/* Find last item in the list, ae_hook can change after the sorting */ /* Find last item in the list, ae_hook can change after the sorting */
for (cur_p= after_event->get_next(); cur_p->get_next(); for (cur_p= after_event->get_next(); cur_p->get_next();
cur_p= cur_p->get_next()); cur_p= cur_p->get_next())
{
cur_p->always_on_left= 1;
}
ae_hook= &cur_p->next; ae_hook= &cur_p->next;
} }
...@@ -1067,14 +1116,12 @@ int Gcalc_scan_iterator::insert_top_point() ...@@ -1067,14 +1116,12 @@ int Gcalc_scan_iterator::insert_top_point()
point *sp0= new_slice_point(); point *sp0= new_slice_point();
point *sp_inc; point *sp_inc;
GCALC_DBUG_ENTER("Gcalc_scan_iterator::insert_top_point");
if (!sp0) if (!sp0)
return 1; GCALC_DBUG_RETURN(1);
sp0->pi= m_cur_pi; sp0->pi= m_cur_pi;
sp0->next_pi= m_cur_pi->left; sp0->next_pi= m_cur_pi->left;
sp0->thread= m_cur_thread++; sp0->thread= m_cur_thread++;
#ifdef TMP_BLOCK
sp0->x= coord_to_float(m_cur_pi->x);
#endif /*TMP_BLOCK*/
if (m_cur_pi->left) if (m_cur_pi->left)
{ {
calc_dx_dy(sp0); calc_dx_dy(sp0);
...@@ -1082,20 +1129,17 @@ int Gcalc_scan_iterator::insert_top_point() ...@@ -1082,20 +1129,17 @@ int Gcalc_scan_iterator::insert_top_point()
/*Now just to increase the size of m_slice0 to be same*/ /*Now just to increase the size of m_slice0 to be same*/
if (!(sp_inc= new_slice_point())) if (!(sp_inc= new_slice_point()))
return 1; GCALC_DBUG_RETURN(1);
sp_inc->next= current_state->slice; sp_inc->next= current_state->slice;
current_state->slice= sp_inc; current_state->slice= sp_inc;
if (m_cur_pi->right) if (m_cur_pi->right)
{ {
if (!(sp1= new_slice_point())) if (!(sp1= new_slice_point()))
return 1; GCALC_DBUG_RETURN(1);
sp1->event= sp0->event= scev_two_threads; sp1->event= sp0->event= scev_two_threads;
sp1->pi= m_cur_pi; sp1->pi= m_cur_pi;
sp1->next_pi= m_cur_pi->right; sp1->next_pi= m_cur_pi->right;
sp1->thread= m_cur_thread++; sp1->thread= m_cur_thread++;
#ifdef TMP_BLOCK
sp1->x= sp0->x;
#endif /*TMP_BLOCK*/
calc_dx_dy(sp1); calc_dx_dy(sp1);
/* We have two threads so should decide which one will be first */ /* We have two threads so should decide which one will be first */
if (sp0->cmp_dx_dy(sp1)>0) if (sp0->cmp_dx_dy(sp1)>0)
...@@ -1107,7 +1151,7 @@ int Gcalc_scan_iterator::insert_top_point() ...@@ -1107,7 +1151,7 @@ int Gcalc_scan_iterator::insert_top_point()
/*Now just to increase the size of m_slice0 to be same*/ /*Now just to increase the size of m_slice0 to be same*/
if (!(sp_inc= new_slice_point())) if (!(sp_inc= new_slice_point()))
return 1; GCALC_DBUG_RETURN(1);
sp_inc->next= current_state->slice; sp_inc->next= current_state->slice;
current_state->slice= sp_inc; current_state->slice= sp_inc;
} }
...@@ -1115,10 +1159,6 @@ int Gcalc_scan_iterator::insert_top_point() ...@@ -1115,10 +1159,6 @@ int Gcalc_scan_iterator::insert_top_point()
else else
{ {
sp0->event= scev_single_point; sp0->event= scev_single_point;
#ifdef TMP_BLOCK
sp0->horiz_dir= 0;
sp0->dx_dy= 0.0;
#endif /*TMP_BLOCK*/
} }
...@@ -1154,36 +1194,10 @@ int Gcalc_scan_iterator::insert_top_point() ...@@ -1154,36 +1194,10 @@ int Gcalc_scan_iterator::insert_top_point()
sp0->next= sp; sp0->next= sp;
next_state->event_end_hook= &sp0->next; next_state->event_end_hook= &sp0->next;
} }
return 0; GCALC_DBUG_RETURN(0);
} }
#ifndef NO_TESTING
const char *pev(int ev)
{
switch (ev)
{
case scev_none:
return "n";
case scev_thread:
return "t";
case scev_two_threads:
return "tt";
case scev_end:
return "e";
case scev_two_ends:
return "ee";
case scev_intersection:
return "i";
case scev_point:
return "p";
case scev_single_point:
return "sp";
};
return "fck";
}
extern int ca_counter;
#endif /*NO_TESTING*/
int Gcalc_scan_iterator::normal_scan() int Gcalc_scan_iterator::normal_scan()
{ {
point *sp; point *sp;
...@@ -1191,13 +1205,17 @@ int Gcalc_scan_iterator::normal_scan() ...@@ -1191,13 +1205,17 @@ int Gcalc_scan_iterator::normal_scan()
Gcalc_heap::Info *next_pi; Gcalc_heap::Info *next_pi;
point *first_bottom_point; point *first_bottom_point;
GCALC_DBUG_ENTER("Gcalc_scan_iterator::normal_scan");
GCALC_DBUG_CHECK_COUNTER();
GCALC_DBUG_PRINT_SLICE("in\t", next_state->slice);
if (m_next_is_top_point && insert_top_point()) if (m_next_is_top_point && insert_top_point())
return 1; GCALC_DBUG_RETURN(1);
for (next_pi= m_cur_pi->get_next(); for (next_pi= m_cur_pi->get_next();
next_pi && cmp_point_info(m_cur_pi, next_pi) == 0; next_pi && cmp_point_info(m_cur_pi, next_pi) == 0;
next_pi= next_pi->get_next()) next_pi= next_pi->get_next())
{ {
GCALC_DBUG_PRINT(("eq_loop equal pi"));
next_state->clear_event_position(); next_state->clear_event_position();
m_next_is_top_point= true; m_next_is_top_point= true;
first_bottom_point= NULL; first_bottom_point= NULL;
...@@ -1205,40 +1223,52 @@ int Gcalc_scan_iterator::normal_scan() ...@@ -1205,40 +1223,52 @@ int Gcalc_scan_iterator::normal_scan()
sp_hook= (Gcalc_dyn_list::Item **) &next_state->slice; sp; sp_hook= (Gcalc_dyn_list::Item **) &next_state->slice; sp;
sp_hook= &sp->next, sp= sp->get_next()) sp_hook= &sp->next, sp= sp->get_next())
{ {
#ifndef NO_TESTING GCALC_DBUG_PRINT(("eq_loop normal_eq_step %s%d", gcalc_ev_name(sp->event),
// if (ca_counter == 21) sp->thread));
printf("%s%d\t", pev(sp->event), sp->thread);
#endif /*NO_TESTING*/
if (sp->next_pi == next_pi) /* End of the segment */ if (sp->next_pi == next_pi) /* End of the segment */
{ {
#ifdef TMP_BLOCK GCALC_DBUG_PRINT(("eq_loop edge end"));
sp->x= coord_to_float(next_pi->x);
sp->pi= next_pi;
#endif /*TMP_BLOCK*/
if (cmp_point_info(sp->pi, next_pi)) if (cmp_point_info(sp->pi, next_pi))
{
GCALC_DBUG_PRINT(("eq_loop zero-len edge"));
sp->pi= next_pi; sp->pi= next_pi;
}
sp->next_pi= next_pi->left; sp->next_pi= next_pi->left;
m_next_is_top_point= false; m_next_is_top_point= false;
if (next_pi->is_bottom()) if (next_pi->is_bottom())
{ {
GCALC_DBUG_PRINT(("eq_loop bottom_point"));
if (sp->event == scev_thread) if (sp->event == scev_thread)
{
/* Beginning of the thread, and the end are same */
/* Make single point out of the line then. */
GCALC_DBUG_PRINT(("eq_loop line_to_point"));
sp->event= scev_single_point; sp->event= scev_single_point;
}
else if (sp->event == scev_two_threads) else if (sp->event == scev_two_threads)
{ {
if (sp->get_next() && sp->get_next()->pi == sp->pi) if (sp->get_next() && sp->get_next()->pi == sp->pi)
{
GCALC_DBUG_PRINT(("eq_loop two_threads_to_line %d",
sp->get_next()->thread));
sp->get_next()->event= scev_thread; sp->get_next()->event= scev_thread;
}
else if (sp != next_state->slice) else if (sp != next_state->slice)
{ {
point *fnd_sp; point *fnd_sp;
for (fnd_sp= next_state->slice; fnd_sp->get_next() != sp; for (fnd_sp= next_state->slice; fnd_sp->get_next() != sp;
fnd_sp= fnd_sp->get_next()); fnd_sp= fnd_sp->get_next())
DBUG_ASSERT(fnd_sp->pi == sp->pi); {}
GCALC_DBUG_ASSERT(fnd_sp->pi == sp->pi);
GCALC_DBUG_PRINT(("eq_loop two_threads_to_line %d",
fnd_sp->thread));
fnd_sp->event= scev_thread; fnd_sp->event= scev_thread;
} }
sp->event= scev_single_point; sp->event= scev_single_point;
} }
else if (first_bottom_point) else if (first_bottom_point)
{ {
GCALC_DBUG_PRINT(("eq_loop two_ends"));
first_bottom_point->event= sp->event= scev_two_ends; first_bottom_point->event= sp->event= scev_two_ends;
} }
else else
...@@ -1249,6 +1279,8 @@ int Gcalc_scan_iterator::normal_scan() ...@@ -1249,6 +1279,8 @@ int Gcalc_scan_iterator::normal_scan()
} }
else else
{ {
GCALC_DBUG_PRINT(("eq_loop no_bottom_point %d%s", sp->thread,
gcalc_ev_name(sp->event)));
if ((sp->event & (scev_point | scev_thread | scev_two_threads)) == 0) if ((sp->event & (scev_point | scev_thread | scev_two_threads)) == 0)
sp->event= scev_point; sp->event= scev_point;
calc_dx_dy(sp); calc_dx_dy(sp);
...@@ -1257,44 +1289,31 @@ int Gcalc_scan_iterator::normal_scan() ...@@ -1257,44 +1289,31 @@ int Gcalc_scan_iterator::normal_scan()
} }
else if (sp->event || (cmp_sp_pi(sp, next_pi) == 0)) else if (sp->event || (cmp_sp_pi(sp, next_pi) == 0))
{ {
GCALC_DBUG_PRINT(("eq_loop l_event %d%s", sp->thread,
gcalc_ev_name(sp->event)));
if (!sp->event) if (!sp->event)
sp->event= scev_intersection; sp->event= scev_intersection;
mark_event_position1(sp, sp_hook); mark_event_position1(sp, sp_hook);
} }
} }
#ifndef NO_TESTING
//if (ca_counter == 21)
printf("\n");
#endif /*NO_TESTING*/
m_cur_pi= next_pi; m_cur_pi= next_pi;
if (m_next_is_top_point) if (m_next_is_top_point)
{ {
if (insert_top_point()) if (insert_top_point())
return 1; GCALC_DBUG_RETURN(1);
/* Set proper values to the event position */ /* Set proper values to the event position */
/* TODO: can be done faster */ /* TODO: can be done faster */
next_state->clear_event_position(); next_state->clear_event_position();
if (next_state->slice->event) if (next_state->slice->event)
mark_event_position1(next_state->slice, mark_event_position1(next_state->slice,
(Gcalc_dyn_list::Item **) &next_state->slice); (Gcalc_dyn_list::Item **) &next_state->slice);
#ifndef NO_TESTING
//if (ca_counter == 21)
printf("*%s%d\t", pev(next_state->slice->event), next_state->slice->thread);
#endif /*NO_TESTING*/
for (sp= next_state->slice; sp->get_next(); sp= sp->get_next()) for (sp= next_state->slice; sp->get_next(); sp= sp->get_next())
{ {
#ifndef NO_TESTING
//if (ca_counter == 21)
printf("%s%d\t", pev(sp->get_next()->event), sp->get_next()->thread);
#endif /*NO_TESTING*/
if (sp->get_next()->event) if (sp->get_next()->event)
mark_event_position1(sp->get_next(), &sp->next); mark_event_position1(sp->get_next(), &sp->next);
} }
#ifndef NO_TESTING
//if (ca_counter == 21)
printf("\n");
#endif /*NO_TESTING*/
} }
GCALC_DBUG_PRINT_SLICE("eq_loop\t", next_state->slice);
} }
/* Swap current <-> next */ /* Swap current <-> next */
...@@ -1305,42 +1324,25 @@ int Gcalc_scan_iterator::normal_scan() ...@@ -1305,42 +1324,25 @@ int Gcalc_scan_iterator::normal_scan()
} }
if (arrange_event()) if (arrange_event())
return 1; GCALC_DBUG_RETURN(1);
GCALC_DBUG_PRINT_SLICE("after_arrange\t", current_state->slice);
GCALC_DBUG_PRINT_SLICE("events\t", m_events);
GCALC_DBUG_PRINT_STATE(current_state);
point *sp0= current_state->slice; point *sp0= current_state->slice;
point *sp1= next_state->slice; point *sp1= next_state->slice;
point *prev_sp1= NULL; point *prev_sp1= NULL;
#ifndef NO_TESTING
//if (ca_counter == 21)
{
point *sp= current_state->slice;
printf("After arrange\n");
for (; sp; sp= sp->get_next())
printf("%s%d\t", pev(sp->event), sp->thread);
printf("\nEvent\n");
for (sp= m_events; sp; sp= sp->get_next())
printf("%s%d\t", pev(sp->event), sp->thread);
printf("\n");
}
#endif /*NO_TESTING*/
if (!(m_cur_pi= next_pi)) if (!(m_cur_pi= next_pi))
{ {
free_list(sp1); free_list(sp1);
next_state->slice= NULL; next_state->slice= NULL;
#ifdef TO_REMOVE GCALC_DBUG_RETURN(0);
for (; sp0; sp0= sp0->get_next())
sp0->next_link= NULL;
#endif /*TO_REMOVE*/
return 0;
} }
next_state->intersection_scan= 0; next_state->intersection_scan= 0;
next_state->pi= m_cur_pi; next_state->pi= m_cur_pi;
Gcalc_heap::Info *cur_pi= m_cur_pi; Gcalc_heap::Info *cur_pi= m_cur_pi;
#ifdef TMP_BLOCK
next_state->y= coord_to_float(cur_pi->y);
#endif /*TMP_BLOCK*/
first_bottom_point= NULL; first_bottom_point= NULL;
...@@ -1350,23 +1352,19 @@ int Gcalc_scan_iterator::normal_scan() ...@@ -1350,23 +1352,19 @@ int Gcalc_scan_iterator::normal_scan()
for (; sp0; sp0= sp0->get_next()) for (; sp0; sp0= sp0->get_next())
{ {
DBUG_ASSERT(!sp0->is_bottom()); GCALC_DBUG_ASSERT(!sp0->is_bottom());
if (sp0->next_pi == cur_pi) /* End of the segment */ if (sp0->next_pi == cur_pi) /* End of the segment */
{ {
#ifdef TMP_BLOCK GCALC_DBUG_PRINT(("edge_end %d", sp0->thread));
sp1->x= coord_to_float(cur_pi->x);
#endif /*TMP_BLOCK*/
sp1->pi= cur_pi; sp1->pi= cur_pi;
sp1->thread= sp0->thread; sp1->thread= sp0->thread;
sp1->next_pi= cur_pi->left; sp1->next_pi= cur_pi->left;
#ifdef TO_REMOVE
sp0->next_link= sp1;
#endif /*TO_REMOVE*/
m_next_is_top_point= false; m_next_is_top_point= false;
if (sp1->is_bottom()) if (sp1->is_bottom())
{ {
GCALC_DBUG_PRINT(("bottom_point"));
if (!first_bottom_point) if (!first_bottom_point)
{ {
sp1->event= scev_end; sp1->event= scev_end;
...@@ -1374,6 +1372,7 @@ int Gcalc_scan_iterator::normal_scan() ...@@ -1374,6 +1372,7 @@ int Gcalc_scan_iterator::normal_scan()
} }
else else
{ {
GCALC_DBUG_PRINT(("two_ends"));
first_bottom_point->event= sp1->event= scev_two_ends; first_bottom_point->event= sp1->event= scev_two_ends;
} }
} }
...@@ -1388,15 +1387,12 @@ int Gcalc_scan_iterator::normal_scan() ...@@ -1388,15 +1387,12 @@ int Gcalc_scan_iterator::normal_scan()
} }
else else
{ {
GCALC_DBUG_PRINT(("cut_edge %d", sp0->thread));
/* Cut current string with the height of the new point*/ /* Cut current string with the height of the new point*/
sp1->copy_core(sp0); sp1->copy_core(sp0);
#ifdef TMP_BLOCK
sp1->x= sp1->horiz_dir ? coord_to_float(cur_pi->x) :
(coord_to_float(sp1->pi->x) +
(next_state->y-coord_to_float(sp1->pi->y)) * sp1->dx_dy);
#endif /*TMP_BLOCK*/
if (cmp_sp_pi(sp1, cur_pi) == 0) if (cmp_sp_pi(sp1, cur_pi) == 0)
{ {
GCALC_DBUG_PRINT(("equal_point"));
mark_event_position1(sp1, mark_event_position1(sp1,
prev_sp1 ? &prev_sp1->next : prev_sp1 ? &prev_sp1->next :
(Gcalc_dyn_list::Item **) &next_state->slice); (Gcalc_dyn_list::Item **) &next_state->slice);
...@@ -1408,6 +1404,7 @@ int Gcalc_scan_iterator::normal_scan() ...@@ -1408,6 +1404,7 @@ int Gcalc_scan_iterator::normal_scan()
intersections_found= intersections_found || intersections_found= intersections_found ||
(prev_sp1 && cmp_sp_sp(prev_sp1, sp1, cur_pi) > 0); (prev_sp1 && cmp_sp_sp(prev_sp1, sp1, cur_pi) > 0);
GCALC_DBUG_PRINT(("%s", intersections_found ? "X":"-"));
prev_sp1= sp1; prev_sp1= sp1;
sp1= sp1->get_next(); sp1= sp1->get_next();
...@@ -1422,26 +1419,14 @@ int Gcalc_scan_iterator::normal_scan() ...@@ -1422,26 +1419,14 @@ int Gcalc_scan_iterator::normal_scan()
free_list(sp1); free_list(sp1);
} }
#ifndef NO_TESTING GCALC_DBUG_PRINT_SLICE("after_loop\t", next_state->slice);
//if (ca_counter == 21)
{
point *sp= next_state->slice;
printf("After slice\n");
for (; sp; sp= sp->get_next())
printf("%s%d\t", pev(sp->event), sp->thread);
printf("\n");
}
#endif /*NO_TESTING*/
if (intersections_found) if (intersections_found)
return handle_intersections(); GCALC_DBUG_RETURN(handle_intersections());
return 0; GCALC_DBUG_RETURN(0);
} }
#ifndef NO_TESTING
int isc_counter= 0;
#endif /*NO_TESTING*/
int Gcalc_scan_iterator::add_intersection(int n_row, int Gcalc_scan_iterator::add_intersection(int n_row,
const point *a, const point *b, const point *a, const point *b,
Gcalc_dyn_list::Item ***p_hook) Gcalc_dyn_list::Item ***p_hook)
...@@ -1450,8 +1435,9 @@ int Gcalc_scan_iterator::add_intersection(int n_row, ...@@ -1450,8 +1435,9 @@ int Gcalc_scan_iterator::add_intersection(int n_row,
const point *b0= b->intersection_link; const point *b0= b->intersection_link;
intersection *isc= new_intersection(); intersection *isc= new_intersection();
GCALC_DBUG_ENTER("Gcalc_scan_iterator::add_intersection");
if (!isc) if (!isc)
return 1; GCALC_DBUG_RETURN(1);
m_n_intersections++; m_n_intersections++;
**p_hook= isc; **p_hook= isc;
...@@ -1462,15 +1448,7 @@ int Gcalc_scan_iterator::add_intersection(int n_row, ...@@ -1462,15 +1448,7 @@ int Gcalc_scan_iterator::add_intersection(int n_row,
isc->ii= m_heap->new_intersection(a0->pi, a0->next_pi, isc->ii= m_heap->new_intersection(a0->pi, a0->next_pi,
b0->pi, b0->next_pi); b0->pi, b0->next_pi);
#ifndef NO_TESTING GCALC_DBUG_RETURN(isc->ii == NULL);
//if (isc_counter == 40)
{
long double ix, iy;
isc->ii->calc_xy_ld(&ix, &iy);
printf("%d\t%d\t%.20LG\t%.20LG\t%d\n", isc->thread_a, isc->thread_b, ix, iy, isc->n_row);
}
#endif /*NO_TESTING*/
return isc->ii == NULL;
} }
...@@ -1478,10 +1456,7 @@ int Gcalc_scan_iterator::find_intersections() ...@@ -1478,10 +1456,7 @@ int Gcalc_scan_iterator::find_intersections()
{ {
Gcalc_dyn_list::Item **hook; Gcalc_dyn_list::Item **hook;
#ifndef NO_TESTING GCALC_DBUG_ENTER("Gcalc_scan_iterator::find_intersections");
++isc_counter;
printf("Looking for intersections\n");
#endif /*NO_TESTING*/
m_n_intersections= 0; m_n_intersections= 0;
{ {
/* Set links between slicepoints */ /* Set links between slicepoints */
...@@ -1489,18 +1464,9 @@ int Gcalc_scan_iterator::find_intersections() ...@@ -1489,18 +1464,9 @@ int Gcalc_scan_iterator::find_intersections()
point *sp1= next_state->slice; point *sp1= next_state->slice;
for (; sp1; sp0= sp0->get_next(),sp1= sp1->get_next()) for (; sp1; sp0= sp0->get_next(),sp1= sp1->get_next())
{ {
DBUG_ASSERT(!sp0->is_bottom()); GCALC_DBUG_ASSERT(!sp0->is_bottom());
DBUG_ASSERT(sp0->thread == sp1->thread); GCALC_DBUG_ASSERT(sp0->thread == sp1->thread);
sp1->intersection_link= sp0; sp1->intersection_link= sp0;
#ifndef NO_TESTING
//if (isc_counter == 40)
{
long double spx, spx1;
sp0->calc_x(&spx, current_state->pi->y, current_state->pi->x);
sp1->calc_x(&spx1, m_cur_pi->y, m_cur_pi->x);
printf("%d\t%.20LG\t%.20LG\n", sp0->thread, spx, spx1);
}
#endif /*NO_TESTING*/
} }
} }
...@@ -1526,7 +1492,7 @@ int Gcalc_scan_iterator::find_intersections() ...@@ -1526,7 +1492,7 @@ int Gcalc_scan_iterator::find_intersections()
} }
intersections_found= true; intersections_found= true;
if (add_intersection(n_row, prev_s1, s1, &hook)) if (add_intersection(n_row, prev_s1, s1, &hook))
return 1; GCALC_DBUG_RETURN(1);
*pprev_s1= s1; *pprev_s1= s1;
prev_s1->next= s1->next; prev_s1->next= s1->next;
s1->next= prev_s1; s1->next= prev_s1;
...@@ -1537,7 +1503,7 @@ int Gcalc_scan_iterator::find_intersections() ...@@ -1537,7 +1503,7 @@ int Gcalc_scan_iterator::find_intersections()
} while (intersections_found); } while (intersections_found);
*hook= NULL; *hook= NULL;
return 0; GCALC_DBUG_RETURN(0);
} }
...@@ -1584,76 +1550,6 @@ static void calc_isc_exp(Gcalc_coord5 *exp, ...@@ -1584,76 +1550,6 @@ static void calc_isc_exp(Gcalc_coord5 *exp,
} }
#ifdef TMP_BLOCK
static void calc_aa1_b(Gcalc_coord2 *res,
const Gcalc_heap::Info *a0,
const Gcalc_heap::Info *a1,
const Gcalc_coord1 *xb,
const Gcalc_coord1 *yb)
{
Gcalc_coord1 aa1_x, aa1_y;
Gcalc_coord2 p1, p2;
res->init();
aa1_x.init();
aa1_y.init();
p1.init();
p2.init();
gcalc_sub_coord(&aa1_x, &a1->ix, &a0->ix);
gcalc_sub_coord(&aa1_y, &a1->iy, &a0->iy);
gcalc_mul_coord(&p1, &aa1_x, yb);
gcalc_mul_coord(&p2, &aa1_y, xb);
gcalc_sub_coord(res, &p1, &p2);
}
static int cmp_intersections_y(const Gcalc_heap::Intersection_info *i1,
const Gcalc_heap::Intersection_info *i2)
{
Gcalc_coord2 t_a1, t_b1;
Gcalc_coord2 t_a2, t_b2;
Gcalc_coord1 yb1, yb2;
Gcalc_coord1 xb1, xb2;
Gcalc_coord5 exp_a, exp_b;
calc_t(&t_a1, &t_b1, &xb1, &yb1, i1);
calc_t(&t_a2, &t_b2, &xb2, &yb2, i2);
calc_isc_exp(&exp_a, &t_b2, &i1->p1->iy, &t_b1, &yb1, &t_a1);
calc_isc_exp(&exp_b, &t_b1, &i2->p1->iy, &t_b2, &yb2, &t_a2);
int result= gcalc_cmp_coord(&exp_a, &exp_b);
#ifdef GCALC_CHECK_WITH_FLOAT
long double x1, y1, x2,y2;
i1->calc_xy_ld(&x1, &y1);
i2->calc_xy_ld(&x2, &y2);
if (result == 0)
DBUG_ASSERT(de_check(y1, y2));
if (result < 0)
DBUG_ASSERT(de_check1(y1, y2) || y1 < y2);
if (result > 0)
DBUG_ASSERT(de_check1(y1, y2) || y1 > y2);
#endif /*GCALC_CHECK_WITH_FLOAT*/
return result;
}
static int compare_intersections(const void *e1, const void *e2)
{
Gcalc_scan_iterator::intersection *i1= (Gcalc_scan_iterator::intersection *)e1;
Gcalc_scan_iterator::intersection *i2= (Gcalc_scan_iterator::intersection *)e2;
int result= cmp_intersections_y(i1->ii, i2->ii);
if (result != 0)
return result > 0;
return (i1->n_row > i2->n_row);
}
#endif /*TMP_BLOCK*/
#ifndef NO_TESTING
extern int ca_counter;
#endif /*NO_TESTING*/
static int cmp_intersections(const Gcalc_heap::Intersection_info *i1, static int cmp_intersections(const Gcalc_heap::Intersection_info *i1,
const Gcalc_heap::Intersection_info *i2) const Gcalc_heap::Intersection_info *i2)
{ {
...@@ -1677,15 +1573,11 @@ static int cmp_intersections(const Gcalc_heap::Intersection_info *i1, ...@@ -1677,15 +1573,11 @@ static int cmp_intersections(const Gcalc_heap::Intersection_info *i1,
i2->calc_xy_ld(&x2, &y2); i2->calc_xy_ld(&x2, &y2);
if (result == 0) if (result == 0)
DBUG_ASSERT(de_weak(y1, y2)); GCALC_DBUG_ASSERT(de_check(y1, y2));
#ifndef NO_TESTING
if (ca_counter == 7)
printf("77");
#endif /*NO_TESTING*/
if (result < 0) if (result < 0)
DBUG_ASSERT(de_weak(y1, y2) || y1 < y2); GCALC_DBUG_ASSERT(de_check(y1, y2) || y1 < y2);
if (result > 0) if (result > 0)
DBUG_ASSERT(de_weak(y1, y2) || y1 > y2); GCALC_DBUG_ASSERT(de_check(y1, y2) || y1 > y2);
#endif /*GCALC_CHECK_WITH_FLOAT*/ #endif /*GCALC_CHECK_WITH_FLOAT*/
if (result != 0) if (result != 0)
...@@ -1697,11 +1589,11 @@ static int cmp_intersections(const Gcalc_heap::Intersection_info *i1, ...@@ -1697,11 +1589,11 @@ static int cmp_intersections(const Gcalc_heap::Intersection_info *i1,
result= gcalc_cmp_coord(&exp_a, &exp_b); result= gcalc_cmp_coord(&exp_a, &exp_b);
#ifdef GCALC_CHECK_WITH_FLOAT #ifdef GCALC_CHECK_WITH_FLOAT
if (result == 0) if (result == 0)
DBUG_ASSERT(de_weak(x1, x2)); GCALC_DBUG_ASSERT(de_check(x1, x2));
if (result < 0) if (result < 0)
DBUG_ASSERT(de_weak(x1, x2) || x1 < x2); GCALC_DBUG_ASSERT(de_check(x1, x2) || x1 < x2);
if (result > 0) if (result > 0)
DBUG_ASSERT(de_weak(x1, x2) || x1 > x2); GCALC_DBUG_ASSERT(de_check(x1, x2) || x1 > x2);
#endif /*GCALC_CHECK_WITH_FLOAT*/ #endif /*GCALC_CHECK_WITH_FLOAT*/
return result; return result;
} }
...@@ -1723,28 +1615,6 @@ inline int intersections_eq(const Gcalc_heap::Intersection_info *i1, ...@@ -1723,28 +1615,6 @@ inline int intersections_eq(const Gcalc_heap::Intersection_info *i1,
} }
#ifdef TMP_BLOCK
static void calc_isc_sp_exp(Gcalc_coord4 *exp,
const Gcalc_coord2 *bb,
const Gcalc_coord1 *x1,
const Gcalc_coord1 *y1,
const Gcalc_coord1 *x2,
const Gcalc_coord1 *y2)
{
Gcalc_coord2 p1, p2, sum;
p1.init();
p2.init();
sum.init();
exp->init();
gcalc_mul_coord(&p1, x1, y1);
gcalc_mul_coord(&p2, x2, y2);
gcalc_add_coord(&sum, &p1, &p2);
gcalc_mul_coord(exp, bb, &sum);
}
#endif /*TMP_BLOCK*/
static int sp_isc_eq(const Gcalc_scan_iterator::point *sp, static int sp_isc_eq(const Gcalc_scan_iterator::point *sp,
const Gcalc_heap::Intersection_info *isc) const Gcalc_heap::Intersection_info *isc)
{ {
...@@ -1753,17 +1623,6 @@ static int sp_isc_eq(const Gcalc_scan_iterator::point *sp, ...@@ -1753,17 +1623,6 @@ static int sp_isc_eq(const Gcalc_scan_iterator::point *sp,
Gcalc_coord1 xb1, yb1; Gcalc_coord1 xb1, yb1;
Gcalc_coord2 t_a, t_b; Gcalc_coord2 t_a, t_b;
Gcalc_coord2 t_sp_a, t_sp_b; Gcalc_coord2 t_sp_a, t_sp_b;
#ifdef TMP_BLOCK
xa1a0.init();
ya1a0.init();
gcalc_sub_coord(&xa1a0, &isc->p1->ix, &sp->pi->ix);
gcalc_sub_coord(&ya1a0, &isc->p1->iy, &sp->pi->iy);
calc_isc_sp_exp(&exp_a, &t_b, &sp->pi->ix, &ya1a0, &sp->pi->iy, &xa1a0);
calc_isc_sp_exp(&exp_b, &t_a, &sp->pi->iy, &isc->p1->ix,
&sp->pi->ix, &isc->p1->iy);
return gcalc_cmp_coord(&exp_a, &exp_b);
#endif /*TMP_BLOCK*/
exp_a.init(); exp_a.init();
exp_b.init(); exp_b.init();
calc_t(&t_a, &t_b, &xb1, &yb1, isc); calc_t(&t_a, &t_b, &xb1, &yb1, isc);
...@@ -1777,12 +1636,8 @@ static int sp_isc_eq(const Gcalc_scan_iterator::point *sp, ...@@ -1777,12 +1636,8 @@ static int sp_isc_eq(const Gcalc_scan_iterator::point *sp,
isc->calc_xy_ld(&int_x, &int_y); isc->calc_xy_ld(&int_x, &int_y);
sp->calc_x(&sp_x, int_y, int_x); sp->calc_x(&sp_x, int_y, int_x);
if (result == 0) if (result == 0)
DBUG_ASSERT(de_check1(sp->dy.get_double(), 0.0) || GCALC_DBUG_ASSERT(de_check(sp->dy.get_double(), 0.0) ||
de_check(sp_x, int_x)); de_check(sp_x, int_x));
#ifdef TMP_BLOCK
else
DBUG_ASSERT(!de_check1(sp_x, int_x));
#endif /*TMP_BLOCK*/
#endif /*GCALC_CHECK_WITH_FLOAT*/ #endif /*GCALC_CHECK_WITH_FLOAT*/
return result == 0; return result == 0;
} }
...@@ -1797,11 +1652,15 @@ inline void Gcalc_scan_iterator::sort_intersections() ...@@ -1797,11 +1652,15 @@ inline void Gcalc_scan_iterator::sort_intersections()
int Gcalc_scan_iterator::handle_intersections() int Gcalc_scan_iterator::handle_intersections()
{ {
DBUG_ASSERT(next_state->slice->next); GCALC_DBUG_ENTER("Gcalc_scan_iterator::handle_intersections");
GCALC_DBUG_ASSERT(next_state->slice->next);
if (find_intersections()) if (find_intersections())
return 1; GCALC_DBUG_RETURN(1);
GCALC_DBUG_PRINT_INTERSECTIONS(m_intersections);
sort_intersections(); sort_intersections();
GCALC_DBUG_PRINT(("After sorting"));
GCALC_DBUG_PRINT_INTERSECTIONS(m_intersections);
/* Swap saved <-> next */ /* Swap saved <-> next */
{ {
...@@ -1812,19 +1671,7 @@ int Gcalc_scan_iterator::handle_intersections() ...@@ -1812,19 +1671,7 @@ int Gcalc_scan_iterator::handle_intersections()
/* We need the next slice to be just equal */ /* We need the next slice to be just equal */
next_state->slice= new_slice(saved_state->slice); next_state->slice= new_slice(saved_state->slice);
m_cur_intersection= m_intersections; m_cur_intersection= m_intersections;
#ifndef NO_TESTING GCALC_DBUG_RETURN(intersection_scan());
//if (isc_counter == 40)
{
printf("Sorted\n");
for (intersection *isc= m_intersections; isc; isc= isc->get_next())
{
long double ix, iy;
isc->ii->calc_xy_ld(&ix, &iy);
printf("%d\t%d\t%.20LG\t%.20LG\t%d\n", isc->thread_a, isc->thread_b, ix, iy, isc->n_row);
}
}
#endif /*NO_TESTING*/
return intersection_scan();
} }
...@@ -1834,8 +1681,11 @@ int Gcalc_scan_iterator::intersection_scan() ...@@ -1834,8 +1681,11 @@ int Gcalc_scan_iterator::intersection_scan()
Gcalc_dyn_list::Item **hook; Gcalc_dyn_list::Item **hook;
intersection *next_intersection= NULL; intersection *next_intersection= NULL;
GCALC_DBUG_ENTER("Gcalc_scan_iterator::intersection_scan");
GCALC_DBUG_CHECK_COUNTER();
if (m_cur_intersection != m_intersections) if (m_cur_intersection != m_intersections)
{ {
GCALC_DBUG_PRINT_SLICE("in_isc\t", next_state->slice);
/* Swap current <-> next */ /* Swap current <-> next */
{ {
slice_state *tmp= current_state; slice_state *tmp= current_state;
...@@ -1844,33 +1694,9 @@ int Gcalc_scan_iterator::intersection_scan() ...@@ -1844,33 +1694,9 @@ int Gcalc_scan_iterator::intersection_scan()
} }
if (arrange_event()) if (arrange_event())
return 1; GCALC_DBUG_RETURN(1);
#ifdef TMP_BLOCK
if (!m_cur_intersection)
{
saved_state->event_position_hook=
(Gcalc_dyn_list::Item **) &saved_state->slice;
for (sp1= saved_state->slice; sp1; sp1= sp1->get_next())
{
if (sp1->get_next() == saved_state->event_position)
saved_state->event_position_hook= &sp1->next;
}
/* Swap saved <-> next */
{
slice_state *tmp= next_state;
next_state= saved_state;
saved_state= tmp;
}
free_list(saved_state->slice);
saved_state->slice= NULL;
free_list(m_intersections); GCALC_DBUG_PRINT_SLICE("isc_after_arrange\t", current_state->slice);
m_intersections= NULL;
return 0;
}
#endif /*TMP_BLOCK*/
if (!m_cur_intersection) if (!m_cur_intersection)
{ {
/* Swap saved <-> next */ /* Swap saved <-> next */
...@@ -1894,8 +1720,9 @@ int Gcalc_scan_iterator::intersection_scan() ...@@ -1894,8 +1720,9 @@ int Gcalc_scan_iterator::intersection_scan()
point *fnd_s= sp1->get_next(); point *fnd_s= sp1->get_next();
Gcalc_dyn_list::Item **fnd_hook= &sp1->next; Gcalc_dyn_list::Item **fnd_hook= &sp1->next;
for (; fnd_s && fnd_s->thread != sp0->thread; for (; fnd_s && fnd_s->thread != sp0->thread;
fnd_hook= &fnd_s->next, fnd_s= fnd_s->get_next()); fnd_hook= &fnd_s->next, fnd_s= fnd_s->get_next())
DBUG_ASSERT(fnd_s && fnd_s == *fnd_hook); {}
GCALC_DBUG_ASSERT(fnd_s && fnd_s == *fnd_hook);
/* Now swap items of the next_state->slice */ /* Now swap items of the next_state->slice */
*n_hook= fnd_s; *n_hook= fnd_s;
*fnd_hook= fnd_s->next; *fnd_hook= fnd_s->next;
...@@ -1905,19 +1732,19 @@ int Gcalc_scan_iterator::intersection_scan() ...@@ -1905,19 +1732,19 @@ int Gcalc_scan_iterator::intersection_scan()
if (sp1->event) if (sp1->event)
mark_event_position1(sp1, n_hook); mark_event_position1(sp1, n_hook);
} }
#ifndef DBUG_OFF #ifndef GCALC_DBUG_OFF
sp0= current_state->slice; sp0= current_state->slice;
sp1= next_state->slice; sp1= next_state->slice;
for (; sp0; sp0= sp0->get_next(), sp1= sp1->get_next()) for (; sp0; sp0= sp0->get_next(), sp1= sp1->get_next())
DBUG_ASSERT(sp0->thread == sp1->thread); GCALC_DBUG_ASSERT(sp0->thread == sp1->thread);
DBUG_ASSERT(!sp1); GCALC_DBUG_ASSERT(!sp1);
#endif /*DBUG_OFF*/ #endif /*GCALC_DBUG_OFF*/
free_list(saved_state->slice); free_list(saved_state->slice);
saved_state->slice= NULL; saved_state->slice= NULL;
free_list(m_intersections); free_list(m_intersections);
m_intersections= NULL; m_intersections= NULL;
return 0; GCALC_DBUG_RETURN(0);
} }
} }
...@@ -1934,15 +1761,17 @@ int Gcalc_scan_iterator::intersection_scan() ...@@ -1934,15 +1761,17 @@ int Gcalc_scan_iterator::intersection_scan()
if (sp0->thread == m_cur_intersection->thread_a || if (sp0->thread == m_cur_intersection->thread_a ||
sp0->thread == m_cur_intersection->thread_b) sp0->thread == m_cur_intersection->thread_b)
{ {
DBUG_ASSERT(sp0->thread != m_cur_intersection->thread_a || GCALC_DBUG_ASSERT(sp0->thread != m_cur_intersection->thread_a ||
sp0->get_next()->thread == m_cur_intersection->thread_b || sp0->get_next()->thread == m_cur_intersection->thread_b ||
sp_isc_eq(sp0->get_next(), m_cur_intersection->ii)); sp_isc_eq(sp0->get_next(), m_cur_intersection->ii));
GCALC_DBUG_PRINT(("isc_i_thread %d", sp0->thread));
sp1->copy_core(sp0); sp1->copy_core(sp0);
sp1->event= scev_intersection; sp1->event= scev_intersection;
mark_event_position1(sp1, hook); mark_event_position1(sp1, hook);
} }
else else
{ {
GCALC_DBUG_PRINT(("isc_cut %d", sp0->thread));
sp1->copy_core(sp0); sp1->copy_core(sp0);
if (sp_isc_eq(sp1, m_cur_intersection->ii)) if (sp_isc_eq(sp1, m_cur_intersection->ii))
{ {
...@@ -1967,6 +1796,7 @@ int Gcalc_scan_iterator::intersection_scan() ...@@ -1967,6 +1796,7 @@ int Gcalc_scan_iterator::intersection_scan()
next_intersection= next_intersection->get_next()) next_intersection= next_intersection->get_next())
{ {
/* Handle equal intersections. We only need to set proper events */ /* Handle equal intersections. We only need to set proper events */
GCALC_DBUG_PRINT(("isc_eq_intersection"));
sp0= current_state->slice; sp0= current_state->slice;
hook= (Gcalc_dyn_list::Item **) &next_state->slice; hook= (Gcalc_dyn_list::Item **) &next_state->slice;
sp1= next_state->slice; sp1= next_state->slice;
...@@ -1979,6 +1809,7 @@ int Gcalc_scan_iterator::intersection_scan() ...@@ -1979,6 +1809,7 @@ int Gcalc_scan_iterator::intersection_scan()
sp0->thread == next_intersection->thread_b || sp0->thread == next_intersection->thread_b ||
sp1->event == scev_intersection) sp1->event == scev_intersection)
{ {
GCALC_DBUG_PRINT(("isc_eq_thread %d", sp0->thread));
sp1->event= scev_intersection; sp1->event= scev_intersection;
mark_event_position1(sp1, hook); mark_event_position1(sp1, hook);
} }
...@@ -1986,7 +1817,7 @@ int Gcalc_scan_iterator::intersection_scan() ...@@ -1986,7 +1817,7 @@ int Gcalc_scan_iterator::intersection_scan()
} }
m_cur_intersection= next_intersection; m_cur_intersection= next_intersection;
return 0; GCALC_DBUG_RETURN(0);
} }
......
...@@ -17,6 +17,16 @@ ...@@ -17,6 +17,16 @@
#ifndef GCALC_SLICESCAN_INCLUDED #ifndef GCALC_SLICESCAN_INCLUDED
#define GCALC_SLICESCAN_INCLUDED #define GCALC_SLICESCAN_INCLUDED
#ifndef DBUG_OFF
#define GCALC_CHECK_WITH_FLOAT
#else
#define GCALC_DBUG_OFF
#endif /*DBUG_OFF*/
#define GCALC_DBUG_PRINT(b) DBUG_PRINT("Gcalc", b)
#define GCALC_DBUG_ENTER(a) DBUG_ENTER("Gcalc "a)
#define GCALC_DBUG_RETURN(r) DBUG_RETURN(r)
#define GCALC_DBUG_ASSERT(r) DBUG_ASSERT(r)
/* /*
Gcalc_dyn_list class designed to manage long lists of same-size objects Gcalc_dyn_list class designed to manage long lists of same-size objects
...@@ -102,12 +112,6 @@ typedef long long coord2; ...@@ -102,12 +112,6 @@ typedef long long coord2;
#define C_SCALE 1e13 #define C_SCALE 1e13
#define COORD_BASE 2 #define COORD_BASE 2
#ifndef DBUG_OFF
//#define GCALC_CHECK_WITH_FLOAT
#define NO_TESTING
#else
#define NO_TESTING
#endif /*DBUG_OFF*/
class Gcalc_internal_coord class Gcalc_internal_coord
{ {
...@@ -349,22 +353,17 @@ public: ...@@ -349,22 +353,17 @@ public:
class point : public Gcalc_dyn_list::Item class point : public Gcalc_dyn_list::Item
{ {
public: public:
#ifdef TMP_BLOCK
double x;
double dx_dy;
int horiz_dir;
#endif /*TMP_BLOCK*/
Gcalc_coord1 dx; Gcalc_coord1 dx;
Gcalc_coord1 dy; Gcalc_coord1 dy;
Gcalc_heap::Info *pi; Gcalc_heap::Info *pi;
Gcalc_heap::Info *next_pi; Gcalc_heap::Info *next_pi;
sc_thread_id thread; sc_thread_id thread;
const Gcalc_coord1 *l_border;
const Gcalc_coord1 *r_border;
int always_on_left;
const point *intersection_link; const point *intersection_link;
Gcalc_scan_events event; Gcalc_scan_events event;
#ifdef TO_REMOVE
point *next_link;
#endif /*TO_REMOVE*/
inline const point *c_get_next() const inline const point *c_get_next() const
{ return (const point *)next; } { return (const point *)next; }
...@@ -377,10 +376,6 @@ public: ...@@ -377,10 +376,6 @@ public:
void copy_all(const point *from); void copy_all(const point *from);
/* Compare the dx_dy parameters regarding the horiz_dir */ /* Compare the dx_dy parameters regarding the horiz_dir */
/* returns -1 if less, 0 if equal, 1 if bigger */ /* returns -1 if less, 0 if equal, 1 if bigger */
#ifdef TMP_BLOCK
static int cmp_dx_dy(int horiz_dir_a, double dx_dy_a,
int horiz_dir_b, double dx_dy_b);
#endif /*TMP_BLOCK*/
static int cmp_dx_dy(const Gcalc_coord1 *dx_a, static int cmp_dx_dy(const Gcalc_coord1 *dx_a,
const Gcalc_coord1 *dy_a, const Gcalc_coord1 *dy_a,
const Gcalc_coord1 *dx_b, const Gcalc_coord1 *dx_b,
...@@ -409,10 +404,6 @@ public: ...@@ -409,10 +404,6 @@ public:
int n_row; int n_row;
sc_thread_id thread_a; sc_thread_id thread_a;
sc_thread_id thread_b; sc_thread_id thread_b;
#ifdef TMP_BLOCK
double x;
double y;
#endif /*TMP_BLOCK*/
const Gcalc_heap::Intersection_info *ii; const Gcalc_heap::Intersection_info *ii;
inline intersection *get_next() { return (intersection *)next; } inline intersection *get_next() { return (intersection *)next; }
}; };
...@@ -430,9 +421,6 @@ public: ...@@ -430,9 +421,6 @@ public:
const Gcalc_heap::Info *pi; const Gcalc_heap::Info *pi;
const Gcalc_heap::Intersection_info *isc; const Gcalc_heap::Intersection_info *isc;
}; };
#ifdef TMP_BLOCK
double y;
#endif /*TMP_BLOCK*/
slice_state() : slice(NULL) {} slice_state() : slice(NULL) {}
void clear_event_position() void clear_event_position()
{ {
......
...@@ -135,6 +135,8 @@ int Gcalc_function::count_internal(const char *cur_func, uint set_type, ...@@ -135,6 +135,8 @@ int Gcalc_function::count_internal(const char *cur_func, uint set_type,
int result; int result;
const char *sav_cur_func= cur_func; const char *sav_cur_func= cur_func;
// GCALC_DBUG_ENTER("Gcalc_function::count_internal");
cur_func+= 4; cur_func+= 4;
if (next_func == op_shape) if (next_func == op_shape)
{ {
...@@ -167,6 +169,7 @@ int Gcalc_function::count_internal(const char *cur_func, uint set_type, ...@@ -167,6 +169,7 @@ int Gcalc_function::count_internal(const char *cur_func, uint set_type,
if (n_ops == 0) if (n_ops == 0)
return mask; return mask;
//GCALC_DBUG_RETURN(mask);
result= count_internal(cur_func, set_type, &cur_func); result= count_internal(cur_func, set_type, &cur_func);
...@@ -219,13 +222,14 @@ exit: ...@@ -219,13 +222,14 @@ exit:
result= 0; result= 0;
break; break;
default: default:
DBUG_ASSERT(0); GCALC_DBUG_ASSERT(0);
}; };
} }
if (end) if (end)
*end= cur_func; *end= cur_func;
return result; return result;
//GCALC_DBUG_RETURN(result);
} }
...@@ -258,11 +262,12 @@ void Gcalc_function::reset() ...@@ -258,11 +262,12 @@ void Gcalc_function::reset()
int Gcalc_function::check_function(Gcalc_scan_iterator &scan_it) int Gcalc_function::check_function(Gcalc_scan_iterator &scan_it)
{ {
const Gcalc_scan_iterator::point *eq_start, *cur_eq, *events; const Gcalc_scan_iterator::point *eq_start, *cur_eq, *events;
GCALC_DBUG_ENTER("Gcalc_function::check_function");
while (scan_it.more_points()) while (scan_it.more_points())
{ {
if (scan_it.step()) if (scan_it.step())
return -1; GCALC_DBUG_RETURN(-1);
events= scan_it.get_events(); events= scan_it.get_events();
/* these kinds of events don't change the function */ /* these kinds of events don't change the function */
...@@ -282,7 +287,7 @@ int Gcalc_function::check_function(Gcalc_scan_iterator &scan_it) ...@@ -282,7 +287,7 @@ int Gcalc_function::check_function(Gcalc_scan_iterator &scan_it)
set_b_state(events->get_shape()); set_b_state(events->get_shape());
if (count()) if (count())
return 1; GCALC_DBUG_RETURN(1);
clear_b_states(); clear_b_states();
continue; continue;
} }
...@@ -301,7 +306,7 @@ int Gcalc_function::check_function(Gcalc_scan_iterator &scan_it) ...@@ -301,7 +306,7 @@ int Gcalc_function::check_function(Gcalc_scan_iterator &scan_it)
} }
if (count()) if (count())
return 1; GCALC_DBUG_RETURN(1);
/* Set back states changed in the loop above. */ /* Set back states changed in the loop above. */
for (events= scan_it.get_events(); events; events= events->get_next()) for (events= scan_it.get_events(); events; events= events->get_next())
...@@ -337,7 +342,7 @@ int Gcalc_function::check_function(Gcalc_scan_iterator &scan_it) ...@@ -337,7 +342,7 @@ int Gcalc_function::check_function(Gcalc_scan_iterator &scan_it)
invert_i_state(si); invert_i_state(si);
} }
if (count()) if (count())
return 1; GCALC_DBUG_RETURN(1);
for (cur_eq= eq_start; cur_eq != pit.point(); cur_eq= cur_eq->get_next()) for (cur_eq= eq_start; cur_eq != pit.point(); cur_eq= cur_eq->get_next())
{ {
...@@ -351,11 +356,11 @@ int Gcalc_function::check_function(Gcalc_scan_iterator &scan_it) ...@@ -351,11 +356,11 @@ int Gcalc_function::check_function(Gcalc_scan_iterator &scan_it)
invert_i_state(cur_eq->get_shape()); invert_i_state(cur_eq->get_shape());
} }
if (count()) if (count())
return 1; GCALC_DBUG_RETURN(1);
eq_start= pit.point(); eq_start= pit.point();
} while (pit.point() != scan_it.get_event_end()); } while (pit.point() != scan_it.get_event_end());
} }
return 0; GCALC_DBUG_RETURN(0);
} }
...@@ -435,52 +440,51 @@ int Gcalc_operation_transporter::empty_shape() ...@@ -435,52 +440,51 @@ int Gcalc_operation_transporter::empty_shape()
int Gcalc_result_receiver::start_shape(Gcalc_function::shape_type shape) int Gcalc_result_receiver::start_shape(Gcalc_function::shape_type shape)
{ {
GCALC_DBUG_ENTER("Gcalc_result_receiver::start_shape");
if (buffer.reserve(4*2, 512)) if (buffer.reserve(4*2, 512))
return 1; GCALC_DBUG_RETURN(1);
cur_shape= shape; cur_shape= shape;
shape_pos= buffer.length(); shape_pos= buffer.length();
buffer.length(shape_pos + ((shape == Gcalc_function::shape_point) ? 4:8)); buffer.length(shape_pos + ((shape == Gcalc_function::shape_point) ? 4:8));
n_points= 0; n_points= 0;
shape_area= 0.0; shape_area= 0.0;
return 0; GCALC_DBUG_RETURN(0);
} }
int Gcalc_result_receiver::add_point(double x, double y) int Gcalc_result_receiver::add_point(double x, double y)
{ {
GCALC_DBUG_ENTER("Gcalc_result_receiver::add_point");
if (n_points && x == prev_x && y == prev_y) if (n_points && x == prev_x && y == prev_y)
return 0; GCALC_DBUG_RETURN(0);
if (!n_points++) if (!n_points++)
{ {
prev_x= first_x= x; prev_x= first_x= x;
prev_y= first_y= y; prev_y= first_y= y;
return 0; GCALC_DBUG_RETURN(0);
} }
shape_area+= prev_x*y - prev_y*x; shape_area+= prev_x*y - prev_y*x;
if (buffer.reserve(8*2, 512)) if (buffer.reserve(8*2, 512))
return 1; GCALC_DBUG_RETURN(1);
buffer.q_append(prev_x); buffer.q_append(prev_x);
buffer.q_append(prev_y); buffer.q_append(prev_y);
prev_x= x; prev_x= x;
prev_y= y; prev_y= y;
#ifndef NO_TESTING GCALC_DBUG_RETURN(0);
if (n_points == 53)
printf("xxx\n");
#endif /*NO_TESTING*/
return 0;
} }
int Gcalc_result_receiver::complete_shape() int Gcalc_result_receiver::complete_shape()
{ {
GCALC_DBUG_ENTER("Gcalc_result_receiver::complete_shape");
if (n_points == 0) if (n_points == 0)
{ {
buffer.length(shape_pos); buffer.length(shape_pos);
return 0; GCALC_DBUG_RETURN(0);
} }
if (n_points == 1) if (n_points == 1)
{ {
...@@ -489,7 +493,7 @@ int Gcalc_result_receiver::complete_shape() ...@@ -489,7 +493,7 @@ int Gcalc_result_receiver::complete_shape()
if (cur_shape == Gcalc_function::shape_hole) if (cur_shape == Gcalc_function::shape_hole)
{ {
buffer.length(shape_pos); buffer.length(shape_pos);
return 0; GCALC_DBUG_RETURN(0);
} }
cur_shape= Gcalc_function::shape_point; cur_shape= Gcalc_function::shape_point;
buffer.length(buffer.length()-4); buffer.length(buffer.length()-4);
...@@ -504,7 +508,7 @@ int Gcalc_result_receiver::complete_shape() ...@@ -504,7 +508,7 @@ int Gcalc_result_receiver::complete_shape()
if (fabs(shape_area) < 1e-8) if (fabs(shape_area) < 1e-8)
{ {
buffer.length(shape_pos); buffer.length(shape_pos);
return 0; GCALC_DBUG_RETURN(0);
} }
} }
...@@ -520,7 +524,7 @@ int Gcalc_result_receiver::complete_shape() ...@@ -520,7 +524,7 @@ int Gcalc_result_receiver::complete_shape()
} }
if (buffer.reserve(8*2, 512)) if (buffer.reserve(8*2, 512))
return 1; GCALC_DBUG_RETURN(1);
buffer.q_append(prev_x); buffer.q_append(prev_x);
buffer.q_append(prev_y); buffer.q_append(prev_y);
...@@ -540,7 +544,7 @@ do_complete: ...@@ -540,7 +544,7 @@ do_complete:
{ {
collection_result= true; collection_result= true;
} }
return 0; GCALC_DBUG_RETURN(0);
} }
...@@ -593,28 +597,30 @@ int Gcalc_result_receiver::move_hole(uint32 dest_position, uint32 source_positio ...@@ -593,28 +597,30 @@ int Gcalc_result_receiver::move_hole(uint32 dest_position, uint32 source_positio
{ {
char *ptr; char *ptr;
int source_len; int source_len;
GCALC_DBUG_ENTER("Gcalc_result_receiver::move_hole");
GCALC_DBUG_PRINT(("ps %d %d", dest_position, source_position));
*position_shift= source_len= buffer.length() - source_position; *position_shift= source_len= buffer.length() - source_position;
if (dest_position == source_position) if (dest_position == source_position)
return 0; GCALC_DBUG_RETURN(0);
if (buffer.reserve(source_len, MY_ALIGN(source_len, 512))) if (buffer.reserve(source_len, MY_ALIGN(source_len, 512)))
return 1; GCALC_DBUG_RETURN(1);
ptr= (char *) buffer.ptr(); ptr= (char *) buffer.ptr();
memmove(ptr + dest_position + source_len, ptr + dest_position, memmove(ptr + dest_position + source_len, ptr + dest_position,
buffer.length() - dest_position); buffer.length() - dest_position);
memcpy(ptr + dest_position, ptr + buffer.length(), source_len); memcpy(ptr + dest_position, ptr + buffer.length(), source_len);
return 0; GCALC_DBUG_RETURN(0);
} }
Gcalc_operation_reducer::Gcalc_operation_reducer(size_t blk_size) : Gcalc_operation_reducer::Gcalc_operation_reducer(size_t blk_size) :
Gcalc_dyn_list(blk_size, sizeof(res_point)), Gcalc_dyn_list(blk_size, sizeof(res_point)),
#ifndef DBUG_OFF #ifndef GCALC_DBUG_OFF
n_res_points(0), n_res_points(0),
#endif /*DBUG_OFF*/ #endif /*GCALC_DBUG_OFF*/
m_res_hook((Gcalc_dyn_list::Item **)&m_result), m_res_hook((Gcalc_dyn_list::Item **)&m_result),
m_first_active_thread(NULL) m_first_active_thread(NULL)
{} {}
...@@ -649,43 +655,35 @@ void Gcalc_operation_reducer::res_point::set(const Gcalc_scan_iterator *si) ...@@ -649,43 +655,35 @@ void Gcalc_operation_reducer::res_point::set(const Gcalc_scan_iterator *si)
pi= si->get_cur_pi(); pi= si->get_cur_pi();
} }
#ifndef NO_TESTING
void call_checkpoint(int d)
{
printf("%d\n", d);
}
#endif /*NO_TESTING*/
Gcalc_operation_reducer::res_point * Gcalc_operation_reducer::res_point *
Gcalc_operation_reducer::add_res_point(Gcalc_function::shape_type type) Gcalc_operation_reducer::add_res_point(Gcalc_function::shape_type type)
{ {
GCALC_DBUG_ENTER("Gcalc_operation_reducer::add_res_point");
res_point *result= (res_point *)new_item(); res_point *result= (res_point *)new_item();
*m_res_hook= result; *m_res_hook= result;
result->prev_hook= m_res_hook; result->prev_hook= m_res_hook;
m_res_hook= &result->next; m_res_hook= &result->next;
result->type= type; result->type= type;
#ifndef DBUG_OFF #ifndef GCALC_DBUG_OFF
result->point_n= n_res_points++; result->point_n= n_res_points++;
#endif /*DBUG_OFF*/ #endif /*GCALC_DBUG_OFF*/
#ifndef NO_TESTING GCALC_DBUG_RETURN(result);
if (result->point_n == 74)
call_checkpoint(74);
#endif /*NO_TESTING*/
return result;
} }
int Gcalc_operation_reducer::add_line(int incoming, active_thread *t, int Gcalc_operation_reducer::add_line(int incoming, active_thread *t,
const Gcalc_scan_iterator::point *p) const Gcalc_scan_iterator::point *p)
{ {
line *l= new_line(); line *l= new_line();
GCALC_DBUG_ENTER("Gcalc_operation_reducer::add_line");
if (!l) if (!l)
return 1; GCALC_DBUG_RETURN(1);
l->incoming= incoming; l->incoming= incoming;
l->t= t; l->t= t;
l->p= p; l->p= p;
*m_lines_hook= l; *m_lines_hook= l;
m_lines_hook= &l->next; m_lines_hook= &l->next;
return 0; GCALC_DBUG_RETURN(0);
} }
...@@ -693,15 +691,16 @@ int Gcalc_operation_reducer::add_poly_border(int incoming, ...@@ -693,15 +691,16 @@ int Gcalc_operation_reducer::add_poly_border(int incoming,
active_thread *t, int prev_state, const Gcalc_scan_iterator::point *p) active_thread *t, int prev_state, const Gcalc_scan_iterator::point *p)
{ {
poly_border *b= new_poly_border(); poly_border *b= new_poly_border();
GCALC_DBUG_ENTER("Gcalc_operation_reducer::add_poly_border");
if (!b) if (!b)
return 1; GCALC_DBUG_RETURN(1);
b->incoming= incoming; b->incoming= incoming;
b->t= t; b->t= t;
b->prev_state= prev_state; b->prev_state= prev_state;
b->p= p; b->p= p;
*m_poly_borders_hook= b; *m_poly_borders_hook= b;
m_poly_borders_hook= &b->next; m_poly_borders_hook= &b->next;
return 0; GCALC_DBUG_RETURN(0);
} }
...@@ -710,8 +709,9 @@ int Gcalc_operation_reducer::continue_range(active_thread *t, ...@@ -710,8 +709,9 @@ int Gcalc_operation_reducer::continue_range(active_thread *t,
const Gcalc_heap::Info *p_next) const Gcalc_heap::Info *p_next)
{ {
res_point *rp= add_res_point(t->rp->type); res_point *rp= add_res_point(t->rp->type);
GCALC_DBUG_ENTER("Gcalc_operation_reducer::continue_range");
if (!rp) if (!rp)
return 1; GCALC_DBUG_RETURN(1);
rp->glue= NULL; rp->glue= NULL;
rp->down= t->rp; rp->down= t->rp;
t->rp->up= rp; t->rp->up= rp;
...@@ -720,7 +720,7 @@ int Gcalc_operation_reducer::continue_range(active_thread *t, ...@@ -720,7 +720,7 @@ int Gcalc_operation_reducer::continue_range(active_thread *t,
t->rp= rp; t->rp= rp;
t->p1= p; t->p1= p;
t->p2= p_next; t->p2= p_next;
return 0; GCALC_DBUG_RETURN(0);
} }
...@@ -728,25 +728,27 @@ inline int Gcalc_operation_reducer::continue_i_range(active_thread *t, ...@@ -728,25 +728,27 @@ inline int Gcalc_operation_reducer::continue_i_range(active_thread *t,
const Gcalc_heap::Intersection_info *ii) const Gcalc_heap::Intersection_info *ii)
{ {
res_point *rp= add_res_point(t->rp->type); res_point *rp= add_res_point(t->rp->type);
GCALC_DBUG_ENTER("Gcalc_operation_reducer::continue_i_range");
if (!rp) if (!rp)
return 1; GCALC_DBUG_RETURN(1);
rp->glue= NULL; rp->glue= NULL;
rp->down= t->rp; rp->down= t->rp;
t->rp->up= rp; t->rp->up= rp;
rp->intersection_point= true; rp->intersection_point= true;
rp->ii= ii; rp->ii= ii;
t->rp= rp; t->rp= rp;
return 0; GCALC_DBUG_RETURN(0);
} }
int Gcalc_operation_reducer::end_couple(active_thread *t0, active_thread *t1, int Gcalc_operation_reducer::end_couple(active_thread *t0, active_thread *t1,
const Gcalc_heap::Info *p) const Gcalc_heap::Info *p)
{ {
res_point *rp0, *rp1; res_point *rp0, *rp1;
GCALC_DBUG_ENTER("Gcalc_operation_reducer::end_couple");
DBUG_ASSERT(t0->rp->type == t1->rp->type); DBUG_ASSERT(t0->rp->type == t1->rp->type);
if (!(rp0= add_res_point(t0->rp->type)) || if (!(rp0= add_res_point(t0->rp->type)) ||
!(rp1= add_res_point(t0->rp->type))) !(rp1= add_res_point(t0->rp->type)))
return 1; GCALC_DBUG_RETURN(1);
rp0->down= t0->rp; rp0->down= t0->rp;
rp1->down= t1->rp; rp1->down= t1->rp;
rp1->glue= rp0; rp1->glue= rp0;
...@@ -756,19 +758,13 @@ int Gcalc_operation_reducer::end_couple(active_thread *t0, active_thread *t1, ...@@ -756,19 +758,13 @@ int Gcalc_operation_reducer::end_couple(active_thread *t0, active_thread *t1,
t1->rp->up= rp1; t1->rp->up= rp1;
rp0->intersection_point= rp1->intersection_point= false; rp0->intersection_point= rp1->intersection_point= false;
rp0->pi= rp1->pi= p; rp0->pi= rp1->pi= p;
return 0; GCALC_DBUG_RETURN(0);
} }
#ifndef NO_TESTING
int ca_counter= 0;
#endif /*NO_TESTING*/
int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si) int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si)
{ {
Gcalc_point_iterator pi(si); Gcalc_point_iterator pi(si);
#ifdef TMP_BLOCK
const Gcalc_heap::Info *event_point= NULL;
#endif /*TMP_BLOCK*/
int prev_state= 0; int prev_state= 0;
int sav_prev_state; int sav_prev_state;
active_thread *prev_range= NULL; active_thread *prev_range= NULL;
...@@ -778,17 +774,10 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si) ...@@ -778,17 +774,10 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si)
active_thread **starting_t_hook; active_thread **starting_t_hook;
active_thread *bottom_threads= NULL; active_thread *bottom_threads= NULL;
active_thread *eq_thread, *point_thread;; active_thread *eq_thread, *point_thread;;
GCALC_DBUG_ENTER("Gcalc_operation_reducer::count_slice");
#ifndef NO_TESTING
if (ca_counter == 11522)
call_checkpoint(89);
#endif /*NO_TESTING*/
m_fn->clear_i_states(); m_fn->clear_i_states();
/* Walk to the event, remembering what is needed. */ /* Walk to the event, remembering what is needed. */
#ifndef NO_TESTING
if (si->get_event_position() == pi.point())
printf("yyy\n");
#endif /*NO_TESTING*/
for (; pi.point() != si->get_event_position(); for (; pi.point() != si->get_event_position();
++pi, cur_t_hook= (active_thread **) &(*cur_t_hook)->next) ++pi, cur_t_hook= (active_thread **) &(*cur_t_hook)->next)
{ {
...@@ -813,13 +802,13 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si) ...@@ -813,13 +802,13 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si)
{ {
if (cur_t->enabled() && if (cur_t->enabled() &&
continue_range(cur_t, events->pi, events->next_pi)) continue_range(cur_t, events->pi, events->next_pi))
return 1; GCALC_DBUG_RETURN(1);
break; break;
} }
case scev_end: case scev_end:
{ {
if (cur_t->enabled() && end_line(cur_t, si)) if (cur_t->enabled() && end_line(cur_t, si))
return 1; GCALC_DBUG_RETURN(1);
*cur_t_hook= cur_t->get_next(); *cur_t_hook= cur_t->get_next();
free_item(cur_t); free_item(cur_t);
break; break;
...@@ -830,13 +819,13 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si) ...@@ -830,13 +819,13 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si)
{ {
/* When two threads are ended here */ /* When two threads are ended here */
if (end_couple(cur_t, cur_t->get_next(), events->pi)) if (end_couple(cur_t, cur_t->get_next(), events->pi))
return 1; GCALC_DBUG_RETURN(1);
} }
else if (cur_t->enabled() || cur_t->get_next()->enabled()) else if (cur_t->enabled() || cur_t->get_next()->enabled())
{ {
/* Rare case when edges of a polygon coincide */ /* Rare case when edges of a polygon coincide */
if (end_line(cur_t->enabled() ? cur_t : cur_t->get_next(), si)) if (end_line(cur_t->enabled() ? cur_t : cur_t->get_next(), si))
return 1; GCALC_DBUG_RETURN(1);
} }
*cur_t_hook= cur_t->get_next()->get_next(); *cur_t_hook= cur_t->get_next()->get_next();
free_item(cur_t->next); free_item(cur_t->next);
...@@ -846,10 +835,7 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si) ...@@ -846,10 +835,7 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si)
default: default:
DBUG_ASSERT(0); DBUG_ASSERT(0);
} }
#ifndef NO_TESTING GCALC_DBUG_RETURN(0);
goto testing;
#endif /*NO_TESTING*/
return 0;
} }
starting_t_hook= cur_t_hook; starting_t_hook= cur_t_hook;
...@@ -860,10 +846,6 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si) ...@@ -860,10 +846,6 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si)
{ {
active_thread *cur_t= *cur_t_hook; active_thread *cur_t= *cur_t_hook;
#ifdef TMP_BLOCK
if (!event_point && events->event != scev_intersection)
event_point= events->pi;
#endif /*TMP_BLOCK*/
if (events->event == scev_single_point) if (events->event == scev_single_point)
continue; continue;
...@@ -872,7 +854,7 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si) ...@@ -872,7 +854,7 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si)
{ {
active_thread *new_t= new_active_thread(); active_thread *new_t= new_active_thread();
if (!new_t) if (!new_t)
return 1; GCALC_DBUG_RETURN(1);
new_t->rp= NULL; new_t->rp= NULL;
/* Insert into the main thread list before the current */ /* Insert into the main thread list before the current */
new_t->next= cur_t; new_t->next= cur_t;
...@@ -904,7 +886,7 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si) ...@@ -904,7 +886,7 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si)
{ {
active_thread *new_t= new_active_thread(); active_thread *new_t= new_active_thread();
if (!new_t) if (!new_t)
return 1; GCALC_DBUG_RETURN(1);
new_t->rp= NULL; new_t->rp= NULL;
/* Replace the current thread with the new. */ /* Replace the current thread with the new. */
new_t->next= cur_t->next; new_t->next= cur_t->next;
...@@ -952,12 +934,12 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si) ...@@ -952,12 +934,12 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si)
if (prev_state != after_state) if (prev_state != after_state)
{ {
if (add_poly_border(0, eq_thread, prev_state, eq_start)) if (add_poly_border(0, eq_thread, prev_state, eq_start))
return 1; GCALC_DBUG_RETURN(1);
} }
else if (!prev_state /* &&!after_state */ && in_state) else if (!prev_state /* &&!after_state */ && in_state)
{ {
if (add_line(0, eq_thread, eq_start)) if (add_line(0, eq_thread, eq_start))
return 1; GCALC_DBUG_RETURN(1);
} }
prev_state= after_state; prev_state= after_state;
...@@ -978,7 +960,7 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si) ...@@ -978,7 +960,7 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si)
for (events= si->get_events(); events; events= events->get_next()) for (events= si->get_events(); events; events= events->get_next())
m_fn->set_b_state(events->get_shape()); m_fn->set_b_state(events->get_shape());
return m_fn->count() ? add_single_point(si) : 0; GCALC_DBUG_RETURN(m_fn->count() ? add_single_point(si) : 0);
} }
if (m_poly_borders) if (m_poly_borders)
...@@ -988,10 +970,6 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si) ...@@ -988,10 +970,6 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si)
{ {
poly_border *pb1, *pb2; poly_border *pb1, *pb2;
pb1= m_poly_borders; pb1= m_poly_borders;
#ifndef NO_TESTING
if (!m_poly_borders->next)
call_checkpoint(3);
#endif /*NO_TESTING*/
DBUG_ASSERT(m_poly_borders->next); DBUG_ASSERT(m_poly_borders->next);
pb2= get_pair_border(pb1); pb2= get_pair_border(pb1);
...@@ -1000,7 +978,7 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si) ...@@ -1000,7 +978,7 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si)
if (connect_threads(pb1->incoming, pb2->incoming, if (connect_threads(pb1->incoming, pb2->incoming,
pb1->t, pb2->t, pb1->p, pb2->p, pb1->t, pb2->t, pb1->p, pb2->p,
prev_range, si, Gcalc_function::shape_polygon)) prev_range, si, Gcalc_function::shape_polygon))
return 1; GCALC_DBUG_RETURN(1);
free_item(pb1); free_item(pb1);
free_item(pb2); free_item(pb2);
...@@ -1019,7 +997,7 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si) ...@@ -1019,7 +997,7 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si)
m_lines->t, m_lines->get_next()->t, m_lines->t, m_lines->get_next()->t,
m_lines->p, m_lines->get_next()->p, m_lines->p, m_lines->get_next()->p,
NULL, si, Gcalc_function::shape_line)) NULL, si, Gcalc_function::shape_line))
return 1; GCALC_DBUG_RETURN(1);
} }
else else
{ {
...@@ -1028,7 +1006,7 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si) ...@@ -1028,7 +1006,7 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si)
if (cur_line->incoming) if (cur_line->incoming)
{ {
if (end_line(cur_line->t, si)) if (end_line(cur_line->t, si))
return 1; GCALC_DBUG_RETURN(1);
} }
else else
start_line(cur_line->t, cur_line->p, si); start_line(cur_line->t, cur_line->p, si);
...@@ -1042,57 +1020,19 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si) ...@@ -1042,57 +1020,19 @@ int Gcalc_operation_reducer::count_slice(Gcalc_scan_iterator *si)
if (bottom_threads) if (bottom_threads)
free_list(bottom_threads); free_list(bottom_threads);
#ifndef NO_TESTING GCALC_DBUG_RETURN(0);
testing:
{
Gcalc_point_iterator x_pi(si);
active_thread **x_cur_t_hook= &m_first_active_thread;
int x_prev_state= 0;
m_fn->save_states();
m_fn->clear_state();
if (ca_counter == /*11552*/90)
call_checkpoint(10);
for (; x_pi.point(); ++x_pi)
{
active_thread *cur_t= *x_cur_t_hook;
if (cur_t->enabled() &&
cur_t->rp->type == Gcalc_function::shape_polygon)
x_prev_state^= 1;
int ppb= m_fn->count();
if (m_fn->get_shape_kind(x_pi.get_shape()) == Gcalc_function::shape_polygon)
m_fn->invert_state(x_pi.get_shape());
int ppa= m_fn->count();
if (ppa != x_prev_state)
{
if (x_pi.point()->cmp_dx_dy(x_pi.point()->get_next()) != 0)
call_checkpoint(21);
}
if (cur_t->enabled())
{
if (m_fn->get_shape_kind(x_pi.get_shape()) == Gcalc_function::shape_polygon)
if (ppa == ppb)
call_checkpoint(22);
else
if (ppa != 0 && ppb != 0)
call_checkpoint(23);
}
x_cur_t_hook= (active_thread **) &(*x_cur_t_hook)->next;
}
m_fn->restore_states();
}
#endif /*NO_TESTING*/
return 0;
} }
int Gcalc_operation_reducer::add_single_point(const Gcalc_scan_iterator *si) int Gcalc_operation_reducer::add_single_point(const Gcalc_scan_iterator *si)
{ {
res_point *rp= add_res_point(Gcalc_function::shape_point); res_point *rp= add_res_point(Gcalc_function::shape_point);
GCALC_DBUG_ENTER("Gcalc_operation_reducer::add_single_point");
if (!rp) if (!rp)
return 1; GCALC_DBUG_RETURN(1);
rp->glue= rp->up= rp->down= NULL; rp->glue= rp->up= rp->down= NULL;
rp->set(si); rp->set(si);
return 0; GCALC_DBUG_RETURN(0);
} }
...@@ -1101,6 +1041,7 @@ Gcalc_operation_reducer::poly_border ...@@ -1101,6 +1041,7 @@ Gcalc_operation_reducer::poly_border
{ {
poly_border *prev_b= b1; poly_border *prev_b= b1;
poly_border *result= b1->get_next(); poly_border *result= b1->get_next();
GCALC_DBUG_ENTER("Gcalc_operation_reducer::get_pair_border");
if (b1->prev_state) if (b1->prev_state)
{ {
if (b1->incoming) if (b1->incoming)
...@@ -1140,7 +1081,7 @@ Gcalc_operation_reducer::poly_border ...@@ -1140,7 +1081,7 @@ Gcalc_operation_reducer::poly_border
} }
/* Delete the result from the list. */ /* Delete the result from the list. */
prev_b->next= result->next; prev_b->next= result->next;
return result; GCALC_DBUG_RETURN(result);
} }
...@@ -1151,13 +1092,15 @@ int Gcalc_operation_reducer::connect_threads( ...@@ -1151,13 +1092,15 @@ int Gcalc_operation_reducer::connect_threads(
active_thread *prev_range, active_thread *prev_range,
const Gcalc_scan_iterator *si, Gcalc_function::shape_type s_t) const Gcalc_scan_iterator *si, Gcalc_function::shape_type s_t)
{ {
GCALC_DBUG_ENTER("Gcalc_operation_reducer::connect_threads");
GCALC_DBUG_PRINT(("incoming %d %d", incoming_a, incoming_b));
if (incoming_a && incoming_b) if (incoming_a && incoming_b)
{ {
res_point *rpa, *rpb; res_point *rpa, *rpb;
DBUG_ASSERT(ta->rp->type == tb->rp->type); DBUG_ASSERT(ta->rp->type == tb->rp->type);
if (!(rpa= add_res_point(ta->rp->type)) || if (!(rpa= add_res_point(ta->rp->type)) ||
!(rpb= add_res_point(ta->rp->type))) !(rpb= add_res_point(ta->rp->type)))
return 1; GCALC_DBUG_RETURN(1);
rpa->down= ta->rp; rpa->down= ta->rp;
rpb->down= tb->rp; rpb->down= tb->rp;
rpb->glue= rpa; rpb->glue= rpa;
...@@ -1168,7 +1111,7 @@ int Gcalc_operation_reducer::connect_threads( ...@@ -1168,7 +1111,7 @@ int Gcalc_operation_reducer::connect_threads(
rpa->set(si); rpa->set(si);
rpb->set(si); rpb->set(si);
ta->rp= tb->rp= NULL; ta->rp= tb->rp= NULL;
return 0; GCALC_DBUG_RETURN(0);
} }
if (!incoming_a) if (!incoming_a)
{ {
...@@ -1176,7 +1119,7 @@ int Gcalc_operation_reducer::connect_threads( ...@@ -1176,7 +1119,7 @@ int Gcalc_operation_reducer::connect_threads(
res_point *rp0, *rp1; res_point *rp0, *rp1;
if (!(rp0= add_res_point(s_t)) || !(rp1= add_res_point(s_t))) if (!(rp0= add_res_point(s_t)) || !(rp1= add_res_point(s_t)))
return 1; GCALC_DBUG_RETURN(1);
rp0->glue= rp1; rp0->glue= rp1;
rp1->glue= rp0; rp1->glue= rp0;
rp0->set(si); rp0->set(si);
...@@ -1204,7 +1147,7 @@ int Gcalc_operation_reducer::connect_threads( ...@@ -1204,7 +1147,7 @@ int Gcalc_operation_reducer::connect_threads(
/* Chack if needed */ /* Chack if needed */
tb->thread_start= rp0; tb->thread_start= rp0;
} }
return 0; GCALC_DBUG_RETURN(0);
} }
/* else, if only ta is incoming */ /* else, if only ta is incoming */
...@@ -1217,15 +1160,12 @@ int Gcalc_operation_reducer::connect_threads( ...@@ -1217,15 +1160,12 @@ int Gcalc_operation_reducer::connect_threads(
if (si->intersection_step() ? if (si->intersection_step() ?
continue_i_range(tb, si->get_cur_ii()) : continue_i_range(tb, si->get_cur_ii()) :
continue_range(tb, si->get_cur_pi(), pb->next_pi)) continue_range(tb, si->get_cur_pi(), pb->next_pi))
#ifdef TMP_BLOCK GCALC_DBUG_RETURN(1);
continue_range(tb, si->get_cur_pi())
#endif /*TMP_BLOCK*/
return 1;
} }
tb->p1= pb->pi; tb->p1= pb->pi;
tb->p2= pb->next_pi; tb->p2= pb->next_pi;
return 0; GCALC_DBUG_RETURN(0);
} }
...@@ -1234,51 +1174,49 @@ int Gcalc_operation_reducer::start_line(active_thread *t, ...@@ -1234,51 +1174,49 @@ int Gcalc_operation_reducer::start_line(active_thread *t,
const Gcalc_scan_iterator *si) const Gcalc_scan_iterator *si)
{ {
res_point *rp= add_res_point(Gcalc_function::shape_line); res_point *rp= add_res_point(Gcalc_function::shape_line);
GCALC_DBUG_ENTER("Gcalc_operation_reducer::start_line");
if (!rp) if (!rp)
return 1; GCALC_DBUG_RETURN(1);
rp->glue= rp->down= NULL; rp->glue= rp->down= NULL;
rp->set(si); rp->set(si);
t->rp= rp; t->rp= rp;
t->p1= p->pi; t->p1= p->pi;
t->p2= p->next_pi; t->p2= p->next_pi;
return 0; GCALC_DBUG_RETURN(0);
} }
int Gcalc_operation_reducer::end_line(active_thread *t, int Gcalc_operation_reducer::end_line(active_thread *t,
const Gcalc_scan_iterator *si) const Gcalc_scan_iterator *si)
{ {
GCALC_DBUG_ENTER("Gcalc_operation_reducer::end_line");
DBUG_ASSERT(t->rp->type == Gcalc_function::shape_line); DBUG_ASSERT(t->rp->type == Gcalc_function::shape_line);
res_point *rp= add_res_point(Gcalc_function::shape_line); res_point *rp= add_res_point(Gcalc_function::shape_line);
if (!rp) if (!rp)
return 1; GCALC_DBUG_RETURN(1);
rp->glue= rp->up= NULL; rp->glue= rp->up= NULL;
rp->down= t->rp; rp->down= t->rp;
rp->set(si); rp->set(si);
t->rp->up= rp; t->rp->up= rp;
t->rp= NULL; t->rp= NULL;
return 0; GCALC_DBUG_RETURN(0);
} }
int Gcalc_operation_reducer::count_all(Gcalc_heap *hp) int Gcalc_operation_reducer::count_all(Gcalc_heap *hp)
{ {
Gcalc_scan_iterator si; Gcalc_scan_iterator si;
GCALC_DBUG_ENTER("Gcalc_operation_reducer::count_all");
si.init(hp); si.init(hp);
while (si.more_points()) while (si.more_points())
{ {
#ifndef NO_TESTING
printf("Point %d\n", ++ca_counter);
if (ca_counter == 12)
call_checkpoint(10);
#endif /*NO_TESTING*/
if (si.step()) if (si.step())
return 1; GCALC_DBUG_RETURN(1);
if (count_slice(&si)) if (count_slice(&si))
return 1; GCALC_DBUG_RETURN(1);
} }
return 0; GCALC_DBUG_RETURN(0);
} }
inline void Gcalc_operation_reducer::free_result(res_point *res) inline void Gcalc_operation_reducer::free_result(res_point *res)
...@@ -1294,23 +1232,21 @@ inline void Gcalc_operation_reducer::free_result(res_point *res) ...@@ -1294,23 +1232,21 @@ inline void Gcalc_operation_reducer::free_result(res_point *res)
inline int Gcalc_operation_reducer::get_single_result(res_point *res, inline int Gcalc_operation_reducer::get_single_result(res_point *res,
Gcalc_result_receiver *storage) Gcalc_result_receiver *storage)
{ {
GCALC_DBUG_ENTER("Gcalc_operation_reducer::get_single_result");
if (res->intersection_point) if (res->intersection_point)
{ {
double x, y; double x, y;
res->ii->calc_xy(&x, &y); res->ii->calc_xy(&x, &y);
if (storage->single_point(x,y)) if (storage->single_point(x,y))
return 1; GCALC_DBUG_RETURN(1);
} }
else else
if (storage->single_point(res->pi->x, res->pi->y)) if (storage->single_point(res->pi->x, res->pi->y))
return 1; GCALC_DBUG_RETURN(1);
free_result(res); free_result(res);
return 0; GCALC_DBUG_RETURN(0);
} }
#ifndef NO_TESTING
int pc_counter= 0;
#endif /*NO_TESTING*/
int Gcalc_operation_reducer::get_result_thread(res_point *cur, int Gcalc_operation_reducer::get_result_thread(res_point *cur,
Gcalc_result_receiver *storage, Gcalc_result_receiver *storage,
...@@ -1320,13 +1256,9 @@ int Gcalc_operation_reducer::get_result_thread(res_point *cur, ...@@ -1320,13 +1256,9 @@ int Gcalc_operation_reducer::get_result_thread(res_point *cur,
res_point *next; res_point *next;
bool glue_step= false; bool glue_step= false;
double x, y; double x, y;
GCALC_DBUG_ENTER("Gcalc_operation_reducer::get_result_thread");
while (cur) while (cur)
{ {
#ifndef NO_TESTING
++pc_counter;
if (pc_counter == 79)
call_checkpoint(79);
#endif /*NO_TESTING*/
if (!glue_step) if (!glue_step)
{ {
if (cur->intersection_point) if (cur->intersection_point)
...@@ -1339,7 +1271,7 @@ int Gcalc_operation_reducer::get_result_thread(res_point *cur, ...@@ -1339,7 +1271,7 @@ int Gcalc_operation_reducer::get_result_thread(res_point *cur,
y= cur->pi->y; y= cur->pi->y;
} }
if (storage->add_point(x, y)) if (storage->add_point(x, y))
return 1; GCALC_DBUG_RETURN(1);
} }
next= move_upward ? cur->up : cur->down; next= move_upward ? cur->up : cur->down;
...@@ -1358,7 +1290,7 @@ int Gcalc_operation_reducer::get_result_thread(res_point *cur, ...@@ -1358,7 +1290,7 @@ int Gcalc_operation_reducer::get_result_thread(res_point *cur,
free_result(cur); free_result(cur);
cur= next; cur= next;
} }
return 0; GCALC_DBUG_RETURN(0);
} }
...@@ -1366,11 +1298,12 @@ int Gcalc_operation_reducer::get_polygon_result(res_point *cur, ...@@ -1366,11 +1298,12 @@ int Gcalc_operation_reducer::get_polygon_result(res_point *cur,
Gcalc_result_receiver *storage, Gcalc_result_receiver *storage,
res_point *first_poly_node) res_point *first_poly_node)
{ {
GCALC_DBUG_ENTER("Gcalc_operation_reducer::get_polygon_result");
res_point *glue= cur->glue; res_point *glue= cur->glue;
glue->up->down= NULL; glue->up->down= NULL;
free_result(glue); free_result(glue);
return get_result_thread(cur, storage, 1, first_poly_node) || GCALC_DBUG_RETURN(get_result_thread(cur, storage, 1, first_poly_node) ||
storage->complete_shape(); storage->complete_shape());
} }
...@@ -1380,6 +1313,7 @@ int Gcalc_operation_reducer::get_line_result(res_point *cur, ...@@ -1380,6 +1313,7 @@ int Gcalc_operation_reducer::get_line_result(res_point *cur,
res_point *next; res_point *next;
res_point *cur_orig= cur; res_point *cur_orig= cur;
int move_upward= 1; int move_upward= 1;
GCALC_DBUG_ENTER("Gcalc_operation_reducer::get_line_result");
if (cur->glue) if (cur->glue)
{ {
/* Here we have to find the beginning of the line */ /* Here we have to find the beginning of the line */
...@@ -1405,8 +1339,8 @@ int Gcalc_operation_reducer::get_line_result(res_point *cur, ...@@ -1405,8 +1339,8 @@ int Gcalc_operation_reducer::get_line_result(res_point *cur,
} }
} }
return get_result_thread(cur, storage, move_upward, 0) || GCALC_DBUG_RETURN(get_result_thread(cur, storage, move_upward, 0) ||
storage->complete_shape(); storage->complete_shape());
} }
...@@ -1414,6 +1348,7 @@ int Gcalc_operation_reducer::get_result(Gcalc_result_receiver *storage) ...@@ -1414,6 +1348,7 @@ int Gcalc_operation_reducer::get_result(Gcalc_result_receiver *storage)
{ {
poly_instance *polygons= NULL; poly_instance *polygons= NULL;
GCALC_DBUG_ENTER("Gcalc_operation_reducer::get_result");
*m_res_hook= NULL; *m_res_hook= NULL;
while (m_result) while (m_result)
...@@ -1422,7 +1357,7 @@ int Gcalc_operation_reducer::get_result(Gcalc_result_receiver *storage) ...@@ -1422,7 +1357,7 @@ int Gcalc_operation_reducer::get_result(Gcalc_result_receiver *storage)
if (shape == Gcalc_function::shape_point) if (shape == Gcalc_function::shape_point)
{ {
if (get_single_result(m_result, storage)) if (get_single_result(m_result, storage))
return 1; GCALC_DBUG_RETURN(1);
continue; continue;
} }
if (shape == Gcalc_function::shape_polygon) if (shape == Gcalc_function::shape_polygon)
...@@ -1439,7 +1374,7 @@ int Gcalc_operation_reducer::get_result(Gcalc_result_receiver *storage) ...@@ -1439,7 +1374,7 @@ int Gcalc_operation_reducer::get_result(Gcalc_result_receiver *storage)
m_result->outer_poly->first_poly_node) || m_result->outer_poly->first_poly_node) ||
storage->move_hole(insert_position, hole_position, storage->move_hole(insert_position, hole_position,
&position_shift)) &position_shift))
return 1; GCALC_DBUG_RETURN(1);
for (cur_poly= polygons; for (cur_poly= polygons;
cur_poly && *cur_poly->after_poly_position >= insert_position; cur_poly && *cur_poly->after_poly_position >= insert_position;
cur_poly= cur_poly->get_next()) cur_poly= cur_poly->get_next())
...@@ -1454,7 +1389,7 @@ int Gcalc_operation_reducer::get_result(Gcalc_result_receiver *storage) ...@@ -1454,7 +1389,7 @@ int Gcalc_operation_reducer::get_result(Gcalc_result_receiver *storage)
polygons= p; polygons= p;
storage->start_shape(Gcalc_function::shape_polygon); storage->start_shape(Gcalc_function::shape_polygon);
if (get_polygon_result(m_result, storage, m_result)) if (get_polygon_result(m_result, storage, m_result))
return 1; GCALC_DBUG_RETURN(1);
*poly_position= storage->position(); *poly_position= storage->position();
} }
} }
...@@ -1462,13 +1397,13 @@ int Gcalc_operation_reducer::get_result(Gcalc_result_receiver *storage) ...@@ -1462,13 +1397,13 @@ int Gcalc_operation_reducer::get_result(Gcalc_result_receiver *storage)
{ {
storage->start_shape(shape); storage->start_shape(shape);
if (get_line_result(m_result, storage)) if (get_line_result(m_result, storage))
return 1; GCALC_DBUG_RETURN(1);
} }
} }
m_res_hook= (Gcalc_dyn_list::Item **)&m_result; m_res_hook= (Gcalc_dyn_list::Item **)&m_result;
storage->done(); storage->done();
return 0; GCALC_DBUG_RETURN(0);
} }
......
...@@ -222,9 +222,9 @@ public: ...@@ -222,9 +222,9 @@ public:
int get_result(Gcalc_result_receiver *storage); int get_result(Gcalc_result_receiver *storage);
void reset(); void reset();
#ifndef DBUG_OFF #ifndef GCALC_DBUG_OFF
int n_res_points; int n_res_points;
#endif /*DBUG_OFF*/ #endif /*GCALC_DBUG_OFF*/
class res_point : public Gcalc_dyn_list::Item class res_point : public Gcalc_dyn_list::Item
{ {
public: public:
...@@ -235,23 +235,19 @@ public: ...@@ -235,23 +235,19 @@ public:
const Gcalc_heap::Intersection_info *ii; const Gcalc_heap::Intersection_info *ii;
res_point *first_poly_node; res_point *first_poly_node;
}; };
#ifdef TMP_BLOCK
union union
{ {
#endif /*TMP_BLOCK*/
res_point *outer_poly; res_point *outer_poly;
uint32 poly_position; uint32 poly_position;
#ifdef TMP_BLOCK
}; };
#endif /*TMP_BLOCK*/
res_point *up; res_point *up;
res_point *down; res_point *down;
res_point *glue; res_point *glue;
Gcalc_function::shape_type type; Gcalc_function::shape_type type;
Gcalc_dyn_list::Item **prev_hook; Gcalc_dyn_list::Item **prev_hook;
#ifndef DBUG_OFF #ifndef GCALC_DBUG_OFF
int point_n; int point_n;
#endif /*DBUG_OFF*/ #endif /*GCALC_DBUG_OFF*/
void set(const Gcalc_scan_iterator *si); void set(const Gcalc_scan_iterator *si);
res_point *get_next() { return (res_point *)next; } res_point *get_next() { return (res_point *)next; }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment