Skip to content
Snippets Groups Projects
Commit 015f4da3 authored by Tom Fischer's avatar Tom Fischer
Browse files

Added weighted point class and a test.

parent 3fac3fa6
No related branches found
No related tags found
No related merge requests found
/**
* @file TemplateWeightedPoint.h
* @date Sep 3, 2013
* @brief Weighted point class.
*
* @copyright
* Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/LICENSE.txt
*/
#ifndef TEMPLATEWEIGHTEDPOINT_H_
#define TEMPLATEWEIGHTEDPOINT_H_
#include "TemplatePoint.h"
namespace MathLib
{
template <typename FP_T, typename W_T, std::size_t DIM>
class TemplateWeightedPoint : public TemplatePoint<FP_T, DIM>
{
public:
TemplateWeightedPoint(std::initializer_list<FP_T> const& list, W_T weight) :
TemplatePoint<FP_T, DIM>(list), _weight(weight)
{}
W_T getWeight() const
{
return _weight;
}
private:
W_T _weight;
};
typedef TemplateWeightedPoint<double, double, 1> WeightedPoint1D;
typedef TemplateWeightedPoint<double, double, 2> WeightedPoint2D;
typedef TemplateWeightedPoint<double, double, 3> WeightedPoint3D;
} // end namespace MathLib
#endif /* TEMPLATEWEIGHTEDPOINT_H_ */
/**
* @file WeightedPoint.cpp
* @author Thomas Fischer
* @date Sep 4, 2013
* @brief
*
* @copyright
* Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/LICENSE.txt
*/
// google test
#include "gtest/gtest.h"
#include "TemplateWeightedPoint.h"
TEST(MathLib, WeightedPoint1D)
{
double pnt = 0.5;
double w = 100.0;
MathLib::WeightedPoint1D wpnt_1d({pnt}, w);
ASSERT_NEAR(wpnt_1d[0], pnt, std::numeric_limits<double>::min());
ASSERT_NEAR(wpnt_1d.getWeight(), w, std::numeric_limits<double>::min());
}
TEST(MathLib, WeightedPoint2D)
{
double pnt[2] = {0.1, 0.2};
double w = 200.0;
MathLib::WeightedPoint2D wpnt_2d({pnt[0], pnt[1]}, w);
ASSERT_NEAR(wpnt_2d[0], pnt[0], std::numeric_limits<double>::min());
ASSERT_NEAR(wpnt_2d[1], pnt[1], std::numeric_limits<double>::min());
ASSERT_NEAR(wpnt_2d.getWeight(), w, std::numeric_limits<double>::min());
}
TEST(MathLib, WeightedPoint3D)
{
double pnt[3] = {0.1, 0.2, 0.3};
double w = 300.0;
MathLib::WeightedPoint3D wpnt_3d({pnt[0], pnt[1], pnt[2]}, w);
ASSERT_NEAR(wpnt_3d[0], pnt[0], std::numeric_limits<double>::min());
ASSERT_NEAR(wpnt_3d[1], pnt[1], std::numeric_limits<double>::min());
ASSERT_NEAR(wpnt_3d[2], pnt[2], std::numeric_limits<double>::min());
ASSERT_NEAR(wpnt_3d.getWeight(), w, std::numeric_limits<double>::min());
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment