From 7f473799acaa7b277f9f7c36220e5f393df6948e Mon Sep 17 00:00:00 2001 From: zzzzrrr Date: Thu, 19 Nov 2009 10:48:56 -0500 Subject: [PATCH] fixed seidel numerical accuracy bug --- python/poly2tri.py | 4 ++-- python/seidel.py | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/python/poly2tri.py b/python/poly2tri.py index 73570ec..9350017 100644 --- a/python/poly2tri.py +++ b/python/poly2tri.py @@ -11,7 +11,7 @@ class Poly2Tri(Game): super(Poly2Tri, self).__init__(*self.screen_size) # Load point set - file_name = "../data/dude.dat" + file_name = "../data/nazca_monkey.dat" self.points = self.load_points(file_name) # Triangulate @@ -30,7 +30,7 @@ class Poly2Tri(Game): pass def render(self): - reset_zoom(2.0, (400, 500), self.screen_size) + reset_zoom(8, (0, 0), self.screen_size) red = 255, 0, 0 for t in self.triangles: draw_polygon(t, red) diff --git a/python/seidel.py b/python/seidel.py index 367d45f..6c4c596 100644 --- a/python/seidel.py +++ b/python/seidel.py @@ -30,7 +30,7 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # from random import shuffle -from math import atan2, floor +from math import atan2 ## ## Based on Raimund Seidel'e paper "A simple and fast incremental randomized @@ -94,10 +94,12 @@ class Edge(object): self.mpoints.append(q) def is_above(self, point): - return (floor(point.y) < floor(self.slope * point.x + self.b)) + # NOTE rounding can effect numerical robustness + return (round(point.y, 10) < round(self.slope * point.x + self.b, 10)) def is_below(self, point): - return (floor(point.y) > floor(self.slope * point.x + self.b)) + # NOTE rounding can effect numerical robustness + return (round(point.y, 10) > round(self.slope * point.x + self.b, 10)) def intersect(self, c, d): a = self.p