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
afa921d6
Commit
afa921d6
authored
Oct 01, 2010
by
Mathias Goldau
Browse files
[ADD] New method for WLine and hence for WFiber to determine the maxSegementLength
parent
739294b0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
7 deletions
+58
-7
src/common/datastructures/WFiber.cpp
src/common/datastructures/WFiber.cpp
+1
-1
src/common/math/WLine.cpp
src/common/math/WLine.cpp
+15
-1
src/common/math/WLine.h
src/common/math/WLine.h
+9
-1
src/common/math/test/WLine_test.h
src/common/math/test/WLine_test.h
+33
-4
No files found.
src/common/datastructures/WFiber.cpp
View file @
afa921d6
...
...
@@ -22,8 +22,8 @@
//
//---------------------------------------------------------------------------
#include <cmath>
#include <algorithm>
#include <cmath>
#include <utility>
#include <vector>
...
...
src/common/math/WLine.cpp
View file @
afa921d6
...
...
@@ -27,10 +27,10 @@
#include <string>
#include <vector>
#include "../exceptions/WOutOfBounds.h"
#include "../WAssert.h"
#include "../WLimits.h"
#include "../WStringUtils.h"
#include "../exceptions/WOutOfBounds.h"
#include "WLine.h"
#include "WPosition.h"
...
...
@@ -140,4 +140,18 @@ int WLine::equalsDelta( const wmath::WLine& other, double delta ) const
return
diffPos
;
}
double
WLine
::
maxSegmentLength
()
const
{
double
result
=
0.0
;
if
(
empty
()
||
size
()
==
1
)
{
return
result
;
}
for
(
size_t
i
=
0
;
i
<
size
()
-
1
;
++
i
)
{
result
=
std
::
max
(
result
,
(
(
*
this
)[
i
]
-
(
*
this
)[
i
+
1
]
).
norm
()
);
}
return
result
;
}
}
// end of namespace
src/common/math/WLine.h
View file @
afa921d6
...
...
@@ -29,9 +29,9 @@
#include <iostream>
#include <vector>
#include "../WExportCommon.h"
#include "../WMixinVector.h"
#include "WPosition.h"
#include "../WExportCommon.h"
// we need this to find the WLineTest class which is not inside wmath namespace
class
WLineTest
;
...
...
@@ -98,6 +98,14 @@ namespace wmath
* \return -1 in case of the two fibers are considered equal, otherwise the first position on which they differ is returned.
*/
int
equalsDelta
(
const
wmath
::
WLine
&
other
,
double
delta
)
const
;
/**
* Compute the maximal segment length of all segements. If there are no segements meaning
* zero or one point, zero is returned.
*
* \return Max segement length or zero if there aren't any.
*/
double
maxSegmentLength
()
const
;
};
}
// end of namespace
#endif // WLINE_H
src/common/math/test/WLine_test.h
View file @
afa921d6
...
...
@@ -25,13 +25,13 @@
#ifndef WLINE_TEST_H
#define WLINE_TEST_H
#include <string>
#include <sstream>
#include <string>
#include <cxxtest/TestSuite.h>
#include "../../WLimits.h"
#include "../../exceptions/WOutOfBounds.h"
#include "../../WLimits.h"
#include "../WLine.h"
#include "WLineTraits.h"
#include "WPositionTraits.h"
...
...
@@ -317,12 +317,41 @@ public:
*/
void
testMidPointOnEmptyLine
(
void
)
{
using
wmath
::
WPosition
;
wmath
::
WLine
line
;
WPosition
expected
(
1
,
1
,
0
);
wmath
::
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."
);
}
/**
* The max segemnent length is the maximum length over all segments (p_i<->p_j). For further
* information look just on the name of the test function, I think this is really precised ;).
* (Ha one more line in hg churn!)
* BTW: If there are multiple max lengths (equidistant sampled tracts) the first shall be
* chosen, BTW: this is totally stupid!, if they are equals it doesn't matter anyway, huh???
*/
void
testMaxSegementLength
(
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
)
);
TS_ASSERT_DELTA
(
line
.
maxSegmentLength
(),
std
::
sqrt
(
2.0
),
wlimits
::
DBL_EPS
);
line
.
push_back
(
WPosition
(
0
,
0
,
0
)
);
TS_ASSERT_DELTA
(
line
.
maxSegmentLength
(),
2.0
,
wlimits
::
DBL_EPS
);
}
/**
* If there no points at all, 0.0 shall be returned.
*/
void
testEmptyLineOnMaxSegementLength
(
void
)
{
wmath
::
WLine
line
;
TS_ASSERT_EQUALS
(
line
.
maxSegmentLength
(),
0.0
);
line
.
push_back
(
wmath
::
WPosition
(
0
,
3.1415
,
0
)
);
TS_ASSERT_EQUALS
(
line
.
maxSegmentLength
(),
0.0
);
}
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