[geos-commits] [SCM] GEOS branch main updated. dcde8ad8a15eabdafd3a7c3ef78d6cf20cf800de

git at osgeo.org git at osgeo.org
Wed Nov 15 15:48:01 PST 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, main has been updated
       via  dcde8ad8a15eabdafd3a7c3ef78d6cf20cf800de (commit)
      from  758238d1330a164738f868504afe0ce073dd3a31 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit dcde8ad8a15eabdafd3a7c3ef78d6cf20cf800de
Author: Mike Taves <mwtoews at gmail.com>
Date:   Thu Nov 16 12:46:59 2023 +1300

    Rename Angle::sinCos -> sinCosSnap

diff --git a/NEWS.md b/NEWS.md
index 505ddb2eb..faac38bd8 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,7 +2,7 @@
 20xx-xx-xx
 
 - New things:
-  - Add Angle::sinCos to avoid small errors, e.g. with buffer operations (GH-978, Mike Taves)
+  - Add Angle::sinCosSnap to avoid small errors, e.g. with buffer operations (GH-978, Mike Taves)
 
 - Breaking Changes
 
diff --git a/include/geos/algorithm/Angle.h b/include/geos/algorithm/Angle.h
index f4f2f604e..a2ea53a48 100644
--- a/include/geos/algorithm/Angle.h
+++ b/include/geos/algorithm/Angle.h
@@ -218,21 +218,22 @@ public:
     static double diff(double ang1, double ang2);
 
     /// \brief
-    /// Computes both sin and cos of an angle.
+    /// Computes both sin and cos of an angle, snapping near-zero values
+    /// to zero.
     ///
     /// The angle does not need to be normalized. Unlike std::sin
-    /// and std::cos, this method will clip near-zero values to zero
+    /// and std::cos, this method will snap near-zero values to zero
     /// for (e.g.) sin(pi) and cos(pi/2).
     ///
     /// @param ang the input angle (in radians)
     /// @param rSin the result of sin(ang)
     /// @param rCos the result of cos(ang)
     ///
