Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
93e92791
Commit
93e92791
authored
Mar 01, 2010
by
Mathias Goldau
Browse files
[ADD] Midpoint of fibers
parent
2a9159c7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
0 deletions
+68
-0
src/math/WLine.cpp
src/math/WLine.cpp
+10
-0
src/math/WLine.h
src/math/WLine.h
+11
-0
src/math/test/WLine_test.h
src/math/test/WLine_test.h
+47
-0
No files found.
src/math/WLine.cpp
View file @
93e92791
...
...
@@ -28,6 +28,7 @@
#include "../common/WLimits.h"
#include "../common/WStringUtils.h"
#include "../common/exceptions/WOutOfBounds.h"
#include "WLine.h"
#include "WPosition.h"
...
...
@@ -100,4 +101,13 @@ void WLine::resample( size_t numPoints )
assert
(
size
()
==
numPoints
&&
"Resampling of a line has failed! Is your fiber of length 0 or even the new sample rate??"
);
}
const
wmath
::
WPosition
&
WLine
::
midPoint
()
const
{
if
(
empty
()
)
{
throw
WOutOfBounds
(
"There is no midpoint for an empty line."
);
}
return
at
(
(
size
()
-
1
)
/
2
);
}
}
// end of namespace
src/math/WLine.h
View file @
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
src/math/test/WLine_test.h
View file @
93e92791
...
...
@@ -31,8 +31,10 @@
#include <cxxtest/TestSuite.h>
#include "../../common/WLimits.h"
#include "../../common/exceptions/WOutOfBounds.h"
#include "../WLine.h"
#include "WLineTraits.h"
#include "WVector3DTraits.h"
/**
* Unit tests the WLine class
...
...
@@ -226,6 +228,51 @@ 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 +
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment