diff --git a/Framework/API/src/WorkspaceFactory.cpp b/Framework/API/src/WorkspaceFactory.cpp index 30dedbc1fe13fbb5d4707218919d8824470e3bbd..9fc696538fbc79b22d12054cd4ae9ab374fa3a10 100644 --- a/Framework/API/src/WorkspaceFactory.cpp +++ b/Framework/API/src/WorkspaceFactory.cpp @@ -5,6 +5,7 @@ // & Institut Laue - Langevin // SPDX - License - Identifier: GPL - 3.0 + #include "MantidAPI/WorkspaceFactory.h" +#include "MantidAPI/BinEdgeAxis.h" #include "MantidAPI/IPeaksWorkspace.h" #include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/MatrixWorkspace.h" @@ -127,10 +128,12 @@ void WorkspaceFactoryImpl::initializeFromParent( // deal with axis for (size_t i = 0; i < parent.m_axes.size(); ++i) { - const size_t newAxisLength = child.getAxis(i)->length(); - const size_t oldAxisLength = parent.getAxis(i)->length(); + const bool isBinEdge = + dynamic_cast<const BinEdgeAxis *const>(parent.m_axes[i]) != nullptr; + const size_t newAxisLength = child.m_axes[i]->length() + (isBinEdge ? 1 : 0); + const size_t oldAxisLength = parent.m_axes[i]->length(); - if (!differentSize || newAxisLength == oldAxisLength) { + if (!differentSize && newAxisLength == oldAxisLength) { // Need to delete the existing axis created in init above delete child.m_axes[i]; // Now set to a copy of the parent workspace's axis diff --git a/Framework/DataObjects/test/WorkspaceCreationTest.h b/Framework/DataObjects/test/WorkspaceCreationTest.h index 82eee10415802f66fd473500d74251905831c32f..a7fe8b94993a82c5df0908200f969f18960ede5f 100644 --- a/Framework/DataObjects/test/WorkspaceCreationTest.h +++ b/Framework/DataObjects/test/WorkspaceCreationTest.h @@ -9,6 +9,7 @@ #include <cxxtest/TestSuite.h> +#include "MantidAPI/BinEdgeAxis.h" #include "MantidAPI/Run.h" #include "MantidDataObjects/EventWorkspace.h" #include "MantidDataObjects/SpecialWorkspace2D.h" @@ -419,6 +420,30 @@ public: check_zeroed_data(*ws); } + void test_create_parent_numeric_vertical_axis() { + constexpr size_t parentNhist{3}; + const auto parent = create<Workspace2D>(parentNhist, Histogram(Points{1})); + NumericAxis *parentAxis = new NumericAxis({-1.5, -0.5, 2.3}); + parent->replaceAxis(1, parentAxis); + constexpr size_t nhist{2}; + const auto ws = create<Workspace2D>(*parent, nhist, parent->histogram(0)); + auto axis = ws->getAxis(1); + TS_ASSERT_DIFFERS(dynamic_cast<NumericAxis *>(axis), nullptr) + TS_ASSERT_EQUALS(axis->length(), nhist); + } + + void test_create_parent_bin_edge_vertical_axis() { + constexpr size_t parentNhist{3}; + const auto parent = create<Workspace2D>(parentNhist, Histogram(Points{1})); + BinEdgeAxis *parentAxis = new BinEdgeAxis({-1.5, -0.5, 2.3, 3.4}); + parent->replaceAxis(1, parentAxis); + constexpr size_t nhist{2}; + const auto ws = create<Workspace2D>(*parent, nhist, parent->histogram(0)); + auto axis = ws->getAxis(1); + TS_ASSERT_DIFFERS(dynamic_cast<BinEdgeAxis *>(axis), nullptr) + TS_ASSERT_EQUALS(axis->length(), nhist + 1); + } + void test_create_drop_events() { auto eventWS = create<EventWorkspace>(1, Histogram(BinEdges(3))); auto ws = create<HistoWorkspace>(*eventWS);