Phase 10A/10B Inc 0: build system, handle model, first module surface
Builds n3xd-ocp end to end and publishes 7.9.3.1.dev1 to the Gitea registry, where it installs anonymously and passes its suite. - occt/Dockerfile: OCCT 7.9.3 compiled once into a manylinux_2_28 builder image (base digest + tarball sha256 pinned), Draw/VTK/Tk/Xlib/OpenGL off, FreeType on, -O2 without fast-math or march=native. A final layer asserts TKService/TKV3d exist with no libGL/libX11 DT_NEEDED, which is what lets the app image drop libgl1/libx11-6. Mounted into, never built FROM. - scikit-build-core + nanobind STABLE_ABI -> one cp312-abi3 extension that registers every OCP.* submodule via PyImport_AddModule, so `import OCP.TopoDS` needs no shim and cls.__module__ is right. Version <occt>.N is asserted against the OCCT found, keeping occt_version() truthful. - occt_handle.h: type caster for opencascade::handle<T> over OCCT's intrusive refcount. Wrappers are non-owning instances holding exactly one handle in their keep-alive list, reusing an existing wrapper so identity survives a round trip. Transient constructors go through ocp_new (never nb::init<>, which would let OCCT delete nanobind's storage); the caster refuses a refcount-0 object rather than corrupt the heap. Verified under ASAN with no memory-safety errors, plus an RSS bound over 50k create/destroy cycles. - Sub-shapes are returned by value everywhere, making the TShape lifetime class that segfaulted a process-global face memo unrepresentable. - Standard_Failure derives RuntimeError, with ~20 concrete types dispatched on the dynamic OCCT type (cad_pool marshals failures home by type name). - Inc 0 surface: gp subset, TopAbs, TopoDS (+ downcasts), TopExp, TopLoc, TopTools, BRep, BinTools, Poly, Standard. 34 of the app's 139 symbols. - n3xd_ocp: additive APIs kept out of the OCP namespace so parity testing stays meaningful. bintools (shape <-> bytes, GIL-free, byte-identical) and _debug. Two findings worth the record, both verified against the stock wheel rather than assumed: upstream binds __hash__ but leaves __eq__ at identity, which is exactly what geom_memo.py's hash-bucket + IsSame scan is built around, so we match it instead of "fixing" it; and BinTools can release the GIL after all, by slurping the file-like object instead of bridging a streambuf that would call back into Python. Gate: BREP round-trips are byte-identical to cadquery-ocp-novtk across six fixtures (the generator asserts stock idempotency first). That matters beyond IPC — derive.py content-addresses BREP payloads by sha256 and stores the ref.
This commit is contained in:
138
src/modules/mod_gp.cpp
Normal file
138
src/modules/mod_gp.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
OCP.gp — the Inc 0 subset (points, vectors, directions, axes, transforms).
|
||||
|
||||
The rest of gp (gp_Ax2/Ax3/Pln/Circ/Lin/Pnt2d/Dir2d/Quaternion, which the
|
||||
app also uses) lands with Inc 1, where the curve and surface classes that
|
||||
consume them arrive.
|
||||
*/
|
||||
|
||||
#include "../common/occt_module.h"
|
||||
#include "../common/occt_policies.h"
|
||||
|
||||
#include <gp_Ax1.hxx>
|
||||
#include <gp_Dir.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <gp_Trsf.hxx>
|
||||
#include <gp_Vec.hxx>
|
||||
#include <gp_XYZ.hxx>
|
||||
|
||||
void register_gp(nb::module_ &root) {
|
||||
nb::module_ m = ocp_submodule(root, "gp");
|
||||
|
||||
nb::enum_<gp_TrsfForm>(m, "gp_TrsfForm", nb::is_arithmetic())
|
||||
.value("gp_Identity", gp_Identity)
|
||||
.value("gp_Rotation", gp_Rotation)
|
||||
.value("gp_Translation", gp_Translation)
|
||||
.value("gp_PntMirror", gp_PntMirror)
|
||||
.value("gp_Ax1Mirror", gp_Ax1Mirror)
|
||||
.value("gp_Ax2Mirror", gp_Ax2Mirror)
|
||||
.value("gp_Scale", gp_Scale)
|
||||
.value("gp_CompoundTrsf", gp_CompoundTrsf)
|
||||
.value("gp_Other", gp_Other)
|
||||
.export_values();
|
||||
|
||||
nb::class_<gp_XYZ>(m, "gp_XYZ")
|
||||
.def(nb::init<>())
|
||||
.def(nb::init<Standard_Real, Standard_Real, Standard_Real>(), "X"_a,
|
||||
"Y"_a, "Z"_a)
|
||||
.def("X", &gp_XYZ::X)
|
||||
.def("Y", &gp_XYZ::Y)
|
||||
.def("Z", &gp_XYZ::Z);
|
||||
|
||||
nb::class_<gp_Pnt>(m, "gp_Pnt")
|
||||
.def(nb::init<>())
|
||||
.def(nb::init<Standard_Real, Standard_Real, Standard_Real>(), "Xp"_a,
|
||||
"Yp"_a, "Zp"_a)
|
||||
.def(nb::init<const gp_XYZ &>(), "Coord"_a)
|
||||
.def("X", &gp_Pnt::X)
|
||||
.def("Y", &gp_Pnt::Y)
|
||||
.def("Z", &gp_Pnt::Z)
|
||||
.def("SetX", &gp_Pnt::SetX, "X"_a)
|
||||
.def("SetY", &gp_Pnt::SetY, "Y"_a)
|
||||
.def("SetZ", &gp_Pnt::SetZ, "Z"_a)
|
||||
.def("Coord", nb::overload_cast<>(&gp_Pnt::Coord, nb::const_),
|
||||
OCP_RETURN_COPY)
|
||||
.def("Distance", &gp_Pnt::Distance, "Other"_a)
|
||||
.def("SquareDistance", &gp_Pnt::SquareDistance, "Other"_a)
|
||||
.def("IsEqual", &gp_Pnt::IsEqual, "Other"_a, "LinearTolerance"_a)
|
||||
.def("Transform", &gp_Pnt::Transform, "T"_a)
|
||||
.def("Transformed", &gp_Pnt::Transformed, "T"_a, OCP_RETURN_COPY)
|
||||
.def("Translate",
|
||||
nb::overload_cast<const gp_Vec &>(&gp_Pnt::Translate), "V"_a)
|
||||
.def("Translated",
|
||||
nb::overload_cast<const gp_Vec &>(&gp_Pnt::Translated, nb::const_),
|
||||
"V"_a, OCP_RETURN_COPY);
|
||||
|
||||
nb::class_<gp_Vec>(m, "gp_Vec")
|
||||
.def(nb::init<>())
|
||||
.def(nb::init<Standard_Real, Standard_Real, Standard_Real>(), "Xv"_a,
|
||||
"Yv"_a, "Zv"_a)
|
||||
.def(nb::init<const gp_Dir &>(), "V"_a)
|
||||
.def(nb::init<const gp_Pnt &, const gp_Pnt &>(), "P1"_a, "P2"_a)
|
||||
.def("X", &gp_Vec::X)
|
||||
.def("Y", &gp_Vec::Y)
|
||||
.def("Z", &gp_Vec::Z)
|
||||
.def("Magnitude", &gp_Vec::Magnitude)
|
||||
.def("SquareMagnitude", &gp_Vec::SquareMagnitude)
|
||||
.def("Dot", &gp_Vec::Dot, "Other"_a)
|
||||
.def("Crossed", &gp_Vec::Crossed, "Right"_a, OCP_RETURN_COPY)
|
||||
.def("Normalize", &gp_Vec::Normalize)
|
||||
.def("Normalized", &gp_Vec::Normalized, OCP_RETURN_COPY)
|
||||
.def("Reversed", &gp_Vec::Reversed, OCP_RETURN_COPY)
|
||||
.def("Multiplied", &gp_Vec::Multiplied, "Scalar"_a, OCP_RETURN_COPY)
|
||||
.def("Angle", &gp_Vec::Angle, "Other"_a)
|
||||
.def("Transform", &gp_Vec::Transform, "T"_a)
|
||||
.def("Transformed", &gp_Vec::Transformed, "T"_a, OCP_RETURN_COPY);
|
||||
|
||||
nb::class_<gp_Dir>(m, "gp_Dir")
|
||||
.def(nb::init<>())
|
||||
.def(nb::init<Standard_Real, Standard_Real, Standard_Real>(), "Xv"_a,
|
||||
"Yv"_a, "Zv"_a)
|
||||
.def(nb::init<const gp_Vec &>(), "V"_a)
|
||||
.def("X", &gp_Dir::X)
|
||||
.def("Y", &gp_Dir::Y)
|
||||
.def("Z", &gp_Dir::Z)
|
||||
.def("Dot", &gp_Dir::Dot, "Other"_a)
|
||||
.def("Crossed", &gp_Dir::Crossed, "Right"_a, OCP_RETURN_COPY)
|
||||
.def("Angle", &gp_Dir::Angle, "Other"_a)
|
||||
.def("IsParallel", &gp_Dir::IsParallel, "Other"_a, "AngularTolerance"_a)
|
||||
.def("Reversed", &gp_Dir::Reversed, OCP_RETURN_COPY)
|
||||
.def("Reverse", &gp_Dir::Reverse)
|
||||
.def("Transform", &gp_Dir::Transform, "T"_a)
|
||||
.def("Transformed", &gp_Dir::Transformed, "T"_a, OCP_RETURN_COPY);
|
||||
|
||||
nb::class_<gp_Ax1>(m, "gp_Ax1")
|
||||
.def(nb::init<>())
|
||||
.def(nb::init<const gp_Pnt &, const gp_Dir &>(), "P"_a, "V"_a)
|
||||
.def("Location", &gp_Ax1::Location, OCP_RETURN_COPY)
|
||||
.def("Direction", &gp_Ax1::Direction, OCP_RETURN_COPY)
|
||||
.def("SetLocation", &gp_Ax1::SetLocation, "P"_a)
|
||||
.def("SetDirection", &gp_Ax1::SetDirection, "V"_a)
|
||||
.def("Reversed", &gp_Ax1::Reversed, OCP_RETURN_COPY);
|
||||
|
||||
nb::class_<gp_Trsf>(m, "gp_Trsf")
|
||||
.def(nb::init<>())
|
||||
.def("SetTranslation",
|
||||
nb::overload_cast<const gp_Vec &>(&gp_Trsf::SetTranslation),
|
||||
"V"_a)
|
||||
.def("SetTranslation",
|
||||
nb::overload_cast<const gp_Pnt &, const gp_Pnt &>(
|
||||
&gp_Trsf::SetTranslation),
|
||||
"P1"_a, "P2"_a)
|
||||
.def("SetRotation",
|
||||
nb::overload_cast<const gp_Ax1 &, Standard_Real>(
|
||||
&gp_Trsf::SetRotation),
|
||||
"A1"_a, "Ang"_a)
|
||||
.def("SetScale", &gp_Trsf::SetScale, "P"_a, "S"_a)
|
||||
.def("SetMirror", nb::overload_cast<const gp_Ax1 &>(&gp_Trsf::SetMirror),
|
||||
"A1"_a)
|
||||
.def("Form", &gp_Trsf::Form)
|
||||
.def("ScaleFactor", &gp_Trsf::ScaleFactor)
|
||||
.def("TranslationPart", &gp_Trsf::TranslationPart, OCP_RETURN_COPY)
|
||||
.def("Value", &gp_Trsf::Value, "Row"_a, "Col"_a)
|
||||
.def("Inverted", &gp_Trsf::Inverted, OCP_RETURN_COPY)
|
||||
.def("Multiplied", &gp_Trsf::Multiplied, "T"_a, OCP_RETURN_COPY)
|
||||
.def("Multiply", &gp_Trsf::Multiply, "T"_a)
|
||||
.def("PreMultiply", &gp_Trsf::PreMultiply, "T"_a)
|
||||
.def("Invert", &gp_Trsf::Invert);
|
||||
}
|
||||
Reference in New Issue
Block a user