Skip to content

Commit

Permalink
Merge pull request #14283 from mantidproject/14297_Fix_bug_in_Convert…
Browse files Browse the repository at this point in the history
…ToReflectometryQ

Fix bug in ConvertToReflectometryQ
  • Loading branch information
OwenArnold committed Nov 5, 2015
2 parents 049cbfc + e132f19 commit 35015ba
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
Expand Up @@ -80,6 +80,12 @@ class CalculateReflectometryQxQz : public CalculateReflectometry {
calculateDim1(lamUpper));

Mantid::Geometry::Quadrilateral quad(ll, lr, ur, ul);

while ((quad.at(0).X() > quad.at(3).X()) ||
(quad.at(0).Y() > quad.at(1).Y())) {
quad.shiftVertexesClockwise();
}

return quad;
}
};
Expand Down
3 changes: 2 additions & 1 deletion Framework/DataObjects/src/FractionalRebinning.cpp
Expand Up @@ -20,7 +20,8 @@ namespace FractionalRebinning {

/**
* Find the possible region of intersection on the output workspace for the
* given polygon. The given polygon must have a CLOCKWISE winding.
* given polygon. The given polygon must have a CLOCKWISE winding and the
* first vertex must be the "lowest left" point.
* @param outputWS A pointer to the output workspace
* @param verticalAxis A vector containing the output vertical axis edges
* @param inputQ The input polygon (Polygon winding must be clockwise)
Expand Down
2 changes: 2 additions & 0 deletions Framework/Geometry/inc/MantidGeometry/Math/Quadrilateral.h
Expand Up @@ -73,6 +73,8 @@ class DLLExport Quadrilateral : public ConvexPolygon {
virtual double maxY() const;
/// Return a new Polygon based on the current Quadrilateral
virtual ConvexPolygon toPoly() const;
/// Shifts the vertexes in a clockwise manner
virtual void shiftVertexesClockwise();

private:
/// Lower left
Expand Down
11 changes: 11 additions & 0 deletions Framework/Geometry/src/Math/Quadrilateral.cpp
Expand Up @@ -156,5 +156,16 @@ ConvexPolygon Quadrilateral::toPoly() const {
return ConvexPolygon(points);
}

/// Shifts the vertexes in a clockwise manner
void Quadrilateral::shiftVertexesClockwise() {

V2D temp = m_lowerLeft;

m_lowerLeft = m_upperLeft;
m_upperLeft = m_upperRight;
m_upperRight = m_lowerRight;
m_lowerRight = temp;
}

} // namespace Mantid
} // namespace Geometry
16 changes: 16 additions & 0 deletions Framework/Geometry/test/QuadrilateralTest.h
Expand Up @@ -85,6 +85,22 @@ class QuadrilateralTest : public CxxTest::TestSuite {
TS_ASSERT(!smallRectangle.contains(largeRectangle));
}

void test_clockwise_rotation() {
Quadrilateral quad(V2D(0.0, 0.0), V2D(1.0, 3.0), V2D(4.0, 4.0),
V2D(4.0, 1.0));

quad.shiftVertexesClockwise();

TS_ASSERT_EQUALS(quad.at(0).X(), 4.0);
TS_ASSERT_EQUALS(quad.at(0).Y(), 1.0);
TS_ASSERT_EQUALS(quad.at(1).X(), 4.0);
TS_ASSERT_EQUALS(quad.at(1).Y(), 4.0);
TS_ASSERT_EQUALS(quad.at(2).X(), 1.0);
TS_ASSERT_EQUALS(quad.at(2).Y(), 3.0);
TS_ASSERT_EQUALS(quad.at(3).X(), 0.0);
TS_ASSERT_EQUALS(quad.at(3).Y(), 0.0);
}

private:
Quadrilateral makeRectangle() {
return Quadrilateral(V2D(), V2D(2.0, 0.0), V2D(2.0, 1.5), V2D(0.0, 1.5));
Expand Down

0 comments on commit 35015ba

Please sign in to comment.