Loading files
f2929057eThis file is pinned to the selected release. Download the original to open it in your design tool.
// Copyright (c) 2025 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <gtest/gtest.h>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
#include <BRep_Tool.hxx>
#include <Geom_Ellipse.hxx>
#include <GeomAPI_ProjectPointOnSurf.hxx>
#include <Geom_CylindricalSurface.hxx>
#include <Geom_RectangularTrimmedSurface.hxx>
#include <TopExp_Explorer.hxx>
#include <TopAbs_ShapeEnum.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <TopLoc_Location.hxx>
#include <gp.hxx>
#include <gp_Ax2.hxx>
#include <gp_Dir.hxx>
#include <gp_Pnt.hxx>
#include <gp_Vec.hxx>
#include <Standard_Handle.hxx>
//=================================================================================================
// Bug OCC867: calling Init() with explicit UV bounds then Perform() must not throw.
// The bounds passed to Init() are intentionally tighter (U:[0,3]) than the trimmed surface
// (U:[0,4]) to reproduce the original bug scenario.
TEST(GeomAPI_ProjectPointOnSurfTest, Bug867_InitWithTightBoundsNoException)
{
const occ::handle<Geom_CylindricalSurface> aCyl = new Geom_CylindricalSurface(gp::XOY(), 10.0);
const occ::handle<Geom_RectangularTrimmedSurface> aTrimSurf =
new Geom_RectangularTrimmedSurface(aCyl, 0.0, 4.0, 0.0, 2.0);
const gp_Pnt aPoint(30.0, 30.0, 30.0);
GeomAPI_ProjectPointOnSurf aProjector;
EXPECT_NO_THROW({
aProjector.Init(aTrimSurf, 0.0, 3.0, 0.0, 2.0);
aProjector.Perform(aPoint);
});
// The original bug (OCC867) was that Init()+Perform() threw an exception.
// Whether a projection exists within the given UV bounds is not the concern here.
}
// Migrated from tests/bugs/moddata_3/bug24138. Projecting a point onto the
// lateral face generated by an elliptical wire must return stable UV and XYZ.
TEST(GeomAPI_ProjectPointOnSurfTest, OCC24138_ProjectPointOnEllipticalPrismFace)
{
const occ::handle<Geom_Ellipse> anEllipse =
new Geom_Ellipse(gp_Ax2(gp_Pnt(0.0, 0.0, 0.0), gp_Dir(0.0, 0.0, 1.0)), 10.0, 5.0);
const TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(anEllipse).Edge();
const TopoDS_Wire aWire = BRepBuilderAPI_MakeWire(anEdge).Wire();
const TopoDS_Shape aPrism = BRepPrimAPI_MakePrism(aWire, gp_Vec(2.0, 0.0, 30.0)).Shape();
TopExp_Explorer aFaceExplorer(aPrism, TopAbs_FACE);
ASSERT_TRUE(aFaceExplorer.More());
const TopoDS_Face aFace = TopoDS::Face(aFaceExplorer.Current());
TopLoc_Location aLocation;
const occ::handle<Geom_Surface> aSurface = BRep_Tool::Surface(aFace, aLocation);
ASSERT_FALSE(aSurface.IsNull());
const gp_Pnt aPoint(0.753071156928785, 4.98580193823337, 0.0);
double aUMin = 0.0;
double aUMax = 0.0;
double aVMin = 0.0;
double aVMax = 0.0;
aSurface->Bounds(aUMin, aUMax, aVMin, aVMax);
GeomAPI_ProjectPointOnSurf aProjector;
aProjector.Init(aSurface, aUMin, aUMax, aVMin, aVMax);
aProjector.SetExtremaAlgo(Extrema_ExtAlgo_Grad);
aProjector.SetExtremaFlag(Extrema_ExtFlag_MINMAX);
aProjector.Perform(aPoint);
ASSERT_TRUE(aProjector.IsDone());
ASSERT_GT(aProjector.NbPoints(), 0);
double aU = 0.0;
double aV = 0.0;
aProjector.LowerDistanceParameters(aU, aV);
const gp_Pnt aProjectedPoint = aProjector.NearestPoint();
EXPECT_NEAR(aProjector.LowerDistance(), 9.16061678111512e-10, 1.0e-7);
EXPECT_NEAR(aU, 1.4954178490327235, 1.0e-7);
EXPECT_NEAR(aV, 0.0, 1.0e-7);
EXPECT_NEAR(aProjectedPoint.X(), 0.75307115689421944, 1.0e-7);
EXPECT_NEAR(aProjectedPoint.Y(), 4.9858019383179632, 1.0e-7);
EXPECT_NEAR(aProjectedPoint.Z(), 0.0, 1.0e-7);
}