new GeomAPI_Pnt(aResult.X(), aResult.Y(), aResult.Z()));
}
-const std::shared_ptr<GeomAPI_Pnt> GeomAPI_Lin::project(
- const std::shared_ptr<GeomAPI_Pnt>& thePoint) const
+double GeomAPI_Lin::projParam(
+ const std::shared_ptr<GeomAPI_Pnt>& thePoint) const
{
const gp_XYZ& aDir = MY_LIN->Direction().XYZ();
const gp_XYZ& aLoc = MY_LIN->Location().XYZ();
const gp_XYZ& aPnt = thePoint->impl<gp_Pnt>().XYZ();
- double aParam = aDir.Dot(aPnt - aLoc);
+ return aDir.Dot(aPnt - aLoc);
+}
+const std::shared_ptr<GeomAPI_Pnt> GeomAPI_Lin::project(
+ const std::shared_ptr<GeomAPI_Pnt>& thePoint) const
+{
+ const gp_XYZ& aDir = MY_LIN->Direction().XYZ();
+ const gp_XYZ& aLoc = MY_LIN->Location().XYZ();
+ double aParam = projParam(thePoint);
gp_XYZ aResult = aLoc + aDir * aParam;
return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aResult.X(), aResult.Y(), aResult.Z()));
}
const std::shared_ptr<GeomAPI_Pnt> project(
const std::shared_ptr<GeomAPI_Pnt>& thePoint) const;
+ /// Returns parameter of the point projection
+ GEOMAPI_EXPORT
+ double projParam(const std::shared_ptr<GeomAPI_Pnt>& thePoint) const;
+
/// \return true if this line contains thePoint, that is,
/// if the distance between thePoint and this line
/// is less than or equal to theLinearTolerance.
std::shared_ptr<GeomAPI_Lin> aLin2 = aEdge2->line();
std::shared_ptr<GeomAPI_Pnt> aPnt = aLin1->intersect(aLin2);
+ double aParam1 = aLin1->projParam(aPnt);
+ double aParam2 = aLin2->projParam(aPnt);
+
+ GeomAPI_Curve aCurve1(aShp1);
+ GeomAPI_Curve aCurve2(aShp2);
+ bool isInside1 = ((aParam1 - aCurve1.startParam()) >= -Precision::Confusion()) &&
+ ((aCurve1.endParam() - aParam1) >= Precision::Confusion());
+ bool isInside2 = ((aParam2 - aCurve2.startParam()) >= -Precision::Confusion()) &&
+ ((aCurve2.endParam() - aParam2) >= Precision::Confusion());
+
+ if (!(isInside1 && isInside2))
+ aPnt = std::shared_ptr<GeomAPI_Pnt>();
// Compute position of symbols
SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get();
gp_Pnt aP1 = aMgr->getPosition(aObj1, this, theStep, aPnt);
- //gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep);
- myPntArray = new Graphic3d_ArrayOfPoints(1, withColor);
+ myPntArray = new Graphic3d_ArrayOfPoints(aPnt.get()? 1 : 2, withColor);
myPntArray->AddVertex(aP1);
- //myPntArray->AddVertex(aP2);
+ if (!aPnt.get()) {
+ gp_Pnt aP2 = aMgr->getPosition(aObj2, this, theStep);
+ myPntArray->AddVertex(aP2);
+ }
return true;
}
#include <GeomAPI_Dir.h>
#include <GeomAPI_Ax3.h>
#include <GeomAPI_Circ.h>
+#include <GeomAPI_Lin2d.h>
#include <GeomDataAPI_Point2D.h>
GeomPnt2dPtr aPnt2 = aSPnt2->pnt();
if (aPnt1->isEqual(aPnt2d) || aPnt2->isEqual(aPnt2d)) {
+ // a point corresponds to one of the line end
GeomShapePtr aShp = SketcherPrs_Tools::getShape(aFeature->firstResult());
GeomCurvePtr aCurv = std::shared_ptr<GeomAPI_Curve>(new GeomAPI_Curve(aShp));
aList.push_back(aFeature->firstResult());
+ } else {
+ // Check that a point belongs to the curve
+ GeomAPI_Lin2d aLin2d(aPnt1, aPnt2);
+ double aDist = aLin2d.distance(aPnt2d);
+ if (aDist <= Precision::Confusion())
+ aList.push_back(aFeature->firstResult());
}
} else if ((aFeature->getKind() == SketchPlugin_Circle::ID()) ||
(aFeature->getKind() == SketchPlugin_Arc::ID())) {