X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FPlaneGCSSolver%2FPlaneGCSSolver_EdgeWrapper.cpp;h=d1269bb1bf01420576fab3b5eab1e6014944ae20;hb=87447545000c44e455431ed0d401f850f373374e;hp=51cef8c47496036eb4ed8d5c4d414c3425b8d96e;hpb=fe3678a85238df2b57ea18b341003ebef176e287;p=modules%2Fshaper.git diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_EdgeWrapper.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_EdgeWrapper.cpp index 51cef8c47..d1269bb1b 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_EdgeWrapper.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_EdgeWrapper.cpp @@ -1,22 +1,88 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: PlaneGCSSolver_EdgeWrapper.cpp -// Created: 14 Dec 2015 -// Author: Artem ZHIDKOV +// Copyright (C) 2014-2020 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include +#include + +template +static bool isCurve(const GCSCurvePtr& theEntity) +{ + return std::dynamic_pointer_cast(theEntity).get(); +} + PlaneGCSSolver_EdgeWrapper::PlaneGCSSolver_EdgeWrapper(const GCSCurvePtr theEntity) : myEntity(theEntity) { - std::shared_ptr aLine = std::dynamic_pointer_cast(myEntity); - if (aLine) myType = ENTITY_LINE; - else { + if (isCurve(myEntity)) + myType = ENTITY_LINE; + else if (isCurve(myEntity)) + myType = ENTITY_ARC; + else if (isCurve(myEntity)) + myType = ENTITY_CIRCLE; + else if (isCurve(myEntity)) + myType = ENTITY_ELLIPTIC_ARC; + else if (isCurve(myEntity)) + myType = ENTITY_ELLIPSE; + else if (isCurve(myEntity)) + myType = ENTITY_BSPLINE; +} + +static double squareDistance(const GCS::Point& theP1, const GCS::Point& theP2) +{ + double dx = *theP1.x - *theP2.x; + double dy = *theP1.y - *theP2.y; + return dx*dx + dy*dy; +} + +bool PlaneGCSSolver_EdgeWrapper::isDegenerated() const +{ + static const double THE_SQ_TOL = tolerance * 1e-2; + static const double THE_ANGLE_TOL = 1.e-5; + static const double THE_MAX_RADIUS = 1e8; + static const double THE_SQ_MAX_RADIUS = THE_MAX_RADIUS * THE_MAX_RADIUS; + + if (myType == ENTITY_LINE) { + std::shared_ptr aLine = std::dynamic_pointer_cast(myEntity); + return squareDistance(aLine->p1, aLine->p2) < THE_SQ_TOL; + } + else if (myType == ENTITY_CIRCLE) { + std::shared_ptr aCircle = std::dynamic_pointer_cast(myEntity); + return *aCircle->rad < tolerance || *aCircle->rad > THE_MAX_RADIUS; + } + else if (myType == ENTITY_ARC) { std::shared_ptr anArc = std::dynamic_pointer_cast(myEntity); - if (anArc) myType = ENTITY_ARC; - else { - std::shared_ptr aCircle = std::dynamic_pointer_cast(myEntity); - if (aCircle) myType = ENTITY_CIRCLE; - } + double anAngleDiff = fabs(*anArc->startAngle - *anArc->endAngle); + double aSqRadius = squareDistance(anArc->center, anArc->start); + return aSqRadius < THE_SQ_TOL || aSqRadius > THE_SQ_MAX_RADIUS || // <- arc radius + anAngleDiff < THE_ANGLE_TOL || fabs(anAngleDiff - 2*PI) < THE_ANGLE_TOL; // <- arc angle + } + else if (myType == ENTITY_ELLIPSE) { + std::shared_ptr anEllipse = std::dynamic_pointer_cast(myEntity); + return *anEllipse->radmin < tolerance || anEllipse->getRadMaj() > THE_MAX_RADIUS; + } + else if (myType == ENTITY_ELLIPTIC_ARC) { + std::shared_ptr anArc = + std::dynamic_pointer_cast(myEntity); + double anAngleDiff = fabs(*anArc->startAngle - *anArc->endAngle); + return *anArc->radmin < THE_SQ_TOL || anArc->getRadMaj() > THE_SQ_MAX_RADIUS || // <- arc radius + anAngleDiff < THE_ANGLE_TOL || fabs(anAngleDiff - 2*PI) < THE_ANGLE_TOL; // <- arc angle } + return false; }