34 #define _CRT_SECURE_NO_DEPRECATE
51 #define M_PI 3.1415926535897931159979634685
58 : id( id ), cost( cost ), feature( feature ), probFeat( 0 ), nbOverlap( 0 ), alpha( alpha ), w( w ), h( h ), nextPart( NULL ), partId( -1 ), reversed( isReversed ), upsideDown( false )
62 while ( this->alpha > 2*
M_PI )
63 this->alpha -= 2 *
M_PI;
65 while ( this->alpha < 0 )
66 this->alpha += 2 *
M_PI;
68 double beta = this->alpha + (
M_PI / 2 );
70 double dx1, dx2, dy1, dy2;
74 dx1 = cos( this->alpha ) *
w;
75 dy1 = sin( this->alpha ) *
w;
77 dx2 = cos( beta ) *
h;
78 dy2 = sin( beta ) *
h;
86 x[2] = x1 + dx1 + dx2;
87 y[2] = y1 + dy1 + dy2;
94 this->alpha >
M_PI / 2 && this->alpha <= 3*
M_PI / 2 )
96 bool uprightLabel =
false;
136 if ( this->alpha <
M_PI )
156 memcpy(
x, other.
x,
sizeof(
double )*4 );
157 memcpy(
y, other.
y,
sizeof(
double )*4 );
175 for ( i = 0; i < 4; i++ )
177 if (
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
178 y[i] >= bbox[1] &&
y[i] <= bbox[3] )
193 for ( i = 0; i < 4; i++ )
195 if (
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
196 y[i] >= bbox[1] &&
y[i] <= bbox[3] )
208 for (
int i = 0; i < 4; i++ )
210 if ( !(
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
211 y[i] >= bbox[1] &&
y[i] <= bbox[3] ) )
225 std::cout <<
" cost: " <<
cost;
226 std::cout <<
" alpha" <<
alpha << std::endl;
227 std::cout <<
x[0] <<
", " <<
y[0] << std::endl;
228 std::cout <<
x[1] <<
", " <<
y[1] << std::endl;
229 std::cout <<
x[2] <<
", " <<
y[2] << std::endl;
230 std::cout <<
x[3] <<
", " <<
y[3] << std::endl;
231 std::cout << std::endl;
253 for ( i = 0; i < 4; i++ )
259 for ( j = 0; j < 4; j++ )
267 lp->
x[i2], lp->
y[i2],
276 if ( d1 == -1 || d2 == -1 )
304 for (
int i = 0; i < 4; i++ )
322 return ( i >= 0 && i < 4 ?
x[i] : -1 );
327 return ( i >= 0 && i < 4 ?
y[i] : -1 );
368 for (
int c = 0; c < 4; c++ )
370 if (
x[c] < amin[0] )
372 if (
x[c] > amax[0] )
374 if (
y[c] < amin[1] )
376 if (
y[c] > amax[1] )
418 index->Remove( amin, amax,
this );
427 index->Insert( amin, amax,
this );
468 double *inactiveCost = ((
CountContext* ) ctx )->inactiveCost;
472 std::cout <<
"count overlap : " << lp->
id <<
"<->" << lp2->
id << std::endl;
507 double dist_min = DBL_MAX;
510 for ( i = 0; i < 4; i++ )
513 mx[i] = (
x[i] +
x[j] ) / 2.0;
514 my[i] = (
y[i] +
y[j] ) / 2.0;
520 if (
vabs( dist ) <
vabs( dist_min ) )
524 if (
vabs( dist ) <
vabs( dist_min ) )
531 if (
vabs( dist ) <
vabs( dist_min ) )
535 if (
vabs( dist ) <
vabs( dist_min ) )
539 for ( i = 0; i < 4; i++ )
542 if (
vabs( dist ) <
vabs( dist_min ) )
556 for (
int i = 0; i < 4; i++ )
561 feat->
x[j], feat->
y[j] );
563 feat->
x[j+1], feat->
y[j+1] );
565 if (( ca < 0 && cb > 0 ) || ( ca > 0 && cb < 0 ) )
570 x[( i+1 ) %4],
y[( i+1 ) %4] );
571 if (( ca < 0 && cb > 0 ) || ( ca > 0 && cb < 0 ) )
589 for ( k = 0; k < 4; k++ )
594 for ( a = 0; a < 2; a++ )
598 px = (
x[k] +
x[( k+1 ) %4] ) / 2.0;
599 py = (
y[k] +
y[( k+1 ) %4] ) / 2.0;
603 px = (
x[0] +
x[2] ) / 2.0;
604 py = (
y[0] +
y[2] ) / 2.0;