[geos-commits] r3307 - in trunk: include/geos/algorithm src/algorithm tests/unit tests/unit/algorithm

svn_geos at osgeo.org svn_geos at osgeo.org
Wed Apr 27 11:18:08 EDT 2011


Author: strk
Date: 2011-04-27 08:18:08 -0700 (Wed, 27 Apr 2011)
New Revision: 3307

Added:
   trunk/tests/unit/algorithm/AngleTest.cpp
Modified:
   trunk/include/geos/algorithm/Angle.h
   trunk/src/algorithm/Angle.cpp
   trunk/tests/unit/Makefile.am
Log:
Sync Angle class to JTS-1.12, port unit testing for it.

Modified: trunk/include/geos/algorithm/Angle.h
===================================================================
--- trunk/include/geos/algorithm/Angle.h	2011-04-27 14:13:45 UTC (rev 3306)
+++ trunk/include/geos/algorithm/Angle.h	2011-04-27 15:18:08 UTC (rev 3307)
@@ -4,7 +4,7 @@
  * GEOS - Geometry Engine Open Source
  * http://geos.refractions.net
  *
- * Copyright (C) 2009  Sandro Santilli <strk at keybit.net>
+ * Copyright (C) 2009-2011  Sandro Santilli <strk at keybit.net>
  *
  * This is free software; you can redistribute and/or modify it under
  * the terms of the GNU Lesser General Public Licence as published
@@ -13,7 +13,7 @@
  *
  **********************************************************************
  *
- * Last port: algorithm/Angle.java rev. 1.6 (JTS-1.9)
+ * Last port: algorithm/Angle.java r378 (JTS-1.12)
  *
  **********************************************************************/
 

Modified: trunk/src/algorithm/Angle.cpp
===================================================================
--- trunk/src/algorithm/Angle.cpp	2011-04-27 14:13:45 UTC (rev 3306)
+++ trunk/src/algorithm/Angle.cpp	2011-04-27 15:18:08 UTC (rev 3307)
@@ -4,7 +4,7 @@
  * GEOS - Geometry Engine Open Source
  * http://geos.refractions.net
  *
- * Copyright (C) 2009  Sandro Santilli <strk at keybit.net>
+ * Copyright (C) 2009-2011 Sandro Santilli <strk at keybit.net>
  *
  * This is free software; you can redistribute and/or modify it under
  * the terms of the GNU Lesser General Public Licence as published
@@ -13,7 +13,7 @@
  *
  **********************************************************************
  *
- * Last port: algorithm/Angle.java rev. 1.6 (JTS-1.9)
+ * Last port: algorithm/Angle.java r378 (JTS-1.12)
  *
  **********************************************************************/
 
