11// Part of the Chili3d Project, under the AGPL-3.0 License.
22// See LICENSE file in the project root for full license information.
33
4- #include " shared.hpp"
5- #include " utils.hpp"
4+ #include < GCPnts_AbscissaPoint.hxx>
5+ #include < GCPnts_UniformAbscissa.hxx>
6+ #include < GeomAPI_ExtremaCurveCurve.hxx>
7+ #include < GeomAPI_ProjectPointOnCurve.hxx>
8+ #include < GeomAPI_ProjectPointOnSurf.hxx>
9+ #include < GeomLib_IsPlanarSurface.hxx>
10+ #include < GeomLib_Tool.hxx>
11+ #include < GeomProjLib.hxx>
612#include < Geom_Curve.hxx>
713#include < Geom_Line.hxx>
814#include < Geom_Surface.hxx>
9- #include < GeomAPI_ProjectPointOnCurve.hxx>
10- #include < GeomLib_Tool.hxx>
1115#include < Geom_TrimmedCurve.hxx>
1216#include < Standard_Handle.hxx>
1317#include < gp_Dir.hxx>
1418#include < gp_Pnt.hxx>
1519#include < optional>
16- #include < GeomProjLib.hxx>
17- #include < GeomAPI_ProjectPointOnSurf.hxx>
18- #include < GeomLib_IsPlanarSurface.hxx>
19- #include < optional>
20- #include < GeomAPI_ExtremaCurveCurve.hxx>
21- #include < GCPnts_UniformAbscissa.hxx>
22- #include < GCPnts_AbscissaPoint.hxx>
2320
24- using namespace emscripten ;
21+ #include " shared.hpp"
22+ #include " utils.hpp"
2523
24+ using namespace emscripten ;
2625
2726class Curve {
2827private:
29- static Vector3Array getPoints (const GCPnts_UniformAbscissa& uniformAbscissa, const Geom_Curve* curve) {
28+ static Vector3Array getPoints (const GCPnts_UniformAbscissa& uniformAbscissa,
29+ const Geom_Curve* curve)
30+ {
3031 std::vector<Vector3> points;
3132 for (int i = 1 ; i <= uniformAbscissa.NbPoints (); i++) {
32- points.push_back (Vector3::fromPnt (curve->Value (uniformAbscissa.Parameter (i))));
33+ points.push_back (
34+ Vector3::fromPnt (curve->Value (uniformAbscissa.Parameter (i))));
3335 }
3436 return Vector3Array (val::array (points));
3537 }
3638
3739public:
38- static Handle_Geom_Line makeLine (const Vector3& start, const Vector3& dir) {
40+ static Handle_Geom_Line makeLine (const Vector3& start, const Vector3& dir)
41+ {
3942 Handle_Geom_Line line = new Geom_Line (Vector3::toPnt (start), Vector3::toDir (dir));
4043 return line;
4144 }
4245
43- static Handle_Geom_TrimmedCurve trim (const Geom_Curve* curve, double start, double end) {
46+ static Handle_Geom_TrimmedCurve trim (const Geom_Curve* curve,
47+ double start,
48+ double end)
49+ {
4450 Handle_Geom_TrimmedCurve trimmedCurve = new Geom_TrimmedCurve (curve, start, end);
4551 return trimmedCurve;
4652 }
4753
48- static Vector3Array projects (const Geom_Curve* curve, const Vector3& point) {
54+ static Vector3Array projects (const Geom_Curve* curve, const Vector3& point)
55+ {
4956 GeomAPI_ProjectPointOnCurve projector (Vector3::toPnt (point), curve);
5057 std::vector<Vector3> points;
5158 for (int i = 1 ; i <= projector.NbPoints (); i++) {
5259 points.push_back (Vector3::fromPnt (projector.Point (i)));
5360 }
54-
61+
5562 return Vector3Array (val::array (points));
5663 }
5764
58- static std::optional<ExtremaCCResult> nearestExtremaCC (const Geom_Curve* curve1, const Geom_Curve* curve2) {
65+ static std::optional<ExtremaCCResult> nearestExtremaCC (
66+ const Geom_Curve* curve1,
67+ const Geom_Curve* curve2)
68+ {
5969 GeomAPI_ExtremaCurveCurve extrema (curve1, curve2);
6070 if (extrema.NbExtrema () == 0 ) {
6171 return std::nullopt ;
@@ -65,34 +75,41 @@ class Curve {
6575 extrema.NearestPoints (p1, p2);
6676 double u1, u2;
6777 extrema.LowerDistanceParameters (u1, u2);
68- return ExtremaCCResult {
69- .isParallel = extrema.IsParallel (),
78+ return ExtremaCCResult { .isParallel = extrema.IsParallel (),
7079 .distance = extrema.LowerDistance (),
7180 .p1 = Vector3::fromPnt (p1),
7281 .p2 = Vector3::fromPnt (p2),
7382 .u1 = u1,
74- .u2 = u2
75- };
83+ .u2 = u2 };
7684 }
7785
78- static Vector3Array uniformAbscissaWithLength (const Geom_Curve* curve, double length) {
86+ static Vector3Array uniformAbscissaWithLength (const Geom_Curve* curve,
87+ double length)
88+ {
7989 GeomAdaptor_Curve adaptorCurve (curve);
8090 GCPnts_UniformAbscissa uniformAbscissa (adaptorCurve, length);
8191 return getPoints (uniformAbscissa, curve);
8292 }
8393
84- static Vector3Array uniformAbscissaWithCount (const Geom_Curve* curve, int nbPoints) {
94+ static Vector3Array uniformAbscissaWithCount (const Geom_Curve* curve,
95+ int nbPoints)
96+ {
8597 GeomAdaptor_Curve adaptorCurve (curve);
8698 GCPnts_UniformAbscissa uniformAbscissa (adaptorCurve, nbPoints);
8799 return getPoints (uniformAbscissa, curve);
88100 }
89101
90- static ProjectPointResult projectOrNearest (const Geom_Curve* curve, const Vector3& point) {
102+ static ProjectPointResult projectOrNearest (const Geom_Curve* curve,
103+ const Vector3& point)
104+ {
91105 gp_Pnt pnt = Vector3::toPnt (point);
92106 return projectOrNearestCP (curve, pnt);
93107 }
94108
95- static std::optional<double > parameter (const Geom_Curve* curve, const Vector3& point, double maxDistance) {
109+ static std::optional<double > parameter (const Geom_Curve* curve,
110+ const Vector3& point,
111+ double maxDistance)
112+ {
96113 double parameter = 0 ;
97114 gp_Pnt pnt = Vector3::toPnt (point);
98115 if (GeomLib_Tool::Parameter (curve, pnt, maxDistance, parameter)) {
@@ -101,11 +118,11 @@ class Curve {
101118 return std::nullopt ;
102119 }
103120
104- static double curveLength (const Geom_Curve* curve) {
121+ static double curveLength (const Geom_Curve* curve)
122+ {
105123 GeomAdaptor_Curve adaptorCurve (curve);
106124 return GCPnts_AbscissaPoint::Length (adaptorCurve);
107125 }
108-
109126};
110127
111128struct SurfaceBounds {
@@ -117,40 +134,47 @@ struct SurfaceBounds {
117134
118135class Surface {
119136public:
120- static Handle_Geom_Curve projectCurve (const Geom_Surface* surface, const Geom_Curve* curve) {
137+ static Handle_Geom_Curve projectCurve (const Geom_Surface* surface,
138+ const Geom_Curve* curve)
139+ {
121140 return GeomProjLib::Project (curve, surface);
122141 }
123142
124- static Vector3Array projectPoint (const Geom_Surface* surface, const Vector3& point) {
143+ static Vector3Array projectPoint (const Geom_Surface* surface,
144+ const Vector3& point)
145+ {
125146 gp_Pnt pnt = Vector3::toPnt (point);
126147 GeomAPI_ProjectPointOnSurf projector (pnt, surface);
127148 std::vector<gp_Pnt> points;
128- for (size_t i = 0 ; i < projector.NbPoints (); i++)
129- {
149+ for (size_t i = 0 ; i < projector.NbPoints (); i++) {
130150 points.push_back (projector.Point (i + 1 ));
131151 }
132-
152+
133153 return Vector3Array (val::array (points.begin (), points.end ()));
134154 }
135155
136- static bool isPlanar (const Geom_Surface* surface) {
156+ static bool isPlanar (const Geom_Surface* surface)
157+ {
137158 GeomLib_IsPlanarSurface isPlanarSurface (surface);
138159 return isPlanarSurface.IsPlanar ();
139160 }
140161
141- static std::optional<UV> parameters (const Geom_Surface* surface, const Vector3& point, double maxDistance) {
162+ static std::optional<UV> parameters (const Geom_Surface* surface,
163+ const Vector3& point,
164+ double maxDistance)
165+ {
142166 double u (0 ), v (0 );
143167 gp_Pnt pnt = Vector3::toPnt (point);
144168 if (GeomLib_Tool::Parameters (surface, pnt, maxDistance, u, v)) {
145- return UV {
146- .u = u,
147- .v = v
148- };
169+ return UV { .u = u, .v = v };
149170 }
150171 return std::nullopt ;
151172 }
152173
153- static std::optional<PointAndParameter> nearestPoint (const Geom_Surface* surface, const Vector3& point) {
174+ static std::optional<PointAndParameter> nearestPoint (
175+ const Geom_Surface* surface,
176+ const Vector3& point)
177+ {
154178 gp_Pnt pnt = Vector3::toPnt (point);
155179 GeomAPI_ProjectPointOnSurf projector (pnt, surface);
156180 if (projector.IsDone ()) {
@@ -162,46 +186,45 @@ class Surface {
162186 return std::nullopt ;
163187 }
164188
165- static SurfaceBounds bounds (const Geom_Surface* surface) {
189+ static SurfaceBounds bounds (const Geom_Surface* surface)
190+ {
166191 double u1, u2, v1, v2;
167192 surface->Bounds (u1, u2, v1, v2);
168- return SurfaceBounds {
169- .u1 = u1,
170- .u2 = u2,
171- .v1 = v1,
172- .v2 = v2
173- };
193+ return SurfaceBounds { .u1 = u1, .u2 = u2, .v1 = v1, .v2 = v2 };
174194 }
175-
176195};
177196
178- EMSCRIPTEN_BINDINGS (Geometry) {
197+ EMSCRIPTEN_BINDINGS (Geometry)
198+ {
179199 class_<Curve>(" Curve" )
180200 .class_function (" makeLine" , &Curve::makeLine)
181201 .class_function (" trim" , &Curve::trim, allow_raw_pointers ())
182- .class_function (" projectOrNearest" , &Curve::projectOrNearest, allow_raw_pointers ())
183- .class_function (" uniformAbscissaWithCount" , &Curve::uniformAbscissaWithCount, allow_raw_pointers ())
184- .class_function (" uniformAbscissaWithLength" , &Curve::uniformAbscissaWithLength, allow_raw_pointers ())
185- .class_function (" nearestExtremaCC" , &Curve::nearestExtremaCC, allow_raw_pointers ())
202+ .class_function (" projectOrNearest" , &Curve::projectOrNearest,
203+ allow_raw_pointers ())
204+ .class_function (" uniformAbscissaWithCount" ,
205+ &Curve::uniformAbscissaWithCount, allow_raw_pointers ())
206+ .class_function (" uniformAbscissaWithLength" ,
207+ &Curve::uniformAbscissaWithLength, allow_raw_pointers ())
208+ .class_function (" nearestExtremaCC" , &Curve::nearestExtremaCC,
209+ allow_raw_pointers ())
186210 .class_function (" parameter" , &Curve::parameter, allow_raw_pointers ())
187211 .class_function (" curveLength" , &Curve::curveLength, allow_raw_pointers ())
188- .class_function (" projects" , &Curve::projects, allow_raw_pointers ())
189- ;
212+ .class_function (" projects" , &Curve::projects, allow_raw_pointers ());
190213
191214 value_object<SurfaceBounds>(" SurfaceBounds" )
192215 .field (" u1" , &SurfaceBounds::u1)
193216 .field (" u2" , &SurfaceBounds::u2)
194217 .field (" v1" , &SurfaceBounds::v1)
195- .field (" v2" , &SurfaceBounds::v2)
196- ;
218+ .field (" v2" , &SurfaceBounds::v2);
197219
198220 class_<Surface>(" Surface" )
199- .class_function (" projectCurve" , &Surface::projectCurve, allow_raw_pointers ())
200- .class_function (" projectPoint" , &Surface::projectPoint, allow_raw_pointers ())
221+ .class_function (" projectCurve" , &Surface::projectCurve,
222+ allow_raw_pointers ())
223+ .class_function (" projectPoint" , &Surface::projectPoint,
224+ allow_raw_pointers ())
201225 .class_function (" isPlanar" , &Surface::isPlanar, allow_raw_pointers ())
202226 .class_function (" parameters" , &Surface::parameters, allow_raw_pointers ())
203- .class_function (" nearestPoint" , &Surface::nearestPoint, allow_raw_pointers ())
204- .class_function (" bounds" , &Surface::bounds, allow_raw_pointers ())
205- ;
206-
227+ .class_function (" nearestPoint" , &Surface::nearestPoint,
228+ allow_raw_pointers ())
229+ .class_function (" bounds" , &Surface::bounds, allow_raw_pointers ());
207230}
0 commit comments