78 if( p1->
Get_X() < p2->
Get_X() ) {
return( -1 ); }
79 if( p1->
Get_X() > p2->
Get_X() ) {
return( 1 ); }
80 if( p1->
Get_Y() < p2->
Get_Y() ) {
return( -1 ); }
81 if( p1->
Get_Y() > p2->
Get_Y() ) {
return( 1 ); }
103 Nodes[i] =
Get_Node(i); Nodes[i]->_Del_Relations();
111 Nodes[i] = Nodes[j++];
114 && Nodes[i]->Get_X() == Nodes[j]->Get_X()
115 && Nodes[i]->Get_Y() == Nodes[j]->Get_Y() )
136 _Add_Triangle(Nodes[Triangles[i].p1], Nodes[Triangles[i].p2], Nodes[Triangles[i].p3]);
167 for(
int i=1; i<nPoints; i++)
177 int status = 0, emax = 200, trimax = 4 * nPoints;
180 int *complete = (
int *)
SG_Malloc(trimax *
sizeof(
int));
182 if( complete == NULL )
192 SG_Free(complete);
return(
false );
214 Triangles[0].
p1 = nPoints;
215 Triangles[0].
p2 = nPoints + 1;
216 Triangles[0].
p3 = nPoints + 2;
218 complete [0] =
false;
226 double xp = Points[i]->
Get_X();
227 double yp = Points[i]->
Get_Y();
236 for(
int j=0; j<nTriangles; j++)
243 double x1 = Points[Triangles[j].
p1]->
Get_X();
244 double y1 = Points[Triangles[j].
p1]->
Get_Y();
245 double x2 = Points[Triangles[j].
p2]->
Get_X();
246 double y2 = Points[Triangles[j].
p2]->
Get_Y();
247 double x3 = Points[Triangles[j].
p3]->
Get_X();
248 double y3 = Points[Triangles[j].
p3]->
Get_Y();
250 double xc, yc, r;
int inside =
_CircumCircle(xp, yp, x1, y1, x2, y2, x3, y3, &xc, &yc, &r);
259 if( nedge + 3 >= emax )
271 edges[nedge + 0].
p1 = Triangles[j].
p1;
272 edges[nedge + 0].
p2 = Triangles[j].
p2;
273 edges[nedge + 1].
p1 = Triangles[j].
p2;
274 edges[nedge + 1].
p2 = Triangles[j].
p3;
275 edges[nedge + 2].
p1 = Triangles[j].
p3;
276 edges[nedge + 2].
p2 = Triangles[j].
p1;
280 Triangles[j] = Triangles[nTriangles - 1];
281 complete [j] = complete [nTriangles - 1];
291 for(
int j=0; j<nedge-1; j++)
293 for(
int k=j+1; k<nedge; k++)
295 if( (edges[j].p1 == edges[k].p2) && (edges[j].p2 == edges[k].p1) )
304 if( (edges[j].p1 == edges[k].p1) && (edges[j].p2 == edges[k].p2) )
318 for(
int j=0; j<nedge; j++)
320 if( edges[j].p1 < 0 || edges[j].p2 < 0 )
325 if( nTriangles >= trimax )
330 Triangles[nTriangles].
p1 = edges[j].
p1;
331 Triangles[nTriangles].
p2 = edges[j].
p2;
332 Triangles[nTriangles].
p3 = i;
333 complete [nTriangles] =
false;
341 for(
int i=0; i<nTriangles; i++)
343 if( Triangles[i].p1 >= nPoints
344 || Triangles[i].p2 >= nPoints
345 || Triangles[i].p3 >= nPoints )
347 Triangles[i] = Triangles[nTriangles - 1];
370 #define IS_IDENTICAL(a, b) (a == b) // #define IS_IDENTICAL(a, b) (fabs(a - b) < 0.0001)
373 int CSG_TIN::_CircumCircle(
double xp,
double yp,
double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double *xc,
double *yc,
double *r)
375 double m1, m2, mx1, mx2, my1, my2,
387 m2 = -(x3 - x2) / (y3 - y2);
388 mx2 = (x2 + x3) / 2.0;
389 my2 = (y2 + y3) / 2.0;
390 *xc = (x2 + x1) / 2.0;
392 *yc = m2 * (*xc - mx2) + my2;
396 m1 = -(x2 - x1) / (y2 - y1);
397 mx1 = (x1 + x2) / 2.0;
398 my1 = (y1 + y2) / 2.0;
399 *xc = (x3 + x2) / 2.0;
401 *yc = m1 * (*xc - mx1) + my1;
405 m1 = -(x2 - x1) / (y2 - y1);
406 m2 = -(x3 - x2) / (y3 - y2);
407 mx1 = (x1 + x2) / 2.0;
408 mx2 = (x2 + x3) / 2.0;
409 my1 = (y1 + y2) / 2.0;
410 my2 = (y2 + y3) / 2.0;
412 *xc = (m1 * mx1 - m2 * mx2 + my2 - my1) / (m1 - m2);
413 *yc = m1 * (*xc - mx1) + my1;
419 rsqr = dx*dx + dy*dy;
424 drsqr = dx*dx + dy*dy;
426 return( drsqr <= rsqr ? 1 : 0 );