Commit afa921d6 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[ADD] New method for WLine and hence for WFiber to determine the maxSegementLength

parent 739294b0
......@@ -22,8 +22,8 @@
//
//---------------------------------------------------------------------------
#include <cmath>
#include <algorithm>
#include <cmath>
#include <utility>
#include <vector>
......
......@@ -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
......@@ -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
......@@ -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 +
......
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