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..7fe6c6cb8 --- /dev/null +++ b/python/src/core/separators/codac2_py_SepTest.cpp @@ -0,0 +1,38 @@ +/** + * 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([](const SepBase& s) { + return std::make_unique(s.copy()); + }), + 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..ff153b203 --- /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() == this->size()); + + BoxPair b_pair = _sep.front()->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..bae989c9e --- /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_Sep.h" +#include "codac2_Collection.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 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 new file mode 100644 index 000000000..c3b0949df --- /dev/null +++ b/tests/core/separators/codac2_tests_SepTest.cpp @@ -0,0 +1,40 @@ +/** + * 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 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 = 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