From 67415b49e43bf4825c7b5812f9199b4048ceafa3 Mon Sep 17 00:00:00 2001 From: godardma Date: Tue, 1 Sep 2026 17:45:41 +0200 Subject: [PATCH 1/5] [sep] adding SepTest --- python/src/core/CMakeLists.txt | 1 + python/src/core/codac2_py_core.cpp | 2 + .../src/core/separators/codac2_py_SepTest.cpp | 36 ++++++++++++++ src/core/CMakeLists.txt | 2 + src/core/separators/codac2_SepTest.cpp | 31 ++++++++++++ src/core/separators/codac2_SepTest.h | 49 +++++++++++++++++++ .../core/separators/codac2_tests_SepTest.cpp | 42 ++++++++++++++++ tests/core/separators/codac2_tests_SepTest.py | 38 ++++++++++++++ 8 files changed, 201 insertions(+) create mode 100644 python/src/core/separators/codac2_py_SepTest.cpp create mode 100644 src/core/separators/codac2_SepTest.cpp create mode 100644 src/core/separators/codac2_SepTest.h create mode 100644 tests/core/separators/codac2_tests_SepTest.cpp create mode 100644 tests/core/separators/codac2_tests_SepTest.py diff --git a/python/src/core/CMakeLists.txt b/python/src/core/CMakeLists.txt index 9d83a210d..25221ecb7 100644 --- a/python/src/core/CMakeLists.txt +++ b/python/src/core/CMakeLists.txt @@ -114,6 +114,7 @@ separators/codac2_py_SepPolygon.cpp separators/codac2_py_SepProj.cpp separators/codac2_py_SepQInter.cpp + separators/codac2_py_SepTest.cpp separators/codac2_py_SepTransform.cpp separators/codac2_py_SepUnion.cpp separators/codac2_py_SepVisible.cpp diff --git a/python/src/core/codac2_py_core.cpp b/python/src/core/codac2_py_core.cpp index afe9b27f3..3b0f73931 100644 --- a/python/src/core/codac2_py_core.cpp +++ b/python/src/core/codac2_py_core.cpp @@ -152,6 +152,7 @@ void export_SepPolarCart(py::module& m, py::class_& pysep); void export_SepPolygon(py::module& m, py::class_& sep); void export_SepProj(py::module& m, py::class_& sep); void export_SepQInter(py::module& m, py::class_& sep); +void export_SepTest(py::module& m, py::class_& sep); void export_SepTransform(py::module& m, py::class_& sep); void export_SepUnion(py::module& m, py::class_& sep); void export_SepVisible(py::module& m, py::class_& sep); @@ -336,6 +337,7 @@ PYBIND11_MODULE(_core, m) export_SepPolygon(m,py_sep); export_SepProj(m,py_sep); export_SepQInter(m,py_sep); + export_SepTest(m,py_sep); export_SepTransform(m,py_sep); export_SepUnion(m,py_sep); export_SepVisible(m,py_sep); diff --git a/python/src/core/separators/codac2_py_SepTest.cpp b/python/src/core/separators/codac2_py_SepTest.cpp new file mode 100644 index 000000000..0aee00ea2 --- /dev/null +++ b/python/src/core/separators/codac2_py_SepTest.cpp @@ -0,0 +1,36 @@ +/** + * Codac binding (core) + * ---------------------------------------------------------------------------- + * \date 2026 + * \author Maël Godard + * \copyright Copyright 2025 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ + +#include +#include +#include +#include +#include "codac2_py_Sep.h" +#include "codac2_py_SepTest_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py): + +using namespace std; +using namespace codac2; +namespace py = pybind11; +using namespace pybind11::literals; + +void export_SepTest(py::module& m, py::class_& pysep) +{ + py::class_ exported(m, "SepTest", pysep, SEPTEST_MAIN); + exported + + .def(py::init(), + SEPTEST_SEPTEST_CONST_S_REF, + "s"_a) + + .def("separate", &SepTest::separate, + BOXPAIR_SEPTEST_SEPARATE_CONST_INTERVALVECTOR_REF_CONST, + "x"_a) + + ; +} \ No newline at end of file diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index db02e9526..4ad18aaa0 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -249,6 +249,8 @@ ${CMAKE_CURRENT_SOURCE_DIR}/separators/codac2_SepProj.h ${CMAKE_CURRENT_SOURCE_DIR}/separators/codac2_SepQInter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/separators/codac2_SepQInter.h + ${CMAKE_CURRENT_SOURCE_DIR}/separators/codac2_SepTest.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/separators/codac2_SepTest.h ${CMAKE_CURRENT_SOURCE_DIR}/separators/codac2_SepTransform.cpp ${CMAKE_CURRENT_SOURCE_DIR}/separators/codac2_SepTransform.h ${CMAKE_CURRENT_SOURCE_DIR}/separators/codac2_SepUnion.cpp diff --git a/src/core/separators/codac2_SepTest.cpp b/src/core/separators/codac2_SepTest.cpp new file mode 100644 index 000000000..f00430f99 --- /dev/null +++ b/src/core/separators/codac2_SepTest.cpp @@ -0,0 +1,31 @@ +/** + * SepTest.cpp + * ---------------------------------------------------------------------------- + * \date 2026 + * \author Maël Godard + * \copyright Copyright 2025 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ + +#include "codac2_SepTest.h" +#include + +using namespace std; + +namespace codac2 +{ + BoxPair SepTest::separate(const IntervalVector& x) const + { + assert_release(x.size() == _sep.size()); + + BoxPair b_pair = _sep.separate(x); + + if (!b_pair.inner.is_empty()) + b_pair.inner=x; + + if (!b_pair.outer.is_empty()) + b_pair.outer=x; + + return b_pair; + } +} \ No newline at end of file diff --git a/src/core/separators/codac2_SepTest.h b/src/core/separators/codac2_SepTest.h new file mode 100644 index 000000000..c4255c29f --- /dev/null +++ b/src/core/separators/codac2_SepTest.h @@ -0,0 +1,49 @@ +/** + * \file codac2_SepTest.h + * ---------------------------------------------------------------------------- + * \date 2026 + * \author Maël Godard + * \copyright Copyright 2025 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ + +#pragma once + +#include +#include "codac2_IntervalVector.h" +#include "codac2_Sep.h" +#include "codac2_template_tools.h" + +namespace codac2 +{ + /** + * \brief A separator which tests the result of another separator. + * It can be used to get the result of the separator without the contraction. + */ + class SepTest : public Sep + { + public: + + /** + * \brief Constructor for the separator. + * + * \param s The separator to test. + */ + template + requires IsSepBaseOrPtr + SepTest(const S& s) + : Sep(size_of(s)), _sep({s}) + { } + + /** + * \brief Separates the box. Both the inner and outer are either empty or the box itself. + * + * \param x The box to separate. + */ + BoxPair separate(const IntervalVector& x) const; + + protected: + + const SepBase& _sep; + }; +} \ No newline at end of file diff --git a/tests/core/separators/codac2_tests_SepTest.cpp b/tests/core/separators/codac2_tests_SepTest.cpp new file mode 100644 index 000000000..6a0235812 --- /dev/null +++ b/tests/core/separators/codac2_tests_SepTest.cpp @@ -0,0 +1,42 @@ +/** + * Codac tests + * ---------------------------------------------------------------------------- + * \date 2026 + * \author Maël Godard + * \copyright Copyright 2024 Codac Team + * \license GNU Lesser General Public License (LGPL) + */ + +#include +#include +#include +#include + +using namespace std; +using namespace codac2; + + +TEST_CASE("SepTest") +{ + IntervalVector X ({{1,3},{2,8},{-1,1}}); + SepWrapper_IntervalVector sep_wrapper (X); + SepTest sep_test (sep_wrapper); + + IntervalVector x1 ({{1.5,2.5},{2.5,7.5},{-0.5,0.5}}); + IntervalVector x2 ({{10,11},{10,11},{10,11}}); + IntervalVector x3 ({{1,3},{2,8},{-1,1}}); + + BoxPair xs; + + xs = sep_test.separate(x1); + CHECK(xs.inner==IntervalVector::empty(3)); + CHECK(xs.outer==x1); + + xs = sep_test.separate(x2); + CHECK(xs.inner==x2); + CHECK(xs.outer==IntervalVector::empty(3)); + + xs = sep_test.separate(x3); + CHECK(xs.inner==x3); + CHECK(xs.outer==x3); +} \ No newline at end of file diff --git a/tests/core/separators/codac2_tests_SepTest.py b/tests/core/separators/codac2_tests_SepTest.py new file mode 100644 index 000000000..15a9f09d6 --- /dev/null +++ b/tests/core/separators/codac2_tests_SepTest.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python + +# Codac tests +# ---------------------------------------------------------------------------- +# \date 2026 +# \author Maël Godard +# \copyright Copyright 2024 Codac Team +# \license GNU Lesser General Public License (LGPL) + +import unittest +from codac import * + +class TestSepTest(unittest.TestCase): + + def test_SepTest(self): + + X = IntervalVector([[1,3],[2,8],[-1,1]]) + sep_wrapper = SepWrapper_IntervalVector(X) + sep_test = SepTest(sep_wrapper) + + x1 = IntervalVector([[1.5,2.5],[2.5,7.5],[-0.5,0.5]]) + x2 = IntervalVector([[10,11],[10,11],[10,11]]) + x3 = IntervalVector([[1,3],[2,8],[-1,1]]) + + inner,outer = sep_test.separate(x1) + self.assertTrue(inner==IntervalVector.empty(3)) + self.assertTrue(outer==x1) + + inner,outer = sep_test.separate(x2) + self.assertTrue(inner==x2) + self.assertTrue(outer==IntervalVector.empty(3)) + + inner,outer = sep_test.separate(x3) + self.assertTrue(inner==x3) + self.assertTrue(outer==x3) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file From c6a5a83fb596c3f8605ce7c7ed9a4d5e4d1fe28c Mon Sep 17 00:00:00 2001 From: godardma Date: Wed, 2 Sep 2026 14:40:55 +0200 Subject: [PATCH 2/5] [sep] attempt fix on SepTest for actions --- src/core/separators/codac2_SepTest.cpp | 2 +- src/core/separators/codac2_SepTest.h | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/core/separators/codac2_SepTest.cpp b/src/core/separators/codac2_SepTest.cpp index f00430f99..88c22f921 100644 --- a/src/core/separators/codac2_SepTest.cpp +++ b/src/core/separators/codac2_SepTest.cpp @@ -18,7 +18,7 @@ namespace codac2 { assert_release(x.size() == _sep.size()); - BoxPair b_pair = _sep.separate(x); + BoxPair b_pair = _sep.front()->separate(x); if (!b_pair.inner.is_empty()) b_pair.inner=x; diff --git a/src/core/separators/codac2_SepTest.h b/src/core/separators/codac2_SepTest.h index c4255c29f..cf3049ff9 100644 --- a/src/core/separators/codac2_SepTest.h +++ b/src/core/separators/codac2_SepTest.h @@ -9,10 +9,8 @@ #pragma once -#include -#include "codac2_IntervalVector.h" #include "codac2_Sep.h" -#include "codac2_template_tools.h" +#include "codac2_Collection.h" namespace codac2 { @@ -44,6 +42,6 @@ namespace codac2 protected: - const SepBase& _sep; + const Collection& _sep; }; } \ No newline at end of file From 317afc2ea0a92b8f5997b6dd126fdb8cd7995430 Mon Sep 17 00:00:00 2001 From: godardma Date: Wed, 2 Sep 2026 20:13:17 +0200 Subject: [PATCH 3/5] [sep] attempt fix on SepTest for actions --- python/src/core/separators/codac2_py_SepTest.cpp | 4 +++- src/core/separators/codac2_SepTest.h | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/python/src/core/separators/codac2_py_SepTest.cpp b/python/src/core/separators/codac2_py_SepTest.cpp index 0aee00ea2..7fe6c6cb8 100644 --- a/python/src/core/separators/codac2_py_SepTest.cpp +++ b/python/src/core/separators/codac2_py_SepTest.cpp @@ -24,7 +24,9 @@ void export_SepTest(py::module& m, py::class_& pysep) py::class_ exported(m, "SepTest", pysep, SEPTEST_MAIN); exported - .def(py::init(), + .def(py::init([](const SepBase& s) { + return std::make_unique(s.copy()); + }), SEPTEST_SEPTEST_CONST_S_REF, "s"_a) diff --git a/src/core/separators/codac2_SepTest.h b/src/core/separators/codac2_SepTest.h index cf3049ff9..4a4cbe84e 100644 --- a/src/core/separators/codac2_SepTest.h +++ b/src/core/separators/codac2_SepTest.h @@ -9,8 +9,10 @@ #pragma once +#include #include "codac2_Sep.h" #include "codac2_Collection.h" +#include "codac2_template_tools.h" namespace codac2 { @@ -30,7 +32,7 @@ namespace codac2 template requires IsSepBaseOrPtr SepTest(const S& s) - : Sep(size_of(s)), _sep({s}) + : Sep(size_of(s)), _sep(s) { } /** From caabd3e11432bc98ecc244ddc4a6e9abcaaa8a88 Mon Sep 17 00:00:00 2001 From: godardma Date: Fri, 4 Sep 2026 14:43:26 +0200 Subject: [PATCH 4/5] [sep] attempt fix on SepTest for actions --- src/core/separators/codac2_SepTest.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/core/separators/codac2_SepTest.h b/src/core/separators/codac2_SepTest.h index 4a4cbe84e..6d3864186 100644 --- a/src/core/separators/codac2_SepTest.h +++ b/src/core/separators/codac2_SepTest.h @@ -24,22 +24,12 @@ namespace codac2 { public: - /** - * \brief Constructor for the separator. - * - * \param s The separator to test. - */ template requires IsSepBaseOrPtr SepTest(const S& s) : Sep(size_of(s)), _sep(s) { } - /** - * \brief Separates the box. Both the inner and outer are either empty or the box itself. - * - * \param x The box to separate. - */ BoxPair separate(const IntervalVector& x) const; protected: From 6cae1c9116e59087482ddfade1494fffa22f5dca Mon Sep 17 00:00:00 2001 From: godardma Date: Mon, 7 Sep 2026 12:41:41 +0200 Subject: [PATCH 5/5] [sep] attempt fix on SepTest for actions (again) --- src/core/separators/codac2_SepTest.cpp | 2 +- src/core/separators/codac2_SepTest.h | 12 +++++++++++- tests/CMakeLists.txt | 1 + tests/core/separators/codac2_tests_SepTest.cpp | 6 ++---- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/core/separators/codac2_SepTest.cpp b/src/core/separators/codac2_SepTest.cpp index 88c22f921..ff153b203 100644 --- a/src/core/separators/codac2_SepTest.cpp +++ b/src/core/separators/codac2_SepTest.cpp @@ -16,7 +16,7 @@ namespace codac2 { BoxPair SepTest::separate(const IntervalVector& x) const { - assert_release(x.size() == _sep.size()); + assert_release(x.size() == this->size()); BoxPair b_pair = _sep.front()->separate(x); diff --git a/src/core/separators/codac2_SepTest.h b/src/core/separators/codac2_SepTest.h index 6d3864186..bae989c9e 100644 --- a/src/core/separators/codac2_SepTest.h +++ b/src/core/separators/codac2_SepTest.h @@ -24,16 +24,26 @@ namespace codac2 { public: + /** + * \brief Constructor for the separator. + * + * \param s The separator to test. + */ template requires IsSepBaseOrPtr SepTest(const S& s) : Sep(size_of(s)), _sep(s) { } + /** + * \brief Separates the box. Both the inner and outer are either empty or the box itself. + * + * \param x The box to separate. + */ BoxPair separate(const IntervalVector& x) const; protected: - const Collection& _sep; + const Collection _sep; }; } \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index dff12a6f4..acb9f8f7d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -99,6 +99,7 @@ list(APPEND SRC_TESTS # listing files without extension core/separators/codac2_tests_SepPolygon core/separators/codac2_tests_SepProj core/separators/codac2_tests_SepQInter + core/separators/codac2_tests_SepTest core/separators/codac2_tests_SepTransform core/separators/codac2_tests_SepUnion core/separators/codac2_tests_SepVisible diff --git a/tests/core/separators/codac2_tests_SepTest.cpp b/tests/core/separators/codac2_tests_SepTest.cpp index 6a0235812..c3b0949df 100644 --- a/tests/core/separators/codac2_tests_SepTest.cpp +++ b/tests/core/separators/codac2_tests_SepTest.cpp @@ -19,16 +19,14 @@ using namespace codac2; TEST_CASE("SepTest") { IntervalVector X ({{1,3},{2,8},{-1,1}}); - SepWrapper_IntervalVector sep_wrapper (X); + SepWrapper sep_wrapper (X); SepTest sep_test (sep_wrapper); IntervalVector x1 ({{1.5,2.5},{2.5,7.5},{-0.5,0.5}}); IntervalVector x2 ({{10,11},{10,11},{10,11}}); IntervalVector x3 ({{1,3},{2,8},{-1,1}}); - BoxPair xs; - - xs = sep_test.separate(x1); + BoxPair xs = sep_test.separate(x1); CHECK(xs.inner==IntervalVector::empty(3)); CHECK(xs.outer==x1);