From ff9339905034db40b87da20ffd6a3c7f46bc079c Mon Sep 17 00:00:00 2001
From: sam <sam@92316355-f0b4-4df1-b90c-862c8a59935f>
Date: Wed, 27 May 2009 05:04:30 +0000
Subject: [PATCH] Fix img2twit's rendering. Apparently CGAL's Delaunay
 triangulation module does not work with negative indices.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3529 92316355-f0b4-4df1-b90c-862c8a59935f
---
 examples/img2twit.cpp | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/examples/img2twit.cpp b/examples/img2twit.cpp
index ffda4fc..f27370d 100644
--- a/examples/img2twit.cpp
+++ b/examples/img2twit.cpp
@@ -648,23 +648,23 @@ static void render(pipi_image_t *dst,
     {
         float fx, fy, fr, fg, fb, fs;
         get_point(i, &fx, &fy, &fr, &fg, &fb, &fs);
-        dt.insert(K::Point_2(fx, fy));
+        dt.insert(K::Point_2(fx + dw * RANGE_X, fy + dh * RANGE_Y));
         /* Keep link to point */
         lookup[(int)(fx * 2) + dw * RANGE_X * 2 * (int)(fy * 2)] = i;
     }
 
     /* Add fake points to close the triangulation */
-    dt.insert(K::Point_2(-dw * RANGE_X, -dh * RANGE_Y));
-    dt.insert(K::Point_2(2 * dw * RANGE_X, -dh * RANGE_Y));
-    dt.insert(K::Point_2(-dw * RANGE_X, 2 * dh * RANGE_Y));
-    dt.insert(K::Point_2(2 * dw * RANGE_X, 2 * dh * RANGE_Y));
+    dt.insert(K::Point_2(0, 0));
+    dt.insert(K::Point_2(3 * dw * RANGE_X, 0));
+    dt.insert(K::Point_2(0, 3 * dh * RANGE_Y));
+    dt.insert(K::Point_2(3 * dw * RANGE_X, 3 * dh * RANGE_Y));
 
     for(y = ry; y < ry + rh; y++)
     {
         for(x = rx; x < rx + rw; x++)
         {
-            K::Point_2 m((float)x * dw * RANGE_X / p->w,
-                         (float)y * dh * RANGE_Y / p->h);
+            K::Point_2 m((float)x * dw * RANGE_X / p->w + dw * RANGE_X,
+                         (float)y * dh * RANGE_Y / p->h + dh * RANGE_Y);
             Point_coordinate_vector coords;
             CGAL::Triple<
               std::back_insert_iterator<Point_coordinate_vector>,
@@ -679,8 +679,8 @@ static void render(pipi_image_t *dst,
             {
                 float fx, fy, fr, fg, fb, fs;
 
-                fx = (*it).first.x();
-                fy = (*it).first.y();
+                fx = (*it).first.x() - dw * RANGE_X;
+                fy = (*it).first.y() - dh * RANGE_Y;
 
                 if(fx < 0 || fy < 0
                     || fx > dw * RANGE_X - 1 || fy > dh * RANGE_Y - 1)