From ed3ff69b60ce0f936f5a94ac4ddb9d796c5186e1 Mon Sep 17 00:00:00 2001 From: SimonRohou Date: Tue, 16 Feb 2021 12:32:20 +0100 Subject: [PATCH] [tube] added TubeTreeSynthesis::slice(double t) --- src/core/domains/tube/codac_Tube.cpp | 2 +- .../domains/tube/codac_TubeTreeSynthesis.cpp | 23 +++++++++++++++++++ .../domains/tube/codac_TubeTreeSynthesis.h | 2 ++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/core/domains/tube/codac_Tube.cpp b/src/core/domains/tube/codac_Tube.cpp index b96af11a..92f868e6 100644 --- a/src/core/domains/tube/codac_Tube.cpp +++ b/src/core/domains/tube/codac_Tube.cpp @@ -347,7 +347,7 @@ namespace codac assert(tdomain().contains(t)); if(m_synthesis_tree != NULL) // fast evaluation - return m_synthesis_tree->slice(m_synthesis_tree->time_to_index(t)); + return m_synthesis_tree->slice(t); else { diff --git a/src/core/domains/tube/codac_TubeTreeSynthesis.cpp b/src/core/domains/tube/codac_TubeTreeSynthesis.cpp index 76a6d469..6319f7c6 100644 --- a/src/core/domains/tube/codac_TubeTreeSynthesis.cpp +++ b/src/core/domains/tube/codac_TubeTreeSynthesis.cpp @@ -234,6 +234,29 @@ namespace codac } } + Slice* TubeTreeSynthesis::slice(double t) + { + assert(tdomain().contains(t)); + return const_cast(static_cast(*this).slice(t)); + } + + const Slice* TubeTreeSynthesis::slice(double t) const + { + assert(tdomain().contains(t)); + + if(is_leaf()) + return m_slice_ref; + + else + { + if(t < m_first_subtree->tdomain().ub()) + return m_first_subtree->slice(t); + + else + return m_second_subtree->slice(t); + } + } + void TubeTreeSynthesis::request_values_update() { if(m_values_update_needed) diff --git a/src/core/domains/tube/codac_TubeTreeSynthesis.h b/src/core/domains/tube/codac_TubeTreeSynthesis.h index fc07f554..e9f98d32 100644 --- a/src/core/domains/tube/codac_TubeTreeSynthesis.h +++ b/src/core/domains/tube/codac_TubeTreeSynthesis.h @@ -33,6 +33,8 @@ namespace codac int time_to_index(double t) const; Slice* slice(int slice_id); const Slice* slice(int slice_id) const; + Slice* slice(double t); + const Slice* slice(double t) const; bool is_leaf() const; bool is_root() const;