hasDirection[i] = aSrcDstDirections[i].SquareMagnitude() >= Precision::SquareConfusion();
}
+ // Initial shapes
+ const TopoDS_Shape& aSourceShape = theSourceSolid->impl<TopoDS_Shape>();
+ const TopoDS_Shape& aDestShape = theDestSolid->impl<TopoDS_Shape>();
+ // Check the material of the solids to be on the correct side
+ BRepClass3d_SolidClassifier aClassifier;
+ static const double aTransStep = 10. * Precision::Confusion();
+ if (hasNormal[0]) {
+ aClassifier.Load(aSourceShape);
+ gp_Pnt aPoint = aSrcDstPoints[0];
+ aPoint.Translate(aSrcDstNormals[0] * aTransStep);
+ aClassifier.Perform(aPoint, Precision::Confusion());
+ if ((aClassifier.State() == TopAbs_OUT && !theIsReverse) ||
+ (aClassifier.State() == TopAbs_IN && theIsReverse))
+ aSrcDstNormals[0].Reverse();
+ }
+ if (hasNormal[1]) {
+ aClassifier.Load(aDestShape);
+ gp_Pnt aPoint = aSrcDstPoints[1];
+ aPoint.Translate(aSrcDstNormals[1] * aTransStep);
+ aClassifier.Perform(aPoint, Precision::Confusion());
+ if (aClassifier.State() == TopAbs_IN)
+ aSrcDstNormals[1].Reverse();
+ }
+
// Calculate directions, which comply the normal, for vertices and edges
if (!hasNormal[0] || !hasNormal[1]) {
if (hasNormal[0] || hasNormal[1]) { // plane with line or vertex
}
aSrcDstNormals[0] = aSrcDstDirections[0].Crossed(aVec);
aSrcDstNormals[0].Normalize();
- aSrcDstNormals[1] = aSrcDstDirections[1].Crossed(aVec).Reversed();
+ aSrcDstNormals[1] = aSrcDstDirections[1].Crossed(aVec);
aSrcDstNormals[1].Normalize();
+ if (aSrcDstDirections[0].Dot(aSrcDstDirections[1]) < -Precision::Confusion())
+ aSrcDstNormals[1].Reverse();
} else if (!hasDirection[0] && !hasDirection[1]) { // point - point
aSrcDstNormals[0] = gp_Vec(aSrcDstPoints[0], aSrcDstPoints[1]);
aSrcDstNormals[0].Normalize();
}
}
- // Initial shapes
- const TopoDS_Shape& aSourceShape = theSourceSolid->impl<TopoDS_Shape>();
- const TopoDS_Shape& aDestShape = theDestSolid->impl<TopoDS_Shape>();
+ // Reverse the normal if it was not done before
+ if (!hasNormal[0] && theIsReverse)
+ aSrcDstNormals[0].Reverse();
// Calculate transformation
gp_Trsf aTrsf;
gp_Vec aSrcDir = aSrcDstNormals[0];
gp_Vec aDstDir = aSrcDstNormals[1];
- // Check the material of the solids to be on the correct side
- BRepClass3d_SolidClassifier aClassifier;
- static const double aTransStep = 10. * Precision::Confusion();
- if (hasNormal[0]) {
- aClassifier.Load(aSourceShape);
- gp_Pnt aPoint = aSrcDstPoints[0];
- aPoint.Translate(aSrcDir * aTransStep);
- aClassifier.Perform(aPoint, Precision::Confusion());
- if ((aClassifier.State() == TopAbs_OUT && !theIsReverse) ||
- (aClassifier.State() == TopAbs_IN && theIsReverse))
- aSrcDir.Reverse();
- } else if (theIsReverse)
- aSrcDir.Reverse();
- if (hasNormal[1]) {
- aClassifier.Load(aDestShape);
- gp_Pnt aPoint = aSrcDstPoints[1];
- aPoint.Translate(aDstDir * aTransStep);
- aClassifier.Perform(aPoint, Precision::Confusion());
- if (aClassifier.State() == TopAbs_IN)
- aDstDir.Reverse();
- }
// Calculate rotation
gp_Quaternion aRot(aSrcDir, aDstDir);
aTrsf.SetRotation(aRot);