keep the anchor points as an array of GimpVector2 instead of plain
2008-02-09 Michael Natterer <mitch@gimp.org> * app/core/gimpcurve.[ch]: keep the anchor points as an array of GimpVector2 instead of plain doubles. * app/gegl/gimpcurvesconfig.c * app/widgets/gimpcurveview.c: changed accordingly. svn path=/trunk/; revision=24842
This commit is contained in:

committed by
Michael Natterer

parent
437becc44a
commit
797309b220
@ -1,3 +1,11 @@
|
||||
2008-02-09 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/core/gimpcurve.[ch]: keep the anchor points as an array of
|
||||
GimpVector2 instead of plain doubles.
|
||||
|
||||
* app/gegl/gimpcurvesconfig.c
|
||||
* app/widgets/gimpcurveview.c: changed accordingly.
|
||||
|
||||
2008-02-09 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/widgets/gimpcurveview.c (gimp_curve_view_draw_point): cleanup.
|
||||
|
@ -335,14 +335,14 @@ gimp_curve_reset (GimpCurve *curve,
|
||||
|
||||
for (i = 0; i < GIMP_CURVE_NUM_POINTS; i++)
|
||||
{
|
||||
curve->points[i][0] = -1.0;
|
||||
curve->points[i][1] = -1.0;
|
||||
curve->points[i].x = -1.0;
|
||||
curve->points[i].y = -1.0;
|
||||
}
|
||||
|
||||
curve->points[0][0] = 0.0;
|
||||
curve->points[0][1] = 0.0;
|
||||
curve->points[GIMP_CURVE_NUM_POINTS - 1][0] = 1.0;
|
||||
curve->points[GIMP_CURVE_NUM_POINTS - 1][1] = 1.0;
|
||||
curve->points[0].x = 0.0;
|
||||
curve->points[0].y = 0.0;
|
||||
curve->points[GIMP_CURVE_NUM_POINTS - 1].x = 1.0;
|
||||
curve->points[GIMP_CURVE_NUM_POINTS - 1].y = 1.0;
|
||||
|
||||
g_object_freeze_notify (G_OBJECT (curve));
|
||||
|
||||
@ -380,8 +380,8 @@ gimp_curve_set_curve_type (GimpCurve *curve,
|
||||
{
|
||||
gint32 index = CLAMP0255 (i * 32);
|
||||
|
||||
curve->points[i * 2][0] = (gdouble) index / 255.0;
|
||||
curve->points[i * 2][1] = curve->curve[index];
|
||||
curve->points[i * 2].x = (gdouble) index / 255.0;
|
||||
curve->points[i * 2].y = curve->curve[index];
|
||||
}
|
||||
|
||||
g_object_notify (G_OBJECT (curve), "points");
|
||||
@ -417,12 +417,12 @@ gimp_curve_get_closest_point (GimpCurve *curve,
|
||||
|
||||
for (i = 0; i < GIMP_CURVE_NUM_POINTS; i++)
|
||||
{
|
||||
if (curve->points[i][0] >= 0.0)
|
||||
if (fabs (x - curve->points[i][0]) < distance)
|
||||
{
|
||||
distance = fabs (x - curve->points[i][0]);
|
||||
closest_point = i;
|
||||
}
|
||||
if (curve->points[i].x >= 0.0 &&
|
||||
fabs (x - curve->points[i].x) < distance)
|
||||
{
|
||||
distance = fabs (x - curve->points[i].x);
|
||||
closest_point = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (distance > MIN_DISTANCE)
|
||||
@ -444,8 +444,8 @@ gimp_curve_set_point (GimpCurve *curve,
|
||||
|
||||
g_object_freeze_notify (G_OBJECT (curve));
|
||||
|
||||
curve->points[point][0] = x;
|
||||
curve->points[point][1] = y;
|
||||
curve->points[point].x = x;
|
||||
curve->points[point].y = y;
|
||||
|
||||
g_object_notify (G_OBJECT (curve), "points");
|
||||
|
||||
@ -466,7 +466,7 @@ gimp_curve_move_point (GimpCurve *curve,
|
||||
|
||||
g_object_freeze_notify (G_OBJECT (curve));
|
||||
|
||||
curve->points[point][1] = y;
|
||||
curve->points[point].y = y;
|
||||
|
||||
g_object_notify (G_OBJECT (curve), "points");
|
||||
|
||||
@ -557,17 +557,17 @@ gimp_curve_calculate (GimpCurve *curve)
|
||||
/* cycle through the curves */
|
||||
num_pts = 0;
|
||||
for (i = 0; i < GIMP_CURVE_NUM_POINTS; i++)
|
||||
if (curve->points[i][0] >= 0.0)
|
||||
if (curve->points[i].x >= 0.0)
|
||||
points[num_pts++] = i;
|
||||
|
||||
/* Initialize boundary curve points */
|
||||
if (num_pts != 0)
|
||||
{
|
||||
for (i = 0; i < (gint) (curve->points[points[0]][0] * 255.999); i++)
|
||||
curve->curve[i] = curve->points[points[0]][1];
|
||||
for (i = 0; i < (gint) (curve->points[points[0]].x * 255.999); i++)
|
||||
curve->curve[i] = curve->points[points[0]].y;
|
||||
|
||||
for (i = (gint) (curve->points[points[num_pts - 1]][0] * 255.999); i < 256; i++)
|
||||
curve->curve[i] = curve->points[points[num_pts - 1]][1];
|
||||
for (i = (gint) (curve->points[points[num_pts - 1]].x * 255.999); i < 256; i++)
|
||||
curve->curve[i] = curve->points[points[num_pts - 1]].y;
|
||||
}
|
||||
|
||||
for (i = 0; i < num_pts - 1; i++)
|
||||
@ -583,8 +583,8 @@ gimp_curve_calculate (GimpCurve *curve)
|
||||
/* ensure that the control points are used exactly */
|
||||
for (i = 0; i < num_pts; i++)
|
||||
{
|
||||
gdouble x = curve->points[points[i]][0];
|
||||
gdouble y = curve->points[points[i]][1];
|
||||
gdouble x = curve->points[points[i]].x;
|
||||
gdouble y = curve->points[points[i]].y;
|
||||
|
||||
curve->curve[(gint) (x * 255.999)] = y;
|
||||
}
|
||||
@ -621,10 +621,10 @@ gimp_curve_plot (GimpCurve *curve,
|
||||
gdouble slope;
|
||||
|
||||
/* the outer control points for the bezier curve. */
|
||||
x0 = curve->points[p2][0];
|
||||
y0 = curve->points[p2][1];
|
||||
x3 = curve->points[p3][0];
|
||||
y3 = curve->points[p3][1];
|
||||
x0 = curve->points[p2].x;
|
||||
y0 = curve->points[p2].y;
|
||||
x3 = curve->points[p3].x;
|
||||
y3 = curve->points[p3].y;
|
||||
|
||||
/*
|
||||
* the x values of the inner control points are fixed at
|
||||
@ -655,8 +655,8 @@ gimp_curve_plot (GimpCurve *curve,
|
||||
* the control handle of the right tangent, to ensure that the curve
|
||||
* does not have an inflection point.
|
||||
*/
|
||||
slope = (curve->points[p4][1] - y0) /
|
||||
(curve->points[p4][0] - x0);
|
||||
slope = (curve->points[p4].y - y0) /
|
||||
(curve->points[p4].x - x0);
|
||||
|
||||
y2 = y3 - slope * dx / 3.0;
|
||||
y1 = y0 + (y2 - y0) / 2.0;
|
||||
@ -664,8 +664,8 @@ gimp_curve_plot (GimpCurve *curve,
|
||||
else if (p1 != p2 && p3 == p4)
|
||||
{
|
||||
/* see previous case */
|
||||
slope = (y3 - curve->points[p1][1]) /
|
||||
(x3 - curve->points[p1][0]);
|
||||
slope = (y3 - curve->points[p1].y) /
|
||||
(x3 - curve->points[p1].x);
|
||||
|
||||
y1 = y0 + slope * dx / 3.0;
|
||||
y2 = y3 + (y1 - y3) / 2.0;
|
||||
@ -676,13 +676,13 @@ gimp_curve_plot (GimpCurve *curve,
|
||||
* parallel to the line between the opposite endpoint and the adjacent
|
||||
* neighbor.
|
||||
*/
|
||||
slope = (y3 - curve->points[p1][1]) /
|
||||
(x3 - curve->points[p1][0]);
|
||||
slope = (y3 - curve->points[p1].y) /
|
||||
(x3 - curve->points[p1].x);
|
||||
|
||||
y1 = y0 + slope * dx / 3.0;
|
||||
|
||||
slope = (curve->points[p4][1] - y0) /
|
||||
(curve->points[p4][0] - x0);
|
||||
slope = (curve->points[p4].y - y0) /
|
||||
(curve->points[p4].x - x0);
|
||||
|
||||
y2 = y3 - slope * dx / 3.0;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
|
||||
#include "gimpdata.h"
|
||||
#include "libgimpmath/gimpvector.h"
|
||||
|
||||
|
||||
#define GIMP_CURVE_NUM_POINTS 17 /* TODO: get rid of this limit */
|
||||
@ -42,7 +43,7 @@ struct _GimpCurve
|
||||
|
||||
GimpCurveType curve_type;
|
||||
|
||||
gdouble points[GIMP_CURVE_NUM_POINTS][2];
|
||||
GimpVector2 points[GIMP_CURVE_NUM_POINTS];
|
||||
gdouble curve[256];
|
||||
};
|
||||
|
||||
|
@ -411,15 +411,15 @@ gimp_curves_config_save_cruft (GimpCurvesConfig *config,
|
||||
{
|
||||
gint32 index = CLAMP0255 (j * 32);
|
||||
|
||||
curve->points[j * 2][0] = (gdouble) index / 255.0;
|
||||
curve->points[j * 2][1] = curve->curve[index];
|
||||
curve->points[j * 2].x = (gdouble) index / 255.0;
|
||||
curve->points[j * 2].y = curve->curve[index];
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < GIMP_CURVE_NUM_POINTS; j++)
|
||||
fprintf (file, "%d %d ",
|
||||
(gint) (curve->points[j][0] * 255.999),
|
||||
(gint) (curve->points[j][1] * 255.999));
|
||||
(gint) (curve->points[j].x * 255.999),
|
||||
(gint) (curve->points[j].y * 255.999));
|
||||
|
||||
fprintf (file, "\n");
|
||||
}
|
||||
|
@ -315,8 +315,8 @@ gimp_curve_view_draw_point (GimpCurveView *view,
|
||||
{
|
||||
gdouble x, y;
|
||||
|
||||
x = view->curve->points[i][0];
|
||||
y = 1.0 - view->curve->points[i][1];
|
||||
x = view->curve->points[i].x;
|
||||
y = 1.0 - view->curve->points[i].y;
|
||||
|
||||
if (x < 0.0)
|
||||
return;
|
||||
@ -553,17 +553,17 @@ gimp_curve_view_button_press (GtkWidget *widget,
|
||||
/* determine the leftmost and rightmost points */
|
||||
view->leftmost = -1.0;
|
||||
for (i = closest_point - 1; i >= 0; i--)
|
||||
if (curve->points[i][0] >= 0.0)
|
||||
if (curve->points[i].x >= 0.0)
|
||||
{
|
||||
view->leftmost = curve->points[i][0];
|
||||
view->leftmost = curve->points[i].x;
|
||||
break;
|
||||
}
|
||||
|
||||
view->rightmost = 2.0;
|
||||
for (i = closest_point + 1; i < GIMP_CURVE_NUM_POINTS; i++)
|
||||
if (curve->points[i][0] >= 0.0)
|
||||
if (curve->points[i].x >= 0.0)
|
||||
{
|
||||
view->rightmost = curve->points[i][0];
|
||||
view->rightmost = curve->points[i].x;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -635,7 +635,7 @@ gimp_curve_view_motion_notify (GtkWidget *widget,
|
||||
case GIMP_CURVE_SMOOTH:
|
||||
if (! view->grabbed) /* If no point is grabbed... */
|
||||
{
|
||||
if (curve->points[closest_point][0] >= 0.0)
|
||||
if (curve->points[closest_point].x >= 0.0)
|
||||
new_cursor = GDK_FLEUR;
|
||||
else
|
||||
new_cursor = GDK_TCROSS;
|
||||
@ -651,7 +651,7 @@ gimp_curve_view_motion_notify (GtkWidget *widget,
|
||||
if (x > view->leftmost && x < view->rightmost)
|
||||
{
|
||||
closest_point = ((gint) (x * 255.999) + 8) / 16;
|
||||
if (curve->points[closest_point][0] < 0.0)
|
||||
if (curve->points[closest_point].x < 0.0)
|
||||
gimp_curve_view_set_selected (view, closest_point);
|
||||
|
||||
gimp_curve_set_point (curve, view->selected, x, 1.0 - y);
|
||||
@ -737,7 +737,7 @@ gimp_curve_view_key_press (GtkWidget *widget,
|
||||
GimpCurveView *view = GIMP_CURVE_VIEW (widget);
|
||||
GimpCurve *curve = view->curve;
|
||||
gint i = view->selected;
|
||||
gdouble y = curve->points[i][1];
|
||||
gdouble y = curve->points[i].y;
|
||||
gboolean retval = FALSE;
|
||||
|
||||
if (view->grabbed || ! curve ||
|
||||
@ -749,7 +749,7 @@ gimp_curve_view_key_press (GtkWidget *widget,
|
||||
case GDK_Left:
|
||||
for (i = i - 1; i >= 0 && ! retval; i--)
|
||||
{
|
||||
if (curve->points[i][0] >= 0.0)
|
||||
if (curve->points[i].x >= 0.0)
|
||||
{
|
||||
gimp_curve_view_set_selected (view, i);
|
||||
|
||||
@ -761,7 +761,7 @@ gimp_curve_view_key_press (GtkWidget *widget,
|
||||
case GDK_Right:
|
||||
for (i = i + 1; i < GIMP_CURVE_NUM_POINTS && ! retval; i++)
|
||||
{
|
||||
if (curve->points[i][0] >= 0.0)
|
||||
if (curve->points[i].x >= 0.0)
|
||||
{
|
||||
gimp_curve_view_set_selected (view, i);
|
||||
|
||||
|
Reference in New Issue
Block a user