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;
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -41,13 +41,11 @@
|
|||
|
||||
|
||||
// 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() +
|
||||
p3.x() * p1.y() - p1.x() * p3.y() ));
|
||||
p2.x() * p3.y() - p3.x() * p2.y() +
|
||||
p3.x() * p1.y() - p1.x() * p3.y() ));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -567,7 +567,7 @@ TGPolygon polygon_clip_clipper( clip_op poly_op, const TGPolygon& subject, const
|
|||
} else if ( poly_op == POLY_XOR ) {
|
||||
op = ClipperLib::ctXor;
|
||||
} else if ( poly_op == POLY_UNION ) {
|
||||
op = ClipperLib::ctUnion;
|
||||
op = ClipperLib::ctUnion;
|
||||
} else {
|
||||
throw sg_exception("Unknown polygon op, exiting.");
|
||||
}
|
||||
|
@ -581,7 +581,7 @@ TGPolygon polygon_clip_clipper( clip_op poly_op, const TGPolygon& subject, const
|
|||
|
||||
make_tg_poly_from_clipper( clipper_result, &result );
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue