1
0
Fork 0

some more very minor optimizations

This commit is contained in:
Peter Sadrozinski 2012-10-22 17:53:20 -04:00
parent 4f63c54d94
commit 7138b8509c
5 changed files with 31 additions and 16 deletions

View file

@ -53,15 +53,11 @@ SGVec3d TGConstruct::calc_normal( double area, Point3D p1, Point3D p2, Point3D p
const double area_eps = 1.0e-12;
if ( area < area_eps ) {
degenerate = true;
}
if ( fabs(p1.x() - p2.x()) < SG_EPSILON && fabs(p1.x() - p3.x()) < SG_EPSILON ) {
} else if ( fabs(p1.x() - p2.x()) < SG_EPSILON && fabs(p1.x() - p3.x()) < SG_EPSILON ) {
degenerate = true;
}
if ( fabs(p1.y() - p2.y()) < SG_EPSILON && fabs(p1.y() - p3.y()) < SG_EPSILON ) {
} else if ( fabs(p1.y() - p2.y()) < SG_EPSILON && fabs(p1.y() - p3.y()) < SG_EPSILON ) {
degenerate = true;
}
if ( fabs(p1.z() - p2.z()) < SG_EPSILON && fabs(p1.z() - p3.z()) < SG_EPSILON ) {
} else if ( fabs(p1.z() - p2.z()) < SG_EPSILON && fabs(p1.z() - p3.z()) < SG_EPSILON ) {
degenerate = true;
}

View file

@ -43,13 +43,15 @@ void TGShape::SetMask( TGPolygon mask )
void TGShape::BuildMask( void )
{
TGPolygon poly;
poly_list polys;
clip_mask.erase();
for (unsigned int i=0; i<sps.size(); i++)
{
poly = sps[i].get_poly();
clip_mask = tgPolygonUnion( clip_mask, poly );
polys.push_back( sps[i].get_poly() );
}
clip_mask = tgPolygonUnion( polys );
}
void TGShape::IntersectPolys( void )

View file

@ -41,9 +41,7 @@
// Calculate the area of a triangle
inline double triangle_area( const Point3D p1,
const Point3D p2,
const Point3D p3 )
inline double triangle_area( const Point3D& p1, const Point3D& p2, const Point3D& p3 )
{
return fabs(0.5 * ( p1.x() * p2.y() - p2.x() * p1.y() +
p2.x() * p3.y() - p3.x() * p2.y() +

View file

@ -605,6 +605,24 @@ TGPolygon tgPolygonUnion( const TGPolygon& subject, const TGPolygon& clip ) {
return polygon_clip_clipper( POLY_UNION, subject, clip );
}
TGPolygon tgPolygonUnion( const poly_list& clips )
{
ClipperLib::Polygons clipper_result;
ClipperLib::Clipper c;
TGPolygon result;
c.Clear();
for (unsigned int i=0; i<clips.size(); i++) {
ClipperLib::Polygons clipper_clip;
make_clipper_poly( clips[i], &clipper_clip );
c.AddPolygons(clipper_clip, ClipperLib::ptClip);
}
c.Execute(ClipperLib::ctUnion, clipper_result, ClipperLib::pftEvenOdd, ClipperLib::pftEvenOdd);
make_tg_poly_from_clipper( clipper_result, &result );
return result;
}

View file

@ -258,6 +258,7 @@ TGPolygon tgPolygonXor( const TGPolygon& subject, const TGPolygon& clip );
// Union
TGPolygon tgPolygonUnion( const TGPolygon& subject, const TGPolygon& clip );
TGPolygon tgPolygonUnion( const poly_list& clips );
// wrapper for clipper clip routines