lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Adds epsilon to Bezier range calculations. (issue4820048)


From: mtsolo
Subject: Adds epsilon to Bezier range calculations. (issue4820048)
Date: Wed, 27 Jul 2011 08:37:06 +0000

Reviewers: ,

Message:
This passes regtests and adds a regtest to show it in action.

As I know nothing about rounding error in C++, I'd like others who are
more familiar with this to comment on the way I handle it.

Cheers,
MS

Description:
Adds epsilon to Bezier range calculations.

Please review this at http://codereview.appspot.com/4820048/

Affected files:
  A input/regression/bezier-rounding-error.ly
  M lily/bezier.cc


Index: input/regression/bezier-rounding-error.ly
diff --git a/input/regression/bezier-rounding-error.ly b/input/regression/bezier-rounding-error.ly
new file mode 100644
index 0000000000000000000000000000000000000000..0fe656e705756f45414e0192c01633af1a49f523
--- /dev/null
+++ b/input/regression/bezier-rounding-error.ly
@@ -0,0 +1,11 @@
+\version "2.15.7"
+
+\header {
+  texidoc = "Floating point rounding errors in the Bezier solver
+are encompassed by a small epsilon value to allow for solvable
+Bezier intersections.
+"
+}
+{
+  \slurUp \times 2/3 { a'8( a') a' }
+}
Index: lily/bezier.cc
diff --git a/lily/bezier.cc b/lily/bezier.cc
index e15b04827abd3ba39aa09fe2b1ee4eaea35524b9..078323f803cf6adf4faab23316de47f89d51e4b7 100644
--- a/lily/bezier.cc
+++ b/lily/bezier.cc
@@ -165,8 +165,9 @@ Bezier::polynomial (Axis a) const
 vector<Real>
 filter_solutions (vector<Real> sol)
 {
+  Real epsilon = 1e-10;
   for (vsize i = sol.size (); i--;)
-    if (sol[i] < 0 || sol[i] > 1)
+    if (sol[i] < 0 - epsilon || sol[i] > 1 + epsilon)
       sol.erase (sol.begin () + i);
   return sol;
 }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]