From 015f4da35e0958e2bcd2d310672d47552458de61 Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Wed, 4 Sep 2013 14:37:36 +0200
Subject: [PATCH] Added weighted point class and a test.

---
 MathLib/TemplateWeightedPoint.h | 45 +++++++++++++++++++++++++++++
 Tests/MathLib/WeightedPoint.cpp | 50 +++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+)
 create mode 100644 MathLib/TemplateWeightedPoint.h
 create mode 100644 Tests/MathLib/WeightedPoint.cpp

diff --git a/MathLib/TemplateWeightedPoint.h b/MathLib/TemplateWeightedPoint.h
new file mode 100644
index 00000000000..b2375e8618b
--- /dev/null
+++ b/MathLib/TemplateWeightedPoint.h
@@ -0,0 +1,45 @@
+/**
+ * @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_ */
diff --git a/Tests/MathLib/WeightedPoint.cpp b/Tests/MathLib/WeightedPoint.cpp
new file mode 100644
index 00000000000..3b10a096550
--- /dev/null
+++ b/Tests/MathLib/WeightedPoint.cpp
@@ -0,0 +1,50 @@
+/**
+ * @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());
+}
-- 
GitLab