Files
ConformalLabpp/code/include/p2_utility.hpp
Tarik Moussa 62b02f88b9
Some checks failed
C++ Tests / test-fast (pull_request) Successful in 2m40s
API Docs / doc-build (pull_request) Successful in 1m2s
C++ Tests / test-cgal (pull_request) Failing after 11m52s
docs(doxygen): 100% public-API coverage (228 → 0 undocumented)
Completes the work begun in the previous commit on this branch.  Every
public symbol under code/include/ now carries a brief Doxygen comment
(0 undocumented per scripts/doxygen-coverage.sh, with the `detail::`
implementation namespaces excluded as before).

Trajectory on this branch:
  start (after Doxyfile fix):  24.0 %  (165 / 437 in the no-detail set
                                       was 105 / 437 when detail counted)
  after PR #17 base commit  :  42.4 %  (165 / 396)
  this commit               : 100.0 %  (396 / 396)

Files touched (all .hpp / .h headers under code/include/):
  * cgal/Conformal_map_traits.h
  * clausen.hpp, conformal_mesh.hpp, constants.hpp (already docd)
  * cp_euclidean_functional.hpp, cut_graph.hpp, discrete_elliptic_utility.hpp
  * euclidean_functional.hpp, euclidean_geometry.hpp, euclidean_hessian.hpp
  * fundamental_domain.hpp, gauss_bonnet.hpp
  * hyper_ideal_{functional,geometry,hessian,utility,visualization_utility}.hpp
  * inversive_distance_functional.hpp, layout.hpp
  * matrix_utility.hpp, mesh_builder.hpp, mesh_io.hpp
  * newton_solver.hpp, p2_utility.hpp, period_matrix.hpp, projective_math.hpp
  * serialization.hpp, spherical_functional.hpp, spherical_geometry.hpp
  * spherical_hessian.hpp, viewer_utils.h

CI:
.gitea/workflows/doxygen-pages.yml now enforces
`scripts/doxygen-coverage.sh --threshold 100`, so any future regression
(a new public function landed without a `///` brief) fails the build
before the Doxygen HTML is published to Codeberg Pages.

Doxygen warnings remain at 0.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-24 04:22:49 +02:00

96 lines
3.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
// 2-D projective geometry utilities for the Euclidean signature.
// Ported from de.jreality.math.P2 and de.varylab.discreteconformal.math.P2Big.
//
// Points and lines are represented as homogeneous 3-vectors (x, y, w).
// In the Euclidean case a finite point (px, py) is stored as (px, py, 1).
#include <Eigen/Dense>
#include <cmath>
namespace conformallab {
// ── Point / line duality ──────────────────────────────────────────────────────
/// Cross-product pointline duality in P²: returns the intersection
/// of two lines (or the line through two points). Same as Java
/// `P2.pointFromLines` / `P2.lineFromPoints`.
inline Eigen::Vector3d pointFromLines(const Eigen::Vector3d& l1,
const Eigen::Vector3d& l2) {
return l1.cross(l2);
}
// ── Euclidean perpendicular bisector ─────────────────────────────────────────
/// Homogeneous line coordinates `(a, b, c)` of the perpendicular
/// bisector of `[p, q]` in the Euclidean plane (`ax + by + c = 0`).
/// Same as Java `P2.perpendicularBisector(p, q, Pn.EUCLIDEAN)`.
inline Eigen::Vector3d perpendicularBisectorEuclidean(const Eigen::Vector3d& p_h,
const Eigen::Vector3d& q_h) {
// Dehomogenize
Eigen::Vector2d p = p_h.head<2>() / p_h(2);
Eigen::Vector2d q = q_h.head<2>() / q_h(2);
// Direction vector (p → direction, matching jReality sign convention)
Eigen::Vector2d d = p - q;
// Midpoint
Eigen::Vector2d m = (p + q) * 0.5;
// Line: d[0]*(x - m[0]) + d[1]*(y - m[1]) = 0
// = d[0]*x + d[1]*y - (d[0]*m[0] + d[1]*m[1])
double c = -(d(0) * m(0) + d(1) * m(1));
return {d(0), d(1), c};
}
/// Euclidean distance between two P² homogeneous points (dehomogenises both).
inline double euclideanDistanceP2(const Eigen::Vector3d& p_h,
const Eigen::Vector3d& q_h) {
Eigen::Vector2d p = p_h.head<2>() / p_h(2);
Eigen::Vector2d q = q_h.head<2>() / q_h(2);
return (p - q).norm();
}
// ── Direct Euclidean isometry from two point-frames ──────────────────────────
/// Build the 3×3 projective frame matrix anchored at `p0` with `p1`
/// defining the positive x-direction (Euclidean case). Columns:
/// `[dehom(p0), unit_dir(p0→p1), perp_dir]`.
template <typename S>
Eigen::Matrix<S, 3, 3> makeFrameMatrix(Eigen::Matrix<S, 3, 1> p0_h,
Eigen::Matrix<S, 3, 1> p1_h) {
// Dehomogenize
Eigen::Matrix<S, 3, 1> p0 = p0_h / p0_h(2); // (px, py, 1)
Eigen::Matrix<S, 3, 1> p1_d = p1_h / p1_h(2);
// Unit direction p0 → p1
Eigen::Matrix<S, 2, 1> dir2 = (p1_d - p0).template head<2>();
dir2.normalize();
Eigen::Matrix<S, 3, 1> p1n(dir2(0), dir2(1), S(0));
// Perpendicular direction
Eigen::Matrix<S, 3, 1> p2(-dir2(1), dir2(0), S(0));
Eigen::Matrix<S, 3, 3> M;
M.col(0) = p0;
M.col(1) = p1n;
M.col(2) = p2;
return M;
}
/// 3×3 Euclidean isometry (as a projective matrix) that maps the
/// frame `(s1, s2)` to the frame `(t1, t2)`. Same as Java
/// `P2.makeDirectIsometryFromFrames(..., Pn.EUCLIDEAN)`.
template <typename S>
Eigen::Matrix<S, 3, 3> makeDirectIsometryFromFramesEuclidean(
Eigen::Matrix<S, 3, 1> s1, Eigen::Matrix<S, 3, 1> s2,
Eigen::Matrix<S, 3, 1> t1, Eigen::Matrix<S, 3, 1> t2)
{
auto toS = makeFrameMatrix<S>(s1, s2);
auto toT = makeFrameMatrix<S>(t1, t2);
return toT * toS.inverse();
}
} // namespace conformallab