Skip to content

Commit

Permalink
A few minor performance tweaks.
Browse files Browse the repository at this point in the history
Refs #12584
  • Loading branch information
martyngigg committed Jun 24, 2015
1 parent 8db00cb commit 5520145
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DLLExport PolygonEdge {
/// Access the end point
inline const Kernel::V2D &end() const { return m_end; }
/// Return the direction
inline Kernel::V2D direction() const { return m_end - m_start; }
inline const Kernel::V2D &direction() const { return m_dir; }
/// Create a point a given fraction along this edge
Kernel::V2D point(const double fraction) const;

Expand All @@ -66,6 +66,8 @@ class DLLExport PolygonEdge {
const Kernel::V2D m_start;
/// Destination point
const Kernel::V2D m_end;
/// Direction vector
const Kernel::V2D m_dir;
};

/// Enumeration for point type w.r.t an edge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class DLLExport Quadrilateral : public ConvexPolygon {

/// Index access.
virtual const Kernel::V2D &operator[](const size_t index) const;
/// Bounds-checked index access
virtual const Kernel::V2D &at(const size_t index) const;
/// Return the number of vertices
virtual size_t npoints() const { return 4; }
/// Is a point inside this polygon
Expand All @@ -73,8 +75,6 @@ class DLLExport Quadrilateral : public ConvexPolygon {
virtual ConvexPolygon toPoly() const;

private:
/// Default constructor
Quadrilateral();
/// Lower left
Kernel::V2D m_lowerLeft;
/// Lower right
Expand Down
5 changes: 2 additions & 3 deletions Code/Mantid/Framework/Geometry/src/Math/PolygonEdge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ namespace
* Contructor taking two points, start and end
*/
PolygonEdge::PolygonEdge(const Kernel::V2D &start, const Kernel::V2D &end)
: m_start(start), m_end(end) {}
: m_start(start), m_end(end), m_dir(m_end-m_start) {}

/**
* Create a point a given fraction along this edge
* @param fraction :: The fraction of the current edge
* @returns A point on the edge
*/
Kernel::V2D PolygonEdge::point(const double fraction) const {
const V2D dir = (end() - start());
return V2D(start() + dir * fraction);
return start() + m_dir * fraction;
}

//-------------------------------------------------------------------------
Expand Down
17 changes: 13 additions & 4 deletions Code/Mantid/Framework/Geometry/src/Math/Quadrilateral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Quadrilateral &Quadrilateral::operator=(const Quadrilateral &rhs) {
* @throws Exception::IndexError if the index is out of range
*/
const V2D &Quadrilateral::operator[](const size_t index) const {
if (index < npoints()) {
switch (index) {
case 0:
return m_lowerLeft;
Expand All @@ -66,10 +65,20 @@ const V2D &Quadrilateral::operator[](const size_t index) const {
return m_upperRight;
case 3:
return m_lowerRight;
}
default: throw Kernel::Exception::IndexError(index, npoints(),
"Quadrilateral::operator[]");
}
throw Kernel::Exception::IndexError(index, npoints(),
"Quadrilateral::operator[]");
}

/**
* Return the vertex at the given index
* @param index :: An index, starting at 0
* @returns A reference to the polygon at that index
* @throws Exception::IndexError if the index is out of range
*/
const Kernel::V2D &Quadrilateral::at(const size_t index) const
{
return (*this)[index];
}

/**
Expand Down

0 comments on commit 5520145

Please sign in to comment.