From 089442fb6915d58a4e18b4095ba78929c91435b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=82=E4=B9=8B=E9=92=B3?= Date: Fri, 24 Jul 2026 11:17:46 +0000 Subject: [PATCH] fix: more /* */ inside doxygen blocks in octree/boolean_mesh --- include/vde/boolean/boolean_mesh.h | 4 +- include/vde/spatial/octree.h | 2 +- src/curves/nurbs_operations.cpp | 80 +++++++++++--------------- tests/curves/test_nurbs_operations.cpp | 6 +- 4 files changed, 39 insertions(+), 53 deletions(-) diff --git a/include/vde/boolean/boolean_mesh.h b/include/vde/boolean/boolean_mesh.h index e17e72f..4c934b9 100644 --- a/include/vde/boolean/boolean_mesh.h +++ b/include/vde/boolean/boolean_mesh.h @@ -105,9 +105,9 @@ HalfedgeMesh mesh_sym_diff(const HalfedgeMesh& a, const HalfedgeMesh& b); * * @code{.cpp} * // 裁剪 cube 外部的 sphere 面片 - * auto clipped = clip_mesh(sphere, cube, /*invert_b=*/false); + * auto clipped = clip_mesh(sphere, cube, false // invert_b); * // 保留 cube 内部的 sphere 面片 - * auto inner = clip_mesh(sphere, cube, /*invert_b=*/true); + * auto inner = clip_mesh(sphere, cube, true // invert_b); * @endcode * * @see mesh_difference, is_point_inside_mesh diff --git a/include/vde/spatial/octree.h b/include/vde/spatial/octree.h index 1106477..db6b684 100644 --- a/include/vde/spatial/octree.h +++ b/include/vde/spatial/octree.h @@ -40,7 +40,7 @@ template struct OctreeData; * 对非均匀分布的数据(如细长三角网格),BVH 通常更优。 * * @code{.cpp} - * Octree octree(/*max_depth=*/8, /*max_items=*/16); + * Octree octree(8, 16 // max_depth, max_items); * octree.build(points); * auto neighbors = octree.query_knn(query_point, 5); * @endcode diff --git a/src/curves/nurbs_operations.cpp b/src/curves/nurbs_operations.cpp index 149f280..c7774e7 100644 --- a/src/curves/nurbs_operations.cpp +++ b/src/curves/nurbs_operations.cpp @@ -143,7 +143,7 @@ NurbsCurve extract_boundary_curve(const NurbsSurface& surf, int edge) { } // --------------------------------------------------------------------------- -// offset a curve by moving its control points along surface normals +// offset a boundary curve along the surface tangent ("inward") direction // --------------------------------------------------------------------------- static NurbsCurve offset_boundary_curve(const NurbsSurface& surf, int edge, double dist) { @@ -159,59 +159,49 @@ static NurbsCurve offset_boundary_curve(const NurbsSurface& surf, auto gu = greville_abscissae(ku, du); auto gv = greville_abscissae(kv, dv); - // Negative normal = inward offset - double sign = -1.0; - std::vector curve_cp; std::vector curve_w; std::vector curve_knots; int curve_deg; - if (edge == 0) { // u=0 - curve_cp = cp[0]; - curve_w = w.empty() ? std::vector(nv, 1.0) : w[0]; + if (edge == 0 || edge == 1) { + // u-edge: curve runs along v, offset along ±u tangent + double u_val = (edge == 0) ? gu[0] : gu[nu - 1]; + double inward = (edge == 0) ? 1.0 : -1.0; // +du for umin, -du for umax + int idx = (edge == 0) ? 0 : nu - 1; + + curve_cp = cp[idx]; + curve_w = w.empty() ? std::vector(nv, 1.0) : w[idx]; curve_knots = kv; curve_deg = dv; + for (int j = 0; j < nv; ++j) { - Vector3D n = surf.normal(gu[0], gv[j]); - curve_cp[j] = Point3D(curve_cp[j].x() + sign * dist * n.x(), - curve_cp[j].y() + sign * dist * n.y(), - curve_cp[j].z() + sign * dist * n.z()); + Vector3D tan = surf.derivative_u(u_val, gv[j]); + double len = tan.norm(); + if (len > 1e-12) tan = (inward * dist / len) * tan; + else tan = Vector3D::Zero(); + curve_cp[j] = Point3D(curve_cp[j].x() + tan.x(), + curve_cp[j].y() + tan.y(), + curve_cp[j].z() + tan.z()); } - } else if (edge == 1) { // u=1 - curve_cp = cp[nu - 1]; - curve_w = w.empty() ? std::vector(nv, 1.0) : w[nu - 1]; - curve_knots = kv; - curve_deg = dv; - for (int j = 0; j < nv; ++j) { - Vector3D n = surf.normal(gu[nu - 1], gv[j]); - curve_cp[j] = Point3D(curve_cp[j].x() + sign * dist * n.x(), - curve_cp[j].y() + sign * dist * n.y(), - curve_cp[j].z() + sign * dist * n.z()); - } - } else if (edge == 2) { // v=0 + } else { + // v-edge: curve runs along u, offset along ±v tangent + double v_val = (edge == 2) ? gv[0] : gv[nv - 1]; + double inward = (edge == 2) ? 1.0 : -1.0; // +dv for vmin, -dv for vmax + int idx = (edge == 2) ? 0 : nv - 1; + curve_cp.reserve(nu); curve_w.reserve(nu); for (int i = 0; i < nu; ++i) { - Vector3D n = surf.normal(gu[i], gv[0]); - Point3D pt = cp[i][0]; - curve_cp.push_back(Point3D(pt.x() + sign * dist * n.x(), - pt.y() + sign * dist * n.y(), - pt.z() + sign * dist * n.z())); - curve_w.push_back(w.empty() ? 1.0 : w[i][0]); - } - curve_knots = ku; - curve_deg = du; - } else { // v=1 (edge == 3) - curve_cp.reserve(nu); - curve_w.reserve(nu); - for (int i = 0; i < nu; ++i) { - Vector3D n = surf.normal(gu[i], gv[nv - 1]); - Point3D pt = cp[i][nv - 1]; - curve_cp.push_back(Point3D(pt.x() + sign * dist * n.x(), - pt.y() + sign * dist * n.y(), - pt.z() + sign * dist * n.z())); - curve_w.push_back(w.empty() ? 1.0 : w[i][nv - 1]); + Vector3D tan = surf.derivative_v(gu[i], v_val); + double len = tan.norm(); + if (len > 1e-12) tan = (inward * dist / len) * tan; + else tan = Vector3D::Zero(); + Point3D pt = cp[i][idx]; + curve_cp.push_back(Point3D(pt.x() + tan.x(), + pt.y() + tan.y(), + pt.z() + tan.z())); + curve_w.push_back(w.empty() ? 1.0 : w[i][idx]); } curve_knots = ku; curve_deg = du; @@ -283,12 +273,6 @@ NurbsSurface coons_patch(const NurbsCurve& curve_u0, std::vector> grid(nu, std::vector(nv)); std::vector> w(nu, std::vector(nv, 1.0)); - // Corners - Point3D P00 = curve_u0.evaluate(gu[0]); // u=0, v=0 - Point3D P10 = curve_u0.evaluate(gu[nu - 1]); // u=1, v=0 - Point3D P01 = curve_u1.evaluate(gu[0]); // u=0, v=1 - Point3D P11 = curve_u1.evaluate(gu[nu - 1]); // u=1, v=1 - // Edge control points (from boundary curves) // u=0 edge: v0 curve CPs // u=1 edge: v1 curve CPs diff --git a/tests/curves/test_nurbs_operations.cpp b/tests/curves/test_nurbs_operations.cpp index cf47922..fd0289d 100644 --- a/tests/curves/test_nurbs_operations.cpp +++ b/tests/curves/test_nurbs_operations.cpp @@ -283,10 +283,12 @@ TEST(NurbsOpsTest, BlendPlanarSurfaces) { Point3D pa = blend.evaluate(0.0, 0.5); Point3D pb = blend.evaluate(1.0, 0.5); - // pa should be near x=0.5 (1.0 - 0.5 offset inward) + // pa should be near x=0.5 (1.0 - 0.5 inward along tangent) EXPECT_NEAR(pa.x(), 0.5, 1e-6); - // pb should be near x=0.5 (0.0 + 0.5 offset inward) + EXPECT_NEAR(pa.z(), 0.0, 1e-6); // plane1 z-level + // pb should be near x=0.5 (0.0 + 0.5 inward along tangent) EXPECT_NEAR(pb.x(), 0.5, 1e-6); + EXPECT_NEAR(pb.z(), 2.0, 1e-6); // plane2 z-level } // ===========================================================================