-    static inline void sinCos(const double ang, double& rSin, double& rCos) {
+    static inline void sinCosSnap(const double ang, double& rSin, double& rCos) {
         // calculate both; may be optimized with FSINCOS instruction
         rSin = std::sin(ang);
         rCos = std::cos(ang);
-        // clip near zero values
+        // snap near-zero values
         if (std::fabs(rSin) < 5e-16) rSin = 0.0;
         if (std::fabs(rCos) < 5e-16) rCos = 0.0;
     }
diff --git a/src/operation/buffer/OffsetSegmentGenerator.cpp b/src/operation/buffer/OffsetSegmentGenerator.cpp
index 41e22a91c..915bbd954 100644
--- a/src/operation/buffer/OffsetSegmentGenerator.cpp
+++ b/src/operation/buffer/OffsetSegmentGenerator.cpp
@@ -222,7 +222,7 @@ OffsetSegmentGenerator::addLineEndCap(const Coordinate& p0, const Coordinate& p1
         // segment endpoints
         Coordinate squareCapSideOffset;
         double sinangle, cosangle;
-        Angle::sinCos(angle, sinangle, cosangle);
+        Angle::sinCosSnap(angle, sinangle, cosangle);
         squareCapSideOffset.x = fabs(distance) * cosangle;
         squareCapSideOffset.y = fabs(distance) * sinangle;
 
@@ -283,7 +283,7 @@ OffsetSegmentGenerator::addDirectedFillet(const Coordinate& p, double startAngle
     double sinangle, cosangle;
     Coordinate pt;
     for (int i = 0; i < nSegs; i++) {
-        Angle::sinCos(startAngle + directionFactor * i * angleInc, sinangle, cosangle);
+        Angle::sinCosSnap(startAngle + directionFactor * i * angleInc, sinangle, cosangle);
         pt.x = p.x + radius * cosangle;
         pt.y = p.y + radius * sinangle;
         segList.addPt(pt);
@@ -583,7 +583,7 @@ Coordinate
 OffsetSegmentGenerator::project(const Coordinate& pt, double d, double dir)
 {
     double sindir, cosdir;
-    Angle::sinCos(dir, sindir, cosdir);
+    Angle::sinCosSnap(dir, sindir, cosdir);
     double x = pt.x + d * cosdir;
     double y = pt.y + d * sindir;
     return Coordinate(x, y);
diff --git a/src/util/GeometricShapeFactory.cpp b/src/util/GeometricShapeFactory.cpp
index 4a63e0ac3..141ae5939 100644
--- a/src/util/GeometricShapeFactory.cpp
+++ b/src/util/GeometricShapeFactory.cpp
@@ -138,7 +138,7 @@ GeometricShapeFactory::createCircle()
     uint32_t iPt = 0;
     double sinang, cosang;
     for(uint32_t i = 0; i < nPts; i++) {
-        Angle::sinCos(i * Angle::PI_TIMES_2 / nPts, sinang, cosang);
+        Angle::sinCosSnap(i * Angle::PI_TIMES_2 / nPts, sinang, cosang);
         double x = xRadius * cosang + centreX;
         double y = yRadius * sinang + centreY;
         (*pts)[iPt++] = coord(x, y);
@@ -170,7 +170,7 @@ GeometricShapeFactory::createArc(double startAng, double angExtent)
     uint32_t iPt = 0;
     double sinang, cosang;
     for(uint32_t i = 0; i < nPts; i++) {
-        Angle::sinCos(startAng + i * angInc, sinang, cosang);
+        Angle::sinCosSnap(startAng + i * angInc, sinang, cosang);
         double x = xRadius * cosang + centreX;
         double y = yRadius * sinang + centreY;
         (*pts)[iPt++] = coord(x, y);
@@ -201,7 +201,7 @@ GeometricShapeFactory::createArcPolygon(double startAng, double angExtent)
     (*pts)[iPt++] = coord(centreX, centreY);
     double sinang, cosang;
     for(uint32_t i = 0; i < nPts; i++) {
-        Angle::sinCos(startAng + i * angInc, sinang, cosang);
+        Angle::sinCosSnap(startAng + i * angInc, sinang, cosang);
         double x = xRadius * cosang + centreX;
         double y = yRadius * sinang + centreY;
         (*pts)[iPt++] = coord(x, y);
diff --git a/tests/unit/algorithm/AngleTest.cpp b/tests/unit/algorithm/AngleTest.cpp
index 02eae99e8..cc889c5e9 100644
--- a/tests/unit/algorithm/AngleTest.cpp
+++ b/tests/unit/algorithm/AngleTest.cpp
@@ -162,7 +162,7 @@ void object::test<5>
         TOL);
 }
 
-// testSinCos()
+// testSinCosSnap()
 template<>
 template<>
 void object::test<6>
@@ -174,7 +174,7 @@ void object::test<6>
     for (int angdeg = -720; angdeg <= 720; angdeg++) {
         const double ang = Angle::toRadians(angdeg);
 
-        Angle::sinCos(ang, rSin, rCos);
+        Angle::sinCosSnap(ang, rSin, rCos);
 
         double cSin = std::sin(ang);
         double cCos = std::cos(ang);
@@ -192,7 +192,7 @@ void object::test<6>
     // use radian increments that don't snap to exact degrees or zero
     for (double angrad = -6.3; angrad < 6.3; angrad += 0.013) {
 
-        Angle::sinCos(angrad, rSin, rCos);
+        Angle::sinCosSnap(angrad, rSin, rCos);
 
         ensure_equals(std::to_string(angrad), rSin, std::sin(angrad));
         ensure_equals(std::to_string(angrad), rCos, std::cos(angrad));

-----------------------------------------------------------------------

Summary of changes:
 NEWS.md                                         | 2 +-
 include/geos/algorithm/Angle.h                  | 9 +++++----
 src/operation/buffer/OffsetSegmentGenerator.cpp | 6 +++---
 src/util/GeometricShapeFactory.cpp              | 6 +++---
 tests/unit/algorithm/AngleTest.cpp              | 6 +++---
 5 files changed, 15 insertions(+), 14 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list