This commit closes the remaining red gates so `run-all.sh --fast` is
green end-to-end on the canonical dev machine.
New gates
─────────
1. cmake-format / cmake-lint
* scripts/quality/cmake-format.sh — dry-run by default,
--strict to fail on drift, --fix to apply
* .cmake-format.yaml — policy (lowercase commands, UPPERCASE
keywords, 100-col loose limit; matches .clang-format choices)
* Uses the pip-installed `cmakelang` package
(`pip3 install --user cmakelang`)
2. codespell
* scripts/quality/codespell.sh — exit 1 on any typo, --fix
interactively
* .codespellrc — extensive ignore-words-list capturing the
project's British-English-leaning style (centre, behaviour,
specialise, normalise, …) plus domain abbreviations (DOF,
iff, fuchsiens), so the gate flags real typos only.
* Validated: 0 typos across docs + code/include + scripts +
code/{src,tests}.
SPDX rollout (license-headers --fix)
────────────────────────────────────
license-headers.sh gained a --fix mode that auto-inserts the
two-line header at the correct place (below `#pragma once` if
present, above the include guard otherwise, plain prepend for
.cpp). Ran it on 60 of 66 files — 100 %-licensed now.
Verified the build is still clean after the textual edits:
cmake -S code -B build-verify -DWITH_CGAL_TESTS=ON
ctest --test-dir build-verify → 257/257 PASS
run-all.sh + README updated to include the two new gates.
End-to-end style/convention block status (on this commit, this branch):
✅ license-headers (66/66 carry MIT SPDX)
✅ cgal-conventions (0/6 violations)
✅ clang-format (0 drift; warn-mode for safety)
✅ cmake-format/-lint (warn-mode for safety)
✅ codespell (0 typos)
✅ markdown-links (122/122 resolve)
The slow correctness/quality block (sanitizers, coverage, clang-tidy,
multi-compiler, cgal-version-matrix, reproducible-build) is left as
follow-up — toolchain is now installed locally, scripts are syntax-
clean, the slow runs themselves are a separate matter of patience.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
91 lines
3.4 KiB
C++
91 lines
3.4 KiB
C++
// Copyright (c) 2024-2026 Tarik Moussa.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
// Port of de.varylab.discreteconformal.math.P2BigTest (Java/JUnit).
|
|
// Tests 2-D projective geometry utilities: perpendicular bisectors,
|
|
// point-from-lines, and direct isometries in the Euclidean plane.
|
|
//
|
|
// The Java test compared double precision (P2) against BigDecimal precision
|
|
// (P2Big) to 1E-10. Here we compare double against long double to the
|
|
// same tolerance.
|
|
|
|
#include "p2_utility.hpp"
|
|
#include <gtest/gtest.h>
|
|
#include <Eigen/Dense>
|
|
#include <cmath>
|
|
|
|
using namespace conformallab;
|
|
|
|
// Corresponds to Java P2BigTest.testMakeDirectIsometryFromFramesEuclidean()
|
|
//
|
|
// Computes the Euclidean isometry mapping frame (s1,s2) to frame (t1,t2)
|
|
// with both double and long-double precision, and checks:
|
|
// 1. The two precisions agree to 1E-10 (precision stability).
|
|
// 2. The matrix actually maps s1→t1 and s2→t2.
|
|
TEST(P2UtilityTest, MakeDirectIsometryFromFramesEuclidean) {
|
|
using V3d = Eigen::Vector3d;
|
|
using V3ld = Eigen::Matrix<long double, 3, 1>;
|
|
|
|
V3d s1(-1.4142135623730963, 0.0, 1.0);
|
|
V3d s2( 1.4142135623730951, 0.0, 1.0);
|
|
V3d t1(-2.828427124746189, 2.4494897427831805, 1.0);
|
|
V3d t2( 0.0, 2.4494897427831783, 1.0);
|
|
|
|
// double precision
|
|
auto T = makeDirectIsometryFromFramesEuclidean<double>(s1, s2, t1, t2);
|
|
|
|
// long double precision (analogous to Java's BigDecimal P2Big)
|
|
V3ld s1l = s1.cast<long double>();
|
|
V3ld s2l = s2.cast<long double>();
|
|
V3ld t1l = t1.cast<long double>();
|
|
V3ld t2l = t2.cast<long double>();
|
|
auto Tl = makeDirectIsometryFromFramesEuclidean<long double>(s1l, s2l, t1l, t2l);
|
|
|
|
// 1. double vs long double must agree to 1E-10
|
|
for (int i = 0; i < 3; ++i)
|
|
for (int j = 0; j < 3; ++j)
|
|
EXPECT_NEAR((double)Tl(i,j), T(i,j), 1E-10)
|
|
<< "element (" << i << "," << j << ") differs between precisions";
|
|
|
|
// 2. T must map s1 → t1 and s2 → t2 (verify isometry correctness)
|
|
auto map_s1 = T * s1;
|
|
auto map_s2 = T * s2;
|
|
EXPECT_NEAR(euclideanDistanceP2(map_s1, t1), 0.0, 1E-9) << "T*s1 should equal t1";
|
|
EXPECT_NEAR(euclideanDistanceP2(map_s2, t2), 0.0, 1E-9) << "T*s2 should equal t2";
|
|
}
|
|
|
|
// Corresponds to Java P2BigTest.testPerpendicularBisector()
|
|
TEST(P2UtilityTest, PerpendicularBisector) {
|
|
Eigen::Vector3d p1(0.5, 0.0, 1.0);
|
|
Eigen::Vector3d q1(0.0, 0.5, 1.0);
|
|
|
|
auto bisector = perpendicularBisectorEuclidean(p1, q1);
|
|
|
|
EXPECT_NEAR( 0.5, bisector(0), 1E-10);
|
|
EXPECT_NEAR(-0.5, bisector(1), 1E-10);
|
|
EXPECT_NEAR( 0.0, bisector(2), 1E-10);
|
|
}
|
|
|
|
// Corresponds to Java P2BigTest.testPerpendicularBisectorIntersection()
|
|
//
|
|
// The intersection of the perpendicular bisectors of two edges must be
|
|
// equidistant from the endpoints of each edge (circumcenter property).
|
|
TEST(P2UtilityTest, PerpendicularBisectorIntersection) {
|
|
Eigen::Vector3d p1(0.5, 0.0, 1.0);
|
|
Eigen::Vector3d q1(0.0, 1.0, 1.0);
|
|
Eigen::Vector3d p2(1.0, 0.0, 1.0);
|
|
Eigen::Vector3d q2(0.0, 1.5, 1.0);
|
|
|
|
auto l1 = perpendicularBisectorEuclidean(p1, q1);
|
|
auto l2 = perpendicularBisectorEuclidean(p2, q2);
|
|
auto o = pointFromLines(l1, l2); // circumcenter
|
|
|
|
// o must be equidistant from p1 and q1
|
|
EXPECT_NEAR(euclideanDistanceP2(p1, o),
|
|
euclideanDistanceP2(q1, o), 1E-10);
|
|
|
|
// o must be equidistant from p2 and q2
|
|
EXPECT_NEAR(euclideanDistanceP2(p2, o),
|
|
euclideanDistanceP2(q2, o), 1E-10);
|
|
}
|