33 #if defined(_VERBOSE_) || (_DEBUG_) || (_DEBUG_FULL_)
94 : xmin( aX ), xmax( aY )
95 , ymin( aX ), ymax( aY )
177 newShape->
type = GEOS_POLYGON;
181 newShape->
x =
new double[newShape->
nbPoints];
182 newShape->
y =
new double[newShape->
nbPoints];
184 std::cout <<
"New shape: ";
187 for ( j = 0, i = imin; i != ( imax + 1 ) %
nbPoints; i = ( i + 1 ) %
nbPoints, j++ )
189 newShape->
x[j] =
x[i];
190 newShape->
y[j] =
y[i];
192 std::cout <<
x[i] <<
";" <<
y[i] << std::endl;
199 newShape->
x[j] = fptx;
200 newShape->
y[j] = fpty;
202 std::cout << fptx <<
";" << fpty << std::endl;
207 std::cout <<
"J = " << j <<
"/" << newShape->
nbPoints << std::endl;
208 std::cout << std::endl;
209 std::cout <<
"This: " <<
this << std::endl;
217 LinkedList<PointSet*> *shapes_final,
218 double xrm,
double yrm,
char *uid )
221 std::cout <<
"splitPolygons: " << uid << std::endl;
258 double labelArea = xrm * yrm;
262 while ( shapes_toProcess->size() > 0 )
265 std::cout <<
"Shape popping()" << std::endl;
267 shape = shapes_toProcess->pop_front();
275 std::cout <<
"nbp: " << nbp << std::endl;
276 std::cout <<
" PtSet: ";
279 for ( i = 0; i < nbp; i++ )
283 std::cout << x[i] <<
";" << y[i] << std::endl;
288 std::cout << std::endl;
294 cHull = shape->
cHull;
299 std::cout <<
" CHull: ";
302 std::cout << cHull[i] <<
" ";
304 std::cout << std::endl;
314 ihn = ( ihs + 1 ) % cHullSize;
317 ipn = ( ips + 1 ) % nbp;
318 if ( ipn != cHull[ihn] )
323 for ( i = ips; i != cHull[ihn]; i = ( i + 1 ) % nbp )
326 x[cHull[ihn]], y[cHull[ihn]],
336 std::cout <<
"Deeper POint: " << pt <<
" between " << ips <<
" and " << cHull[ihn] << std::endl;
341 base =
dist_euc2d( x[cHull[ihs]], y[cHull[ihs]],
342 x[cHull[ihn]], y[cHull[ihn]] );
350 s = ( base + b + c ) / 2;
351 area = s * ( s - base ) * ( s - b ) * ( s - c );
356 if ( area - bestArea >
EPSILON )
373 bestArea = sqrt( bestArea );
374 double cx, cy, dx, dy, ex, ey, fx, fy, seg_length, ptx = 0, pty = 0, fptx = 0, fpty = 0;
375 int ps = -1, pe = -1, fps = -1, fpe = -1;
376 if ( retainedPt >= 0 && bestArea > labelArea )
379 std::cout <<
"Trou: " << retainedPt << std::endl;
380 std::cout <<
"Hole: " << cHull[holeS] <<
" -> " << cHull[holeE] << std::endl;
381 std::cout <<
"iterate from " << ( cHull[holeE] + 1 ) % nbp <<
" to " << ( cHull[holeS] - 1 + nbp ) % nbp << std::endl;
389 for ( i = ( cHull[holeE] + 1 ) % nbp; i != ( cHull[holeS] - 1 + nbp ) % nbp; i = j )
396 seg_length =
dist_euc2d( x[i], y[i], x[j], y[j] );
397 cx = ( x[i] + x[j] ) / 2.0;
398 cy = ( y[i] + y[j] ) / 2.0;
407 std::cout <<
"D: " << dx <<
" " << dy << std::endl;
408 std::cout <<
"seg_length: " << seg_length << std::endl;
410 if ( seg_length <
EPSILON ||
vabs(( b =
cross_product( ex, ey, fx, fy, x[retainedPt], y[retainedPt] ) / ( seg_length ) ) ) > ( seg_length / 2 ) )
412 if (( ex =
dist_euc2d_sq( x[i], y[i], x[retainedPt], y[retainedPt] ) ) < ( ey =
dist_euc2d_sq( x[j], y[j], x[retainedPt], y[retainedPt] ) ) )
427 b =
cross_product( x[i], y[i], x[j], y[j], x[retainedPt], y[retainedPt] ) / seg_length;
432 if ( !
computeLineIntersection( x[i], y[i], x[j], y[j], x[retainedPt], y[retainedPt], x[retainedPt] - dx, y[retainedPt] + dy, &ptx, &pty ) )
434 std::cout <<
"Oups ... il devrait par tomber la..." << std::endl;
437 std::cout <<
"intersection : " << x[i] <<
" " << y[i] <<
" " << x[j] <<
" " << y[j] <<
" " << x[retainedPt] <<
" " << y[retainedPt] <<
" " << x[retainedPt] - dx <<
" " << y[retainedPt] + dy << std::endl;
438 std::cout <<
" => " << ptx <<
";" << pty << std::endl;
439 std::cout <<
" cxy> " << cx <<
";" << cy << std::endl;
440 std::cout <<
" dxy> " << dx <<
";" << dy << std::endl;
445 double pointX, pointY;
457 for ( k = cHull[holeS]; k != cHull[holeE]; k = ( k + 1 ) % nbp )
461 if (
isSegIntersects( x[retainedPt], y[retainedPt], pointX, pointY, x[k], y[k], x[l], y[l] ) )
470 if ( isValid && b < c )
482 std::cout <<
" cut from " << retainedPt <<
" to ";
484 std::cout <<
"point " << fps << std::endl;
487 std::cout <<
"new point (" << fptx <<
";" << fpty <<
" between " << fps <<
" and " << fpe << std::endl;
492 int imin = retainedPt;
493 int imax = ((( fps < retainedPt && fpe < retainedPt ) || ( fps > retainedPt && fpe > retainedPt ) ) ?
min( fps, fpe ) :
max( fps, fpe ) );
495 int nbPtSh1, nbPtSh2;
497 nbPtSh1 = imax - imin + 1 + ( fpe != fps );
499 nbPtSh1 = imax + nbp - imin + 1 + ( fpe != fps );
501 if (( imax == fps ? fpe : fps ) < imin )
502 nbPtSh2 = imin - ( imax == fps ? fpe : fps ) + 1 + ( fpe != fps );
504 nbPtSh2 = imin + nbp - ( imax == fps ? fpe : fps ) + 1 + ( fpe != fps );
508 std::cout <<
"imin: " << imin <<
" imax:" << imax << std::endl;
510 if ( retainedPt == -1 || fps == -1 || fpe == -1 )
513 std::cout << std::endl <<
"Failed to split feature !!! (uid=" << uid <<
")" << std::endl;
519 else if ( imax == imin || nbPtSh1 <= 2 || nbPtSh2 <= 2 || nbPtSh1 == nbp || nbPtSh2 == nbp )
521 shapes_final->push_back( shape );
535 std::cout <<
"push back:" << std::endl;
536 for ( i = 0; i < newShape->
nbPoints; i++ )
538 std::cout << newShape->
x[i] <<
";" << newShape->
y[i] << std::endl;
542 shapes_toProcess->push_back( newShape );
549 newShape = shape->
extractShape( nbPtSh2, imax, imin, fps, fpe, fptx, fpty );
557 std::cout <<
"push back:" << std::endl;
558 for ( i = 0; i < newShape->
nbPoints; i++ )
560 std::cout << newShape->
x[i] <<
";" << newShape->
y[i] << std::endl;
563 shapes_toProcess->push_back( newShape );
572 std::cout <<
"Put shape into shapes_final" << std::endl;
574 shapes_final->push_back( shape );
584 std::cout <<
"CreateProblemSpecific:" << std::endl;
599 for (
int i = 0; i <
nbPoints; i++ )
601 shape->
x[i] = this->
x[i];
602 shape->
y[i] = this->
y[i];
605 if (
x[i] < bbmin[0] ||
x[i] > bbmax[0] ||
y[i] < bbmin[1] ||
y[i] > bbmax[1] )
637 double distNearestPoint;
643 double best_area = DBL_MAX;
644 double best_alpha = -1;
646 double best_length = 0;
647 double best_width = 0;
656 std::cout <<
"Compute_chull_bbox" << std::endl;
662 std::cout <<
x[
cHull[i]] <<
";" <<
y[
cHull[i]] << std::endl;
664 if (
x[
cHull[i]] < bbox[0] )
667 if (
x[cHull[i]] > bbox[2] )
668 bbox[2] =
x[cHull[i]];
670 if (
y[cHull[i]] < bbox[1] )
671 bbox[1] =
y[cHull[i]];
673 if (
y[cHull[i]] > bbox[3] )
674 bbox[3] =
y[cHull[i]];
678 dref = bbox[2] - bbox[0];
680 for ( alpha_d = 0; alpha_d < 90; alpha_d++ )
682 alpha = alpha_d *
M_PI / 180.0;
683 d1 = cos( alpha ) * dref;
684 d2 = sin( alpha ) * dref;
705 bb[14] = bb[12] + d2;
706 bb[15] = bb[13] - d1;
709 for ( i = 0; i < 16; i += 4 )
712 alpha_seg = (( i / 4 > 0 ? ( i / 4 ) - 1 : 3 ) ) *
M_PI / 2 + alpha;
724 distNearestPoint = best_cp / dref;
726 d1 = cos( alpha_seg ) * distNearestPoint;
727 d2 = sin( alpha_seg ) * distNearestPoint;
736 width =
cross_product( bb[6], bb[7], bb[4], bb[5], bb[12], bb[13] ) / dref;
737 length =
cross_product( bb[2], bb[3], bb[0], bb[1], bb[8], bb[9] ) / dref;
739 area = width * length;
745 if ( best_area - area >
EPSILON )
748 best_length = length;
751 memcpy( best_bb, bb,
sizeof(
double ) *16 );
759 for ( i = 0; i < 16; i = i + 4 )
762 best_bb[( i+4 ) %16], best_bb[( i+5 ) %16], best_bb[( i+6 ) %16], best_bb[( i+7 ) %16],
763 &finalBb->
x[int ( i/4 )], &finalBb->
y[int ( i/4 )] );
766 finalBb->
alpha = best_alpha;
767 finalBb->
width = best_width;
768 finalBb->
length = best_length;
771 std::cout <<
"FINAL" << std::endl;
772 std::cout <<
"Length : " << best_length << std::endl;
773 std::cout <<
"Width : " << best_width << std::endl;
774 std::cout <<
"Alpha: " << best_alpha <<
" " << best_alpha*180 /
M_PI << std::endl;
775 for ( i = 0; i < 4; i++ )
777 std::cout << finalBb->
x[0] <<
" " << finalBb->
y[0] <<
" ";
779 std::cout << std::endl;
786 double PointSet::getDistInside(
double px,
double py )
800 d = -( d * d * d * d );
812 double height = (
ymax -
ymin ) * 2;
823 for ( i = 0; i < 8; i++ )
858 j = ( i + 1 ) % nbPoints;
860 for ( k = 0; k < 8; k++ )
879 for ( i = 0; i < 8; i++ )
883 std::cout <<
"ERROR!!!!!!!!!!!!!!!!!" << std::endl;
889 a =
min( dist[0], dist[4] );
890 b =
min( dist[1], dist[5] );
891 c =
min( dist[2], dist[6] );
892 d =
min( dist[3], dist[7] );
912 if ( nbPoints == 1 ||
type == GEOS_POINT )
923 int nbP = (
type == GEOS_POLYGON ? nbPoints : nbPoints - 1 );
925 double best_dist = DBL_MAX;
928 for ( a = 0; a < nbP; a++ )
930 b = ( a + 1 ) % nbPoints;
933 px2 = px -
y[b] +
y[a];
934 py2 = py +
x[b] -
x[a];
940 x[a], y[a], x[b], y[b],
985 double cx = 0, cy = 0, A = 0, tmp, sumx = 0, sumy = 0;
988 j = i + 1;
if ( j == nbPoints ) j = 0;
989 tmp = ((
x[i] -
x[0] ) * (
y[j] -
y[0] ) - (
x[j] -
x[0] ) * (
y[i] -
y[0] ) );
990 cx += (
x[i] +
x[j] - 2 *
x[0] ) * tmp;
991 cy += (
y[i] +
y[j] - 2 *
y[0] ) * tmp;
1004 px = cx / ( 3 * A ) +
x[0];
1005 py = cy / ( 3 * A ) +
y[0];
1012 GEOSCoordSequence *coord = GEOSCoordSeq_create_r( geosctxt, nbPoints, 2 );
1014 for (
int i = 0; i <
nbPoints; ++i )
1016 GEOSCoordSeq_setX_r( geosctxt, coord, i,
x[i] );
1017 GEOSCoordSeq_setY_r( geosctxt, coord, i,
y[i] );
1020 GEOSGeometry *geom = GEOSGeom_createPolygon_r( geosctxt, GEOSGeom_createLinearRing_r( geosctxt, coord ), 0, 0 );
1024 GEOSGeometry *pointGeom = GEOSPointOnSurface_r( geosctxt, geom );
1028 const GEOSCoordSequence *coordSeq = GEOSGeom_getCoordSeq_r( geosctxt, pointGeom );
1029 GEOSCoordSeq_getX_r( geosctxt, coordSeq, 0, &px );
1030 GEOSCoordSeq_getY_r( geosctxt, coordSeq, 0, &py );
1032 GEOSGeom_destroy_r( geosctxt, pointGeom );
1034 GEOSGeom_destroy_r( geosctxt, geom );