Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions python/src/core/codac2_py_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ void export_SepPolarCart(py::module& m, py::class_<SepBase,pySep>& pysep);
void export_SepPolygon(py::module& m, py::class_<SepBase,pySep>& sep);
void export_SepProj(py::module& m, py::class_<SepBase,pySep>& sep);
void export_SepQInter(py::module& m, py::class_<SepBase,pySep>& sep);
void export_SepTest(py::module& m, py::class_<SepBase,pySep>& sep);
void export_SepTransform(py::module& m, py::class_<SepBase,pySep>& sep);
void export_SepUnion(py::module& m, py::class_<SepBase,pySep>& sep);
void export_SepVisible(py::module& m, py::class_<SepBase,pySep>& sep);
Expand Down Expand Up @@ -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);
Expand Down
38 changes: 38 additions & 0 deletions python/src/core/separators/codac2_py_SepTest.cpp
Original file line number Diff line number Diff line change
@@ -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 <pybind11/pybind11.h>
#include <pybind11/operators.h>
#include <pybind11/stl.h>
#include <codac2_SepTest.h>
#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_<SepBase,pySep>& pysep)
{
py::class_<SepTest> exported(m, "SepTest", pysep, SEPTEST_MAIN);
exported

.def(py::init([](const SepBase& s) {
return std::make_unique<SepTest>(s.copy());
}),
SEPTEST_SEPTEST_CONST_S_REF,
"s"_a)

.def("separate", &SepTest::separate,
BOXPAIR_SEPTEST_SEPARATE_CONST_INTERVALVECTOR_REF_CONST,
"x"_a)

;
}
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions src/core/separators/codac2_SepTest.cpp
Original file line number Diff line number Diff line change
@@ -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 <vector>

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;
}
}
49 changes: 49 additions & 0 deletions src/core/separators/codac2_SepTest.h
Original file line number Diff line number Diff line change
@@ -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 <type_traits>
#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<SepTest>
{
public:

/**
* \brief Constructor for the separator.
*
* \param s The separator to test.
*/
template<typename S>
requires IsSepBaseOrPtr<S>
SepTest(const S& s)
: Sep<SepTest>(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<SepBase> _sep;
};
}
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions tests/core/separators/codac2_tests_SepTest.cpp
Original file line number Diff line number Diff line change
@@ -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 <catch2/catch_test_macros.hpp>
#include <codac2_SepTest.h>
#include <codac2_Approx.h>
#include <codac2_SepWrapper.h>

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 = 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);
}
38 changes: 38 additions & 0 deletions tests/core/separators/codac2_tests_SepTest.py
Original file line number Diff line number Diff line change
@@ -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()
Loading