@@ -27,7 +27,7 @@
 namespace algorithm { // geos.algorithm
 
 namespace { 
-	const double PI = 3.14159265358979;
+	const double PI = 3.14159265358979323846;
 }
 
 const double Angle::PI_TIMES_2 = 2.0 * PI; 

Modified: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am	2011-04-27 14:13:45 UTC (rev 3306)
+++ trunk/tests/unit/Makefile.am	2011-04-27 15:18:08 UTC (rev 3307)
@@ -30,6 +30,7 @@
 
 geos_unit_SOURCES = \
 	geos_unit.cpp \
+	algorithm/AngleTest.cpp \
 	algorithm/CGAlgorithms/isCCWTest.cpp \
 	algorithm/CGAlgorithms/isPointInRingTest.cpp \
 	algorithm/CGAlgorithms/computeOrientationTest.cpp \

Added: trunk/tests/unit/algorithm/AngleTest.cpp
===================================================================
--- trunk/tests/unit/algorithm/AngleTest.cpp	                        (rev 0)
+++ trunk/tests/unit/algorithm/AngleTest.cpp	2011-04-27 15:18:08 UTC (rev 3307)
@@ -0,0 +1,129 @@
+// $Id$
+// 
+// Test Suite for geos::algorithm::Angle 
+// Ported from JTS junit/algorithm/AngleTest.java r378
+
+#include <tut.hpp>
+// geos
+#include <geos/geom/Coordinate.h>
+#include <geos/algorithm/Angle.h>
+// std
+#include <sstream>
+#include <string>
+#include <memory>
+
+namespace tut
+{
+	//
+	// Test Group
+	//
+
+	// dummy data, not used
+	struct test_angle_data {
+    typedef geos::geom::Coordinate Coordinate;
+    typedef geos::algorithm::Angle Angle;
+
+    double TOL;
+	  double PI;
+
+	  test_angle_data()
+      :
+      TOL (1e-5),
+	    PI  ( 3.14159265358979323846 )
+    {}
+
+	};
+
+	typedef test_group<test_angle_data> group;
+	typedef group::object object;
+
+	group test_angle_group("geos::algorithm::Angle");
+
+	//
+	// Test Cases
+	//
+
+	// testAngle()
+	template<>
+	template<>
+	void object::test<1>()
+	{
+    ensure_equals("1", Angle::angle(Coordinate(10,0)), 0.0, TOL);
+    ensure_equals("2", Angle::angle(Coordinate(10,10)), PI/4, TOL);
+    ensure_equals("3", Angle::angle(Coordinate(0,10)), PI/2, TOL);
+    ensure_equals("4", Angle::angle(Coordinate(-10,10)), 0.75*PI, TOL);
+    ensure_equals("5", Angle::angle(Coordinate(-10,0)), PI, TOL);
+    ensure_equals("6", Angle::angle(Coordinate(-10,-0.1)), -3.131592987, TOL);
+    ensure_equals("7", Angle::angle(Coordinate(-10,-10)), -0.75*PI, TOL);
+	}
+
+	// testIsAcute()
+	template<>
+	template<>
+	void object::test<2>()
+	{
+    ensure(Angle::isAcute(
+      Coordinate(10,0), Coordinate(0,0), Coordinate(5,10)));
+    ensure(Angle::isAcute(
+      Coordinate(10,0), Coordinate(0,0), Coordinate(5,-10)));
+    // angle of 0
+    ensure(Angle::isAcute(
+      Coordinate(10,0), Coordinate(0,0), Coordinate(10,0)));
+    ensure_not(Angle::isAcute(
+      Coordinate(10,0), Coordinate(0,0), Coordinate(-5,10)));
+    ensure_not(Angle::isAcute(
+      Coordinate(10,0), Coordinate(0,0), Coordinate(-5,-10)));
+	}
+
+	// testNormalizePositive()
+	template<>
+	template<>
+	void object::test<3>()
+	{
+    ensure_equals("", Angle::normalizePositive(0.0), 0.0, TOL);
+
+    ensure_equals("", Angle::normalizePositive(-0.5*PI), 1.5*PI, TOL);
+    ensure_equals("", Angle::normalizePositive(-PI), PI, TOL);
+    ensure_equals("", Angle::normalizePositive(-1.5*PI), .5*PI, TOL);
+    ensure_equals("", Angle::normalizePositive(-2*PI), 0.0, TOL);
+    ensure_equals("", Angle::normalizePositive(-2.5*PI), 1.5*PI, TOL);
+    ensure_equals("", Angle::normalizePositive(-3*PI), PI, TOL);
+    ensure_equals("", Angle::normalizePositive(-4 * PI), 0.0, TOL);
+
+    ensure_equals("", Angle::normalizePositive(0.5*PI), 0.5*PI, TOL);
+    ensure_equals("", Angle::normalizePositive(PI), PI, TOL);
+    ensure_equals("", Angle::normalizePositive(1.5*PI), 1.5*PI, TOL);
+    ensure_equals("", Angle::normalizePositive(2*PI), 0.0, TOL);
+    ensure_equals("", Angle::normalizePositive(2.5*PI), 0.5*PI, TOL);
+    ensure_equals("", Angle::normalizePositive(3*PI), PI, TOL);
+    ensure_equals("", Angle::normalizePositive(4 * PI), 0.0, TOL);
+	}
+
+	// testNormalize()
+	template<>
+	template<>
+	void object::test<4>()
+	{
+    ensure_equals("1", Angle::normalize(0.0), 0.0, TOL);
+
+    ensure_equals("2", Angle::normalize(-0.5*PI), -0.5*PI, TOL);
+    ensure_equals("3", Angle::normalize(-PI), PI, TOL);
+    ensure_equals("4", Angle::normalize(-1.5*PI), .5*PI, TOL);
+    ensure_equals("5", Angle::normalize(-2*PI), 0.0, TOL);
+    ensure_equals("6", Angle::normalize(-2.5*PI), -0.5*PI, TOL);
+    ensure_equals("7", Angle::normalize(-3*PI), PI, TOL);
+    ensure_equals("8", Angle::normalize(-4 * PI), 0.0, TOL);
+
+    ensure_equals("9", Angle::normalize(0.5*PI), 0.5*PI, TOL);
+    ensure_equals("10", Angle::normalize(PI), PI, TOL);
+    ensure_equals("11", Angle::normalize(1.5*PI), -0.5*PI, TOL);
+    ensure_equals("12", Angle::normalize(2*PI), 0.0, TOL);
+    ensure_equals("13", Angle::normalize(2.5*PI), 0.5*PI, TOL);
+    ensure_equals("14", Angle::normalize(3*PI), PI, TOL);
+    ensure_equals("15", Angle::normalize(4 * PI), 0.0, TOL);
+	}
+
+
+
+} // namespace tut
+



More information about the geos-commits mailing list