some more very minor optimizations
This commit is contained in:
parent
4f63c54d94
commit
7138b8509c
5 changed files with 31 additions and 16 deletions
|
@ -53,15 +53,11 @@ SGVec3d TGConstruct::calc_normal( double area, Point3D p1, Point3D p2, Point3D p
|
||||||
const double area_eps = 1.0e-12;
|
const double area_eps = 1.0e-12;
|
||||||
if ( area < area_eps ) {
|
if ( area < area_eps ) {
|
||||||
degenerate = true;
|
degenerate = true;
|
||||||
}
|
} else if ( fabs(p1.x() - p2.x()) < SG_EPSILON && fabs(p1.x() - p3.x()) < SG_EPSILON ) {
|
||||||
|
|
||||||
if ( fabs(p1.x() - p2.x()) < SG_EPSILON && fabs(p1.x() - p3.x()) < SG_EPSILON ) {
|
|
||||||
degenerate = true;
|
degenerate = true;
|
||||||
}
|
} else if ( fabs(p1.y() - p2.y()) < SG_EPSILON && fabs(p1.y() - p3.y()) < SG_EPSILON ) {
|
||||||
if ( fabs(p1.y() - p2.y()) < SG_EPSILON && fabs(p1.y() - p3.y()) < SG_EPSILON ) {
|
|
||||||
degenerate = true;
|
degenerate = true;
|
||||||
}
|
} else if ( fabs(p1.z() - p2.z()) < SG_EPSILON && fabs(p1.z() - p3.z()) < SG_EPSILON ) {
|
||||||
if ( fabs(p1.z() - p2.z()) < SG_EPSILON && fabs(p1.z() - p3.z()) < SG_EPSILON ) {
|
|
||||||
degenerate = true;
|
degenerate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,13 +43,15 @@ void TGShape::SetMask( TGPolygon mask )
|
||||||
void TGShape::BuildMask( void )
|
void TGShape::BuildMask( void )
|
||||||
{
|
{
|
||||||
TGPolygon poly;
|
TGPolygon poly;
|
||||||
|
poly_list polys;
|
||||||
clip_mask.erase();
|
clip_mask.erase();
|
||||||
|
|
||||||
for (unsigned int i=0; i<sps.size(); i++)
|
for (unsigned int i=0; i<sps.size(); i++)
|
||||||
{
|
{
|
||||||
poly = sps[i].get_poly();
|
polys.push_back( sps[i].get_poly() );
|
||||||
clip_mask = tgPolygonUnion( clip_mask, poly );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clip_mask = tgPolygonUnion( polys );
|
||||||
}
|
}
|
||||||
|
|
||||||
void TGShape::IntersectPolys( void )
|
void TGShape::IntersectPolys( void )
|
||||||
|
|
|
@ -41,9 +41,7 @@
|
||||||
|
|
||||||
|
|
||||||
// Calculate the area of a triangle
|
// Calculate the area of a triangle
|
||||||
inline double triangle_area( const Point3D p1,
|
inline double triangle_area( const Point3D& p1, const Point3D& p2, const Point3D& p3 )
|
||||||
const Point3D p2,
|
|
||||||
const Point3D p3 )
|
|
||||||
{
|
{
|
||||||
return fabs(0.5 * ( p1.x() * p2.y() - p2.x() * p1.y() +
|
return fabs(0.5 * ( p1.x() * p2.y() - p2.x() * p1.y() +
|
||||||
p2.x() * p3.y() - p3.x() * p2.y() +
|
p2.x() * p3.y() - p3.x() * p2.y() +
|
||||||
|
|
|
@ -605,6 +605,24 @@ TGPolygon tgPolygonUnion( const TGPolygon& subject, const TGPolygon& clip ) {
|
||||||
return polygon_clip_clipper( POLY_UNION, subject, 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -258,6 +258,7 @@ TGPolygon tgPolygonXor( const TGPolygon& subject, const TGPolygon& clip );
|
||||||
|
|
||||||
// Union
|
// Union
|
||||||
TGPolygon tgPolygonUnion( const TGPolygon& subject, const TGPolygon& clip );
|
TGPolygon tgPolygonUnion( const TGPolygon& subject, const TGPolygon& clip );
|
||||||
|
TGPolygon tgPolygonUnion( const poly_list& clips );
|
||||||
|
|
||||||
// wrapper for clipper clip routines
|
// wrapper for clipper clip routines
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue