[gimp] app: use gimp_transform_polygon() in gimp_transform_resize_boundary()



commit 3c0787e4c360348850df1898cca25c5db9ac967f
Author: Ell <ell_se yahoo com>
Date:   Sun Jan 28 14:50:13 2018 -0500

    app: use gimp_transform_polygon() in gimp_transform_resize_boundary()
    
    ... so that the transformed boundary is properly clipped.
    
    Adjust the boundary-size algorithms to operate on arbitrary
    polygons.
    
    Avoid using gimp_matrix3_will_explode() in
    gimp_drawable_transform_buffer_affine() and falling back to
    cropping the result, and avoid setting the "clip-to-input" property
    of gegl:transform.  Neither of those in needed anymore.
    
    This effectively reverts the app/ part of commit
    768d06614f203bf555bbda1f6186d4730ae2f8b5.  The next commit revets
    the libgimpmath/ part.

 app/core/gimp-transform-resize.c     |  550 +++++++++++++++++-----------------
 app/core/gimpdrawable-transform.c    |    4 -
 app/gegl/gimp-gegl-apply-operation.c |    9 +-
 app/gegl/gimp-gegl-apply-operation.h |    1 -
 4 files changed, 278 insertions(+), 286 deletions(-)
---
diff --git a/app/core/gimp-transform-resize.c b/app/core/gimp-transform-resize.c
index 85ef5b8..54c9172 100644
--- a/app/core/gimp-transform-resize.c
+++ b/app/core/gimp-transform-resize.c
@@ -25,6 +25,7 @@
 #include "core-types.h"
 
 #include "gimp-transform-resize.h"
+#include "gimp-transform-utils.h"
 #include "gimp-utils.h"
 
 
@@ -43,82 +44,73 @@
 
 typedef struct
 {
-  gdouble x, y;
-} Point;
-
-typedef struct
-{
-  Point   a, b, c, d;
-  gdouble area;
-  gdouble aspect;
+  GimpVector2 a, b, c, d;
+  gdouble     area;
+  gdouble     aspect;
 } Rectangle;
 
 
-static void      gimp_transform_resize_adjust        (gdouble    dx1,
-                                                      gdouble    dy1,
-                                                      gdouble    dx2,
-                                                      gdouble    dy2,
-                                                      gdouble    dx3,
-                                                      gdouble    dy3,
-                                                      gdouble    dx4,
-                                                      gdouble    dy4,
-                                                      gint      *x1,
-                                                      gint      *y1,
-                                                      gint      *x2,
-                                                      gint      *y2);
-static void      gimp_transform_resize_crop          (gdouble    dx1,
-                                                      gdouble    dy1,
-                                                      gdouble    dx2,
-                                                      gdouble    dy2,
-                                                      gdouble    dx3,
-                                                      gdouble    dy3,
-                                                      gdouble    dx4,
-                                                      gdouble    dy4,
-                                                      gdouble    aspect,
-                                                      gint      *x1,
-                                                      gint      *y1,
-                                                      gint      *x2,
-                                                      gint      *y2);
-
-static void      add_rectangle                       (Point      points[4],
-                                                      Rectangle *r,
-                                                      Point      a,
-                                                      Point      b,
-                                                      Point      c,
-                                                      Point      d);
-static gboolean  intersect                           (Point      a,
-                                                      Point      b,
-                                                      Point      c,
-                                                      Point      d,
-                                                      Point     *i);
-static gboolean  intersect_x                         (Point      a,
-                                                      Point      b,
-                                                      Point      c,
-                                                      Point     *i);
-static gboolean  intersect_y                         (Point      a,
-                                                      Point      b,
-                                                      Point      c,
-                                                      Point     *i);
-static gboolean  in_poly                             (Point      points[4],
-                                                      Point      p);
-static gboolean  point_on_border                     (Point      points[4],
-                                                      Point      p);
-
-static void      find_two_point_rectangle            (Rectangle *r,
-                                                      Point      points[4],
-                                                      gint       p);
-static void      find_three_point_rectangle_corner   (Rectangle *r,
-                                                      Point      points[4],
-                                                      gint       p);
-static void      find_three_point_rectangle          (Rectangle *r,
-                                                      Point      points[4],
-                                                      gint       p);
-static void      find_three_point_rectangle_triangle (Rectangle *r,
-                                                      Point      points[4],
-                                                      gint       p);
-static void      find_maximum_aspect_rectangle       (Rectangle *r,
-                                                      Point      points[4],
-                                                      gint       p);
+static void      gimp_transform_resize_adjust        (const GimpVector2 *points,
+                                                      gint               n_points,
+                                                      gint              *x1,
+                                                      gint              *y1,
+                                                      gint              *x2,
+                                                      gint              *y2);
+static void      gimp_transform_resize_crop          (const GimpVector2 *points,
+                                                      gint               n_points,
+                                                      gdouble            aspect,
+                                                      gint              *x1,
+                                                      gint              *y1,
+                                                      gint              *x2,
+                                                      gint              *y2);
+
+static void      add_rectangle                       (const GimpVector2 *points,
+                                                      gint               n_points,
+                                                      Rectangle         *r,
+                                                      GimpVector2        a,
+                                                      GimpVector2        b,
+                                                      GimpVector2        c,
+                                                      GimpVector2        d);
+static gboolean  intersect                           (GimpVector2        a,
+                                                      GimpVector2        b,
+                                                      GimpVector2        c,
+                                                      GimpVector2        d,
+                                                      GimpVector2       *i);
+static gboolean  intersect_x                         (GimpVector2        a,
+                                                      GimpVector2        b,
+                                                      GimpVector2        c,
+                                                      GimpVector2       *i);
+static gboolean  intersect_y                         (GimpVector2        a,
+                                                      GimpVector2        b,
+                                                      GimpVector2        c,
+                                                      GimpVector2       *i);
+static gboolean  in_poly                             (const GimpVector2 *points,
+                                                      gint               n_points,
+                                                      GimpVector2        p);
+static gboolean  point_on_border                     (const GimpVector2 *points,
+                                                      gint               n_points,
+                                                      GimpVector2        p);
+
+static void      find_two_point_rectangle            (Rectangle         *r,
+                                                      const GimpVector2 *points,
+                                                      gint               n_points,
+                                                      gint               p);
+static void      find_three_point_rectangle_corner   (Rectangle         *r,
+                                                      const GimpVector2 *points,
+                                                      gint               n_points,
+                                                      gint               p);
+static void      find_three_point_rectangle          (Rectangle          *r,
+                                                      const GimpVector2 *points,
+                                                      gint               n_points,
+                                                      gint               p);
+static void      find_three_point_rectangle_triangle (Rectangle         *r,
+                                                      const GimpVector2 *points,
+                                                      gint               n_points,
+                                                      gint               p);
+static void      find_maximum_aspect_rectangle       (Rectangle          *r,
+                                                      const GimpVector2 *points,
+                                                      gint               n_points,
+                                                      gint               p);
 
 
 /*
@@ -136,8 +128,11 @@ gimp_transform_resize_boundary (const GimpMatrix3   *inv,
                                 gint                *x2,
                                 gint                *y2)
 {
-  gdouble dx1, dx2, dx3, dx4;
-  gdouble dy1, dy2, dy3, dy4;
+  GimpVector2 bounds[4];
+  GimpVector2 points[5];
+  gint        n_points;
+  gboolean    valid;
+  gint        i;
 
   g_return_if_fail (inv != NULL);
 
@@ -151,16 +146,21 @@ gimp_transform_resize_boundary (const GimpMatrix3   *inv,
   if (resize == GIMP_TRANSFORM_RESIZE_CLIP)
     return;
 
-  gimp_matrix3_transform_point (inv, u1, v1, &dx1, &dy1);
-  gimp_matrix3_transform_point (inv, u2, v1, &dx2, &dy2);
-  gimp_matrix3_transform_point (inv, u1, v2, &dx3, &dy3);
-  gimp_matrix3_transform_point (inv, u2, v2, &dx4, &dy4);
+  bounds[0] = (GimpVector2) { u1, v1 };
+  bounds[1] = (GimpVector2) { u2, v1 };
+  bounds[2] = (GimpVector2) { u2, v2 };
+  bounds[3] = (GimpVector2) { u1, v2 };
+
+  gimp_transform_polygon (inv, bounds, 4, TRUE,
+                          points, &n_points);
+
+  valid = (n_points >= 2);
 
   /*  check if the transformation matrix is valid at all  */
-  if (! FINITE (dx1) || ! FINITE (dy1) ||
-      ! FINITE (dx2) || ! FINITE (dy2) ||
-      ! FINITE (dx3) || ! FINITE (dy3) ||
-      ! FINITE (dx4) || ! FINITE (dy4))
+  for (i = 0; i < n_points && valid; i++)
+    valid = (FINITE (points[i].x) && FINITE (points[i].y));
+
+  if (! valid)
     {
       g_warning ("invalid transform matrix");
       /* since there is no sensible way to deal with this, just do the same as
@@ -174,18 +174,18 @@ gimp_transform_resize_boundary (const GimpMatrix3   *inv,
     case GIMP_TRANSFORM_RESIZE_ADJUST:
       /* return smallest rectangle (with sides parallel to x- and y-axis)
        * that surrounds the new points */
-      gimp_transform_resize_adjust (dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4,
+      gimp_transform_resize_adjust (points, n_points,
                                     x1, y1, x2, y2);
       break;
 
     case GIMP_TRANSFORM_RESIZE_CROP:
-      gimp_transform_resize_crop (dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4,
+      gimp_transform_resize_crop (points, n_points,
                                   0.0,
                                   x1, y1, x2, y2);
       break;
 
     case GIMP_TRANSFORM_RESIZE_CROP_WITH_ASPECT:
-      gimp_transform_resize_crop (dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4,
+      gimp_transform_resize_crop (points, n_points,
                                   ((gdouble) u2 - u1) / (v2 - v1),
                                   x1, y1, x2, y2);
       break;
@@ -209,56 +209,51 @@ gimp_transform_resize_boundary (const GimpMatrix3   *inv,
  * y-axis) that contains the points d1 to d4
  */
 static void
-gimp_transform_resize_adjust (gdouble  dx1,
-                              gdouble  dy1,
-                              gdouble  dx2,
-                              gdouble  dy2,
-                              gdouble  dx3,
-                              gdouble  dy3,
-                              gdouble  dx4,
-                              gdouble  dy4,
-                              gint    *x1,
-                              gint    *y1,
-                              gint    *x2,
-                              gint    *y2)
+gimp_transform_resize_adjust (const GimpVector2 *points,
+                              gint               n_points,
+                              gint              *x1,
+                              gint              *y1,
+                              gint              *x2,
+                              gint              *y2)
 {
-  *x1 = (gint) floor (MIN4 (dx1, dx2, dx3, dx4));
-  *y1 = (gint) floor (MIN4 (dy1, dy2, dy3, dy4));
+  GimpVector2 top_left;
+  GimpVector2 bottom_right;
+  gint        i;
+
+  top_left = bottom_right = points[0];
 
-  *x2 = (gint) ceil (MAX4 (dx1, dx2, dx3, dx4));
-  *y2 = (gint) ceil (MAX4 (dy1, dy2, dy3, dy4));
+  for (i = 1; i < n_points; i++)
+    {
+      top_left.x     = MIN (top_left.x,     points[i].x);
+      top_left.y     = MIN (top_left.y,     points[i].y);
+
+      bottom_right.x = MAX (bottom_right.x, points[i].x);
+      bottom_right.y = MAX (bottom_right.y, points[i].y);
+    }
+
+  *x1 = (gint) floor (top_left.x);
+  *y1 = (gint) floor (top_left.y);
+
+  *x2 = (gint) ceil (bottom_right.x);
+  *y2 = (gint) ceil (bottom_right.y);
 }
 
 static void
-gimp_transform_resize_crop (gdouble  dx1,
-                            gdouble  dy1,
-                            gdouble  dx2,
-                            gdouble  dy2,
-                            gdouble  dx3,
-                            gdouble  dy3,
-                            gdouble  dx4,
-                            gdouble  dy4,
-                            gdouble  aspect,
-                            gint    *x1,
-                            gint    *y1,
-                            gint    *x2,
-                            gint    *y2)
+gimp_transform_resize_crop (const GimpVector2 *orig_points,
+                            gint               n_points,
+                            gdouble            aspect,
+                            gint              *x1,
+                            gint              *y1,
+                            gint              *x2,
+                            gint              *y2)
 {
-  Point     points[4];
-  Rectangle r;
-  Point     t,a;
-  gint      i, j;
-  gint      min;
-
-  /*  fill in the points array  */
-  points[0].x = dx1;
-  points[0].y = dy1;
-  points[1].x = dx2;
-  points[1].y = dy2;
-  points[2].x = dx3;
-  points[2].y = dy3;
-  points[3].x = dx4;
-  points[3].y = dy4;
+  GimpVector2 points[5];
+  Rectangle   r;
+  GimpVector2 t,a;
+  gint        i, j;
+  gint        min;
+
+  memcpy (points, orig_points, sizeof (GimpVector2) * n_points);
 
   /* find lowest, rightmost corner of surrounding rectangle */
   a.x = 0;
@@ -273,7 +268,7 @@ gimp_transform_resize_crop (gdouble  dx1,
     }
 
   /* and translate all the points to the first quadrant */
-  for (i = 0; i < 4; i++)
+  for (i = 0; i < n_points; i++)
     {
       points[i].x += (-a.x) * 2;
       points[i].y += (-a.y) * 2;
@@ -283,7 +278,7 @@ gimp_transform_resize_crop (gdouble  dx1,
    * in different orders due to gimp_matrix3_transform_point()
    */
   min = 0;
-  for (i = 0; i < 4; i++)
+  for (i = 0; i < n_points; i++)
     {
       if (points[i].y < points[min].y)
         min = i;
@@ -293,17 +288,17 @@ gimp_transform_resize_crop (gdouble  dx1,
   points[0] = points[min];
   points[min] = t;
 
-  for (i = 1; i < 3; i++)
+  for (i = 1; i < n_points - 1; i++)
     {
       gdouble min_theta;
       gdouble min_mag;
       int next;
 
-      next = 3;
+      next = n_points - 1;
       min_theta = 2.0 * G_PI;
       min_mag = DBL_MAX;
 
-      for (j = i; j < 4; j++)
+      for (j = i; j < n_points; j++)
         {
           gdouble theta;
           gdouble sy;
@@ -337,37 +332,36 @@ gimp_transform_resize_crop (gdouble  dx1,
     }
 
   /* reverse the order of points */
-  t = points[0];
-  points[0] = points[3];
-  points[3] = t;
-
-  t = points[1];
-  points[1] = points[2];
-  points[2] = t;
+  for (i = 0; i < n_points / 2; i++)
+    {
+      t                        = points[i];
+      points[i]                = points[n_points - i - 1];
+      points[n_points - i - 1] = t;
+    }
 
   r.a.x = r.a.y = r.b.x = r.b.y = r.c.x = r.c.y = r.d.x = r.d.y = r.area = 0;
   r.aspect = aspect;
 
   if (aspect != 0)
     {
-      for (i = 0; i < 4; i++)
-        find_maximum_aspect_rectangle (&r, points, i);
+      for (i = 0; i < n_points; i++)
+        find_maximum_aspect_rectangle (&r, points, n_points, i);
     }
   else
     {
-      for (i = 0; i < 4; i++)
+      for (i = 0; i < n_points; i++)
         {
-          find_three_point_rectangle          (&r, points, i);
-          find_three_point_rectangle_corner   (&r, points, i);
-          find_two_point_rectangle            (&r, points, i);
-          find_three_point_rectangle_triangle (&r, points, i);
+          find_three_point_rectangle          (&r, points, n_points, i);
+          find_three_point_rectangle_corner   (&r, points, n_points, i);
+          find_two_point_rectangle            (&r, points, n_points, i);
+          find_three_point_rectangle_triangle (&r, points, n_points, i);
         }
     }
 
   if (r.area == 0)
     {
       /* saveguard if something went wrong, adjust and give warning */
-      gimp_transform_resize_adjust (dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4,
+      gimp_transform_resize_adjust (orig_points, n_points,
                                     x1, y1, x2, y2);
       g_warning ("no rectangle found by algorithm, no cropping done");
       return;
@@ -389,83 +383,86 @@ gimp_transform_resize_crop (gdouble  dx1,
 }
 
 static void
-find_three_point_rectangle (Rectangle *r,
-                            Point      points[4],
-                            gint       p)
+find_three_point_rectangle (Rectangle         *r,
+                            const GimpVector2 *points,
+                            gint               n_points,
+                            gint               p)
 {
-  Point a = points[p       % 4];  /* 0 1 2 3 */
-  Point b = points[(p + 1) % 4];  /* 1 2 3 0 */
-  Point c = points[(p + 2) % 4];  /* 2 3 0 1 */
-  Point d = points[(p + 3) % 4];  /* 3 0 1 2 */
-  Point i1;                       /* intersection point */
-  Point i2;                       /* intersection point */
-  Point i3;                       /* intersection point */
+  GimpVector2 a = points[p       % n_points];  /* 0 1 2 3 */
+  GimpVector2 b = points[(p + 1) % n_points];  /* 1 2 3 0 */
+  GimpVector2 c = points[(p + 2) % n_points];  /* 2 3 0 1 */
+  GimpVector2 d = points[(p + 3) % n_points];  /* 3 0 1 2 */
+  GimpVector2 i1;                              /* intersection point */
+  GimpVector2 i2;                              /* intersection point */
+  GimpVector2 i3;                              /* intersection point */
 
   if (intersect_x (b, c, a,  &i1) &&
       intersect_y (c, d, i1, &i2) &&
       intersect_x (d, a, i2, &i3))
-    add_rectangle (points, r, i3, i3, i1, i1);
+    add_rectangle (points, n_points, r, i3, i3, i1, i1);
 
   if (intersect_y (b, c, a,  &i1) &&
       intersect_x (c, d, i1, &i2) &&
       intersect_y (d, a, i2, &i3))
-    add_rectangle (points, r, i3, i3, i1, i1);
+    add_rectangle (points, n_points, r, i3, i3, i1, i1);
 
   if (intersect_x (d, c, a,  &i1) &&
       intersect_y (c, b, i1, &i2) &&
       intersect_x (b, a, i2, &i3))
-    add_rectangle (points, r, i3, i3, i1, i1);
+    add_rectangle (points, n_points, r, i3, i3, i1, i1);
 
   if (intersect_y (d, c, a,  &i1) &&
       intersect_x (c, b, i1, &i2) &&
       intersect_y (b, a, i2, &i3))
-    add_rectangle (points, r, i3, i3, i1, i1);
+    add_rectangle (points, n_points, r, i3, i3, i1, i1);
 }
 
 static void
-find_three_point_rectangle_corner (Rectangle *r,
-                                   Point      points[4],
-                                   gint       p)
+find_three_point_rectangle_corner (Rectangle         *r,
+                                   const GimpVector2 *points,
+                                   gint               n_points,
+                                   gint               p)
 {
-  Point a = points[p       % 4];  /* 0 1 2 3 */
-  Point b = points[(p + 1) % 4];  /* 1 2 3 0 */
-  Point c = points[(p + 2) % 4];  /* 2 3 0 2 */
-  Point d = points[(p + 3) % 4];  /* 3 0 2 1 */
-  Point i1;                       /* intersection point */
-  Point i2;                       /* intersection point */
+  GimpVector2 a = points[p       % n_points];  /* 0 1 2 3 */
+  GimpVector2 b = points[(p + 1) % n_points];  /* 1 2 3 0 */
+  GimpVector2 c = points[(p + 2) % n_points];  /* 2 3 0 2 */
+  GimpVector2 d = points[(p + 3) % n_points];  /* 3 0 2 1 */
+  GimpVector2 i1;                              /* intersection point */
+  GimpVector2 i2;                              /* intersection point */
 
   if (intersect_x (b, c, a , &i1) &&
       intersect_y (c, d, i1, &i2))
-    add_rectangle (points, r, a, a, i1, i2);
+    add_rectangle (points, n_points, r, a, a, i1, i2);
 
   if (intersect_y (b, c, a , &i1) &&
       intersect_x (c, d, i1, &i2))
-    add_rectangle (points, r, a, a, i1, i2);
+    add_rectangle (points, n_points, r, a, a, i1, i2);
 
   if (intersect_x (c, d, a , &i1) &&
       intersect_y (b, c, i1, &i2))
-    add_rectangle (points, r, a, a, i1, i2);
+    add_rectangle (points, n_points, r, a, a, i1, i2);
 
   if (intersect_y (c, d, a , &i1) &&
       intersect_x (b, c, i1, &i2))
-    add_rectangle (points, r, a, a, i1, i2);
+    add_rectangle (points, n_points, r, a, a, i1, i2);
 }
 
 static void
-find_two_point_rectangle (Rectangle *r,
-                          Point      points[4],
-                          gint       p)
+find_two_point_rectangle (Rectangle         *r,
+                          const GimpVector2 *points,
+                          gint               n_points,
+                          gint               p)
 {
-  Point a = points[ p      % 4];  /* 0 1 2 3 */
-  Point b = points[(p + 1) % 4];  /* 1 2 3 0 */
-  Point c = points[(p + 2) % 4];  /* 2 3 0 1 */
-  Point d = points[(p + 3) % 4];  /* 3 0 1 2 */
-  Point i1;                       /* intersection point */
-  Point i2;                       /* intersection point */
-  Point mid;                      /* Mid point */
+  GimpVector2 a = points[ p      % n_points];  /* 0 1 2 3 */
+  GimpVector2 b = points[(p + 1) % n_points];  /* 1 2 3 0 */
+  GimpVector2 c = points[(p + 2) % n_points];  /* 2 3 0 1 */
+  GimpVector2 d = points[(p + 3) % n_points];  /* 3 0 1 2 */
+  GimpVector2 i1;                              /* intersection point */
+  GimpVector2 i2;                              /* intersection point */
+  GimpVector2 mid;                             /* Mid point */
 
-  add_rectangle (points, r, a, a, c, c);
-  add_rectangle (points, r, b, b, d, d);
+  add_rectangle (points, n_points, r, a, a, c, c);
+  add_rectangle (points, n_points, r, b, b, d, d);
 
   if (intersect_x (c, b, a, &i1) &&
       intersect_y (c, b, a, &i2))
@@ -473,55 +470,57 @@ find_two_point_rectangle (Rectangle *r,
       mid.x = ( i1.x + i2.x ) / 2.0;
       mid.y = ( i1.y + i2.y ) / 2.0;
 
-      add_rectangle (points, r, a, a, mid, mid);
+      add_rectangle (points, n_points, r, a, a, mid, mid);
     }
 }
 
 static void
-find_three_point_rectangle_triangle (Rectangle *r,
-                                     Point      points[4],
-                                     gint       p)
+find_three_point_rectangle_triangle (Rectangle         *r,
+                                     const GimpVector2 *points,
+                                     gint               n_points,
+                                     gint               p)
 {
-  Point a = points[p % 4];        /* 0 1 2 3 */
-  Point b = points[(p + 1) % 4];  /* 1 2 3 0 */
-  Point c = points[(p + 2) % 4];  /* 2 3 0 1 */
-  Point d = points[(p + 3) % 4];  /* 3 0 1 2 */
-  Point i1;                       /* intersection point */
-  Point i2;                       /* intersection point */
-  Point mid;
+  GimpVector2 a = points[p       % n_points];  /* 0 1 2 3 */
+  GimpVector2 b = points[(p + 1) % n_points];  /* 1 2 3 0 */
+  GimpVector2 c = points[(p + 2) % n_points];  /* 2 3 0 1 */
+  GimpVector2 d = points[(p + 3) % n_points];  /* 3 0 1 2 */
+  GimpVector2 i1;                              /* intersection point */
+  GimpVector2 i2;                              /* intersection point */
+  GimpVector2 mid;
 
   mid.x = (a.x + b.x) / 2.0;
   mid.y = (a.y + b.y) / 2.0;
 
   if (intersect_x (b, c, mid, &i1) &&
       intersect_y (a, d, mid, &i2))
-    add_rectangle (points, r, mid, mid, i1, i2);
+    add_rectangle (points, n_points, r, mid, mid, i1, i2);
 
   if (intersect_y (b, c, mid, &i1) &&
       intersect_x (a, d, mid, &i2))
-    add_rectangle (points, r, mid, mid, i1, i2);
+    add_rectangle (points, n_points, r, mid, mid, i1, i2);
 
   if (intersect_x (a, d, mid, &i1) &&
       intersect_y (b, c, mid, &i2))
-    add_rectangle (points, r, mid, mid, i1, i2);
+    add_rectangle (points, n_points, r, mid, mid, i1, i2);
 
   if (intersect_y (a, d, mid, &i1) &&
       intersect_x (b, c, mid, &i2))
-    add_rectangle (points, r, mid, mid, i1, i2);
+    add_rectangle (points, n_points, r, mid, mid, i1, i2);
 }
 
 static void
-find_maximum_aspect_rectangle (Rectangle *r,
-                               Point      points[4],
-                               gint       p)
+find_maximum_aspect_rectangle (Rectangle         *r,
+                               const GimpVector2 *points,
+                               gint               n_points,
+                               gint               p)
 {
-  Point a = points[ p      % 4];  /* 0 1 2 3 */
-  Point b = points[(p + 1) % 4];  /* 1 2 3 0 */
-  Point c = points[(p + 2) % 4];  /* 2 3 0 1 */
-  Point d = points[(p + 3) % 4];  /* 3 0 1 2 */
-  Point i1;                       /* intersection point */
-  Point i2;                       /* intersection point */
-  Point i3;                       /* intersection point */
+  GimpVector2 a = points[ p      % n_points];  /* 0 1 2 3 */
+  GimpVector2 b = points[(p + 1) % n_points];  /* 1 2 3 0 */
+  GimpVector2 c = points[(p + 2) % n_points];  /* 2 3 0 1 */
+  GimpVector2 d = points[(p + 3) % n_points];  /* 3 0 1 2 */
+  GimpVector2 i1;                              /* intersection point */
+  GimpVector2 i2;                              /* intersection point */
+  GimpVector2 i3;                              /* intersection point */
 
   if (intersect_x (b, c, a, &i1))
     {
@@ -529,25 +528,25 @@ find_maximum_aspect_rectangle (Rectangle *r,
       i2.y = i1.y + 1.0;
 
       if (intersect (d, a, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       if (intersect (a, b, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       if (intersect (c, d, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       i2.x = i1.x - 1.0 * r->aspect;
       i2.y = i1.y + 1.0;
 
       if (intersect (d, a, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       if (intersect (a, b, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       if (intersect (c, d, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
     }
 
   if (intersect_y (b, c, a, &i1))
@@ -556,25 +555,25 @@ find_maximum_aspect_rectangle (Rectangle *r,
       i2.y = i1.y + 1.0;
 
       if (intersect (d, a, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       if (intersect (a, b, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       if (intersect (c, d, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       i2.x = i1.x - 1.0 * r->aspect;
       i2.y = i1.y + 1.0;
 
       if (intersect (d, a, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       if (intersect (a, b, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       if (intersect (c, d, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
     }
 
   if (intersect_x (c, d, a,  &i1))
@@ -583,25 +582,25 @@ find_maximum_aspect_rectangle (Rectangle *r,
       i2.y = i1.y + 1.0;
 
       if (intersect (d, a, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       if (intersect (a, b, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       if (intersect (b, c, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       i2.x = i1.x - 1.0 * r->aspect;
       i2.y = i1.y + 1.0;
 
       if (intersect (d, a, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       if (intersect (a, b, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       if (intersect (b, c, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
     }
 
   if (intersect_y (c, d, a,  &i1))
@@ -610,25 +609,25 @@ find_maximum_aspect_rectangle (Rectangle *r,
       i2.y = i1.y + 1.0;
 
       if (intersect (d, a, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       if (intersect (a, b, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       if (intersect (b, c, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       i2.x = i1.x - 1.0 * r->aspect;
       i2.y = i1.y + 1.0;
 
       if (intersect (d, a, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       if (intersect (a, b, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
 
       if (intersect (b, c, i1, i2, &i3))
-        add_rectangle (points, r, i1, i3, i1, i3);
+        add_rectangle (points, n_points, r, i1, i3, i1, i3);
     }
 }
 
@@ -636,18 +635,19 @@ find_maximum_aspect_rectangle (Rectangle *r,
  * its still inside.
  */
 static gboolean
-in_poly (Point points[4],
-         Point p)
+in_poly (const GimpVector2 *points,
+         gint               n_points,
+         GimpVector2        p)
 {
-  Point p1, p2;
+  GimpVector2 p1, p2;
   gint  counter = 0;
   gint  i;
 
   p1 = points[0];
 
-  for (i = 1; i <= 4; i++)
+  for (i = 1; i <= n_points; i++)
     {
-      p2 = points[i % 4];
+      p2 = points[i % n_points];
 
       if (p.y > MIN (p1.y, p2.y))
         {
@@ -671,7 +671,7 @@ in_poly (Point points[4],
     }
 
   /* border check */
-  if (point_on_border (points, p))
+  if (point_on_border (points, n_points, p))
     return TRUE;
 
   return (counter % 2 != 0);
@@ -680,15 +680,16 @@ in_poly (Point points[4],
 /* check if the point p lies on the polygon "points"
  */
 static gboolean
-point_on_border (Point points[4],
-                 Point p)
+point_on_border (const GimpVector2 *points,
+                 gint               n_points,
+                 GimpVector2        p)
 {
   gint i;
 
-  for (i = 0; i <= 4; i++)
+  for (i = 0; i <= n_points; i++)
     {
-      Point   a  = points[i % 4];
-      Point   b  = points[(i + 1) % 4];
+      GimpVector2   a  = points[i       % n_points];
+      GimpVector2   b  = points[(i + 1) % n_points];
       gdouble a1 = (b.y - a.y);
       gdouble b1 = (a.x - b.x);
       gdouble c1 = a1 * a.x + b1 * a.y;
@@ -709,11 +710,11 @@ point_on_border (Point points[4],
  * and write it to i, if existing.
  */
 static gboolean
-intersect (Point  a,
-           Point  b,
-           Point  c,
-           Point  d,
-           Point *i)
+intersect (GimpVector2  a,
+           GimpVector2  b,
+           GimpVector2  c,
+           GimpVector2  d,
+           GimpVector2 *i)
 {
   gdouble a1  = (b.y - a.y);
   gdouble b1  = (a.x - b.x);
@@ -737,12 +738,12 @@ intersect (Point  a,
  * through c and write it to i, if existing.
  */
 static gboolean
-intersect_x (Point  a,
-             Point  b,
-             Point  c,
-             Point *i)
+intersect_x (GimpVector2  a,
+             GimpVector2  b,
+             GimpVector2  c,
+             GimpVector2 *i)
 {
-  Point   d = c;
+  GimpVector2   d = c;
   d.y += 1;
 
   return intersect(a,b,c,d,i);
@@ -752,12 +753,12 @@ intersect_x (Point  a,
  * through c and write it to i, if existing.
  */
 static gboolean
-intersect_y (Point  a,
-             Point  b,
-             Point  c,
-             Point *i)
+intersect_y (GimpVector2  a,
+             GimpVector2  b,
+             GimpVector2  c,
+             GimpVector2 *i)
 {
-  Point   d = c;
+  GimpVector2   d = c;
   d.x += 1;
 
   return intersect(a,b,c,d,i);
@@ -769,12 +770,13 @@ intersect_y (Point  a,
  * writes it to r if the area is bigger than the rectangle already stored in r.
  */
 static void
-add_rectangle (Point      points[4],
-               Rectangle *r,
-               Point      a,
-               Point      b,
-               Point      c,
-               Point      d)
+add_rectangle (const GimpVector2 *points,
+               gint               n_points,
+               Rectangle         *r,
+               GimpVector2        a,
+               GimpVector2        b,
+               GimpVector2        c,
+               GimpVector2        d)
 {
   gdouble width;
   gdouble height;
@@ -805,10 +807,10 @@ add_rectangle (Point      points[4],
   height =  maxy - miny;
 
   /* check if this rectangle is inside the polygon "points" */
-  if (in_poly (points, a) &&
-      in_poly (points, b) &&
-      in_poly (points, c) &&
-      in_poly (points, d))
+  if (in_poly (points, n_points, a) &&
+      in_poly (points, n_points, b) &&
+      in_poly (points, n_points, c) &&
+      in_poly (points, n_points, d))
     {
       gdouble area = width * height;
 
diff --git a/app/core/gimpdrawable-transform.c b/app/core/gimpdrawable-transform.c
index d613ca1..5436868 100644
--- a/app/core/gimpdrawable-transform.c
+++ b/app/core/gimpdrawable-transform.c
@@ -116,9 +116,6 @@ gimp_drawable_transform_buffer_affine (GimpDrawable           *drawable,
       ! babl_format_has_alpha (gegl_buffer_get_format (orig_buffer)))
     clip_result = GIMP_TRANSFORM_RESIZE_CLIP;
 
-  if (gimp_matrix3_will_explode (&m, u1, v1, u2, v2))
-    clip_result = GIMP_TRANSFORM_RESIZE_CLIP;
-
   /*  Find the bounding coordinates of target */
   gimp_transform_resize_boundary (&m, clip_result,
                                   u1, v1, u2, v2,
@@ -136,7 +133,6 @@ gimp_drawable_transform_buffer_affine (GimpDrawable           *drawable,
   gimp_gegl_apply_transform (orig_buffer, progress, NULL,
                              new_buffer,
                              interpolation_type,
-                             clip_result,
                              &gegl_matrix);
 
   *new_offset_x = x1;
diff --git a/app/gegl/gimp-gegl-apply-operation.c b/app/gegl/gimp-gegl-apply-operation.c
index 48c283d..ba85e78 100644
--- a/app/gegl/gimp-gegl-apply-operation.c
+++ b/app/gegl/gimp-gegl-apply-operation.c
@@ -697,22 +697,17 @@ gimp_gegl_apply_transform (GeglBuffer            *src_buffer,
                            const gchar           *undo_desc,
                            GeglBuffer            *dest_buffer,
                            GimpInterpolationType  interpolation_type,
-                           GimpTransformResize    clip_result,
                            GimpMatrix3           *transform)
 {
   GeglNode *node;
-  gboolean  clip_to_input;
 
   g_return_if_fail (GEGL_IS_BUFFER (src_buffer));
   g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
   g_return_if_fail (GEGL_IS_BUFFER (dest_buffer));
 
-  clip_to_input = (clip_result == GIMP_TRANSFORM_RESIZE_CLIP);
-
   node = gegl_node_new_child (NULL,
-                              "operation",     "gegl:transform",
-                              "sampler",       interpolation_type,
-                              "clip-to-input", clip_to_input,
+                              "operation", "gegl:transform",
+                              "sampler",   interpolation_type,
                               NULL);
 
   gimp_gegl_node_set_matrix (node, transform);
diff --git a/app/gegl/gimp-gegl-apply-operation.h b/app/gegl/gimp-gegl-apply-operation.h
index c65fe59..0ba40bb 100644
--- a/app/gegl/gimp-gegl-apply-operation.h
+++ b/app/gegl/gimp-gegl-apply-operation.h
@@ -154,7 +154,6 @@ void   gimp_gegl_apply_transform       (GeglBuffer             *src_buffer,
                                         const gchar            *undo_desc,
                                         GeglBuffer             *dest_buffer,
                                         GimpInterpolationType   interpolation_type,
-                                        GimpTransformResize     clip_result,
                                         GimpMatrix3            *transform);
 
 



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