Commit 6c750a48 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[MERGE]

parents 36953055 93e92791
......@@ -76,6 +76,17 @@ namespace wmath
* \return Sum of all line segment lengths
*/
double pathLength() const;
/**
* Returns the point in the middle of the line. In case of an even sized
* line the mid point is the same as if there were only size()-1 many
* elements present.
*
* \throws WOutOfBounds In case its called on an empty line
*
* \return Const reference to the midpoint element.
*/
const wmath::WPosition& midPoint() const;
};
} // end of namespace
#endif // WLINE_H
......@@ -226,6 +226,49 @@ public:
// assert_SAMELINES( expected, line );
// }
/**
* The mid point of a WLine is just the point in the middle of the line.
* For lines with even numbered size the element before that non existing
* midPoint is selected.
*/
void testMidPointOnEvenSize( void )
{
using wmath::WPosition;
wmath::WLine line;
line.push_back( WPosition( 0, 0, 0 ) );
line.push_back( WPosition( 1, 1, 0 ) );
line.push_back( WPosition( 2, 0, 0 ) );
line.push_back( WPosition( 3, 1, 0 ) );
WPosition expected( 1, 1, 0 );
TS_ASSERT_EQUALS( expected, WPosition( line.midPoint() ) );
}
/**
* When a line has uneven numbered size, the mid point is unique.
*/
void testMidPointOnUnevenSize( void )
{
using wmath::WPosition;
wmath::WLine line;
line.push_back( WPosition( 0, 0, 0 ) );
line.push_back( WPosition( 1, 1, 0 ) );
line.push_back( WPosition( 2, 0, 0 ) );
WPosition expected( 1, 1, 0 );
TS_ASSERT_EQUALS( expected, WPosition( line.midPoint() ) );
}
/**
* When calling midPoint on empty lines => there is no point to return
* hence an exception is generated.
*/
void testMidPointOnEmptyLine( void )
{
using wmath::WPosition;
wmath::WLine line;
WPosition expected( 1, 1, 0 );
TS_ASSERT_THROWS_EQUALS( line.midPoint(), WOutOfBounds &e, std::string( e.what() ), "There is no midpoint for an empty line." );
}
private:
/**
* TS_ASSERT_DELTA needs the operator+, operator- and operator< to be implemented especially for WPositions the operator< and operator +
......
/* XPM */
static const char * eeg_xpm[] = {
"16 16 2 1",
" c None",
". c #000000",
" ... ",
". ... . ",
" . . ....",
" ... ",
" . ",
" . . ",
". . . ",
" . . . .",
" .... . . ",
" . . ",
" . ",
" ",
" .... ",
". . . ",
" ... . ...",
" .. "};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment