2003-10-19 17:44:46 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This is a plug-in for the GIMP.
|
|
|
|
*
|
|
|
|
* Generates images containing vector type drawings.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1997 Andy Thomas alt@picnic.demon.co.uk
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
2004-10-27 14:43:52 +08:00
|
|
|
*
|
2003-10-19 17:44:46 +08:00
|
|
|
*/
|
|
|
|
|
2003-10-24 21:28:46 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
|
|
|
|
#include "gfig.h"
|
2004-07-08 01:52:16 +08:00
|
|
|
#include "gfig-dobject.h"
|
2003-10-24 21:28:46 +08:00
|
|
|
#include "gfig-line.h"
|
|
|
|
|
|
|
|
#include "libgimp/stdplugins-intl.h"
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2004-10-29 05:09:33 +08:00
|
|
|
/* Distance between two points. */
|
2003-10-19 17:44:46 +08:00
|
|
|
static gdouble
|
|
|
|
dist (gdouble x1,
|
|
|
|
gdouble y1,
|
|
|
|
gdouble x2,
|
|
|
|
gdouble y2)
|
|
|
|
{
|
|
|
|
|
|
|
|
double s1 = x1 - x2;
|
|
|
|
double s2 = y1 - y2;
|
|
|
|
|
|
|
|
return sqrt (s1 * s1 + s2 * s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mid point of line returned */
|
|
|
|
static void
|
|
|
|
mid_point (gdouble x1,
|
2004-07-05 04:50:25 +08:00
|
|
|
gdouble y1,
|
|
|
|
gdouble x2,
|
|
|
|
gdouble y2,
|
|
|
|
gdouble *mx,
|
|
|
|
gdouble *my)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
2003-10-20 05:03:21 +08:00
|
|
|
*mx = (x1 + x2) / 2.0;
|
|
|
|
*my = (y1 + y2) / 2.0;
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Careful about infinite grads */
|
|
|
|
static gdouble
|
|
|
|
line_grad (gdouble x1,
|
2004-07-05 04:50:25 +08:00
|
|
|
gdouble y1,
|
|
|
|
gdouble x2,
|
|
|
|
gdouble y2)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
|
|
|
double dx, dy;
|
2004-10-26 06:02:32 +08:00
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
dx = x1 - x2;
|
|
|
|
dy = y1 - y2;
|
|
|
|
|
|
|
|
return (dx == 0.0) ? 0.0 : dy / dx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Constant of line that goes through x, y with grad lgrad */
|
|
|
|
static gdouble
|
|
|
|
line_cons (gdouble x,
|
2004-07-05 04:50:25 +08:00
|
|
|
gdouble y,
|
|
|
|
gdouble lgrad)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
|
|
|
return y - lgrad * x;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Get grad & const for perpend. line to given points */
|
|
|
|
static void
|
|
|
|
line_definition (gdouble x1,
|
2004-07-05 04:50:25 +08:00
|
|
|
gdouble y1,
|
|
|
|
gdouble x2,
|
|
|
|
gdouble y2,
|
|
|
|
gdouble *lgrad,
|
|
|
|
gdouble *lconst)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
|
|
|
double grad1;
|
|
|
|
double midx, midy;
|
|
|
|
|
|
|
|
grad1 = line_grad (x1, y1, x2, y2);
|
|
|
|
|
|
|
|
if (grad1 == 0.0)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf ("Infinite grad....\n");
|
|
|
|
#endif /* DEBUG */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mid_point (x1, y1, x2, y2, &midx, &midy);
|
|
|
|
|
|
|
|
/* Invert grad for perpen gradient */
|
|
|
|
|
2004-10-29 05:09:33 +08:00
|
|
|
*lgrad = -1.0 / grad1;
|
2004-10-26 06:02:32 +08:00
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
*lconst = line_cons (midx, midy,*lgrad);
|
|
|
|
}
|
|
|
|
|
2004-10-27 14:43:52 +08:00
|
|
|
/* Arch details
|
|
|
|
* Given three points get arc radius and the co-ords
|
2003-10-19 17:44:46 +08:00
|
|
|
* of center point.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
arc_details (GdkPoint *vert_a,
|
2004-07-05 04:50:25 +08:00
|
|
|
GdkPoint *vert_b,
|
|
|
|
GdkPoint *vert_c,
|
|
|
|
GdkPoint *center_pnt,
|
|
|
|
gdouble *radius)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
|
|
|
/* Only vertices are in whole numbers - everything else is in doubles */
|
|
|
|
double ax, ay;
|
|
|
|
double bx, by;
|
|
|
|
double cx, cy;
|
|
|
|
|
|
|
|
double len_a, len_b, len_c;
|
|
|
|
double sum_sides2;
|
|
|
|
double area;
|
|
|
|
double circumcircle_R;
|
|
|
|
double line1_grad, line1_const;
|
|
|
|
double line2_grad, line2_const;
|
2004-10-29 05:09:33 +08:00
|
|
|
double inter_x = 0.0, inter_y = 0.0;
|
|
|
|
int got_x = 0, got_y = 0;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
ax = (double) (vert_a->x);
|
|
|
|
ay = (double) (vert_a->y);
|
|
|
|
bx = (double) (vert_b->x);
|
|
|
|
by = (double) (vert_b->y);
|
|
|
|
cx = (double) (vert_c->x);
|
|
|
|
cy = (double) (vert_c->y);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf ("Vertices (%f,%f), (%f,%f), (%f,%f)\n", ax, ay, bx, by, cx, cy);
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
len_a = dist (ax, ay, bx, by);
|
|
|
|
len_b = dist (bx, by, cx, cy);
|
|
|
|
len_c = dist (cx, cy, ax, ay);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf ("len_a = %f, len_b = %f, len_c = %f\n", len_a, len_b, len_c);
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
sum_sides2 = (fabs (len_a) + fabs (len_b) + fabs (len_c))/2;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf ("Sum sides / 2 = %f\n", sum_sides2);
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
/* Area */
|
|
|
|
area = sqrt (sum_sides2*(sum_sides2 - len_a)*(sum_sides2 - len_b)*(sum_sides2 - len_c));
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf ("Area of triangle = %f\n", area);
|
|
|
|
#endif /* DEBUG */
|
2004-10-26 06:02:32 +08:00
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
/* Circumcircle */
|
|
|
|
circumcircle_R = len_a*len_b*len_c/(4*area);
|
|
|
|
*radius = circumcircle_R;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf ("Circumcircle radius = %f\n", circumcircle_R);
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
|
|
/* Deal with exceptions - I hate exceptions */
|
|
|
|
|
|
|
|
if (ax == bx || ax == cx || cx == bx)
|
|
|
|
{
|
|
|
|
/* vert line -> mid point gives inter_x */
|
|
|
|
if (ax == bx && bx == cx)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
/* Straight line */
|
|
|
|
double miny = ay;
|
|
|
|
double maxy = ay;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
if (by > maxy)
|
|
|
|
maxy = by;
|
2004-10-26 06:02:32 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
if (by < miny)
|
|
|
|
miny = by;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
if (cy > maxy)
|
|
|
|
maxy = cy;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
if (cy < miny)
|
|
|
|
miny = cy;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
inter_y = (maxy - miny)/2 + miny;
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
else if (ax == bx)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
inter_y = (ay - by)/2 + by;
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
else if (bx == cx)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
inter_y = (by - cy)/2 + cy;
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
else
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
inter_y = (cy - ay)/2 + ay;
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
got_y = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ay == by || by == cy || ay == cy)
|
|
|
|
{
|
|
|
|
/* Horz line -> midpoint gives inter_y */
|
|
|
|
if (ax == bx && bx == cx)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
/* Straight line */
|
|
|
|
double minx = ax;
|
|
|
|
double maxx = ax;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
if (bx > maxx)
|
|
|
|
maxx = bx;
|
2004-10-26 06:02:32 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
if (bx < minx)
|
|
|
|
minx = bx;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
if (cx > maxx)
|
|
|
|
maxx = cx;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
if (cx < minx)
|
|
|
|
minx = cx;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2004-07-05 04:50:25 +08:00
|
|
|
inter_x = (maxx - minx)/2 + minx;
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
else if (ay == by)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
inter_x = (ax - bx)/2 + bx;
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
else if (by == cy)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
inter_x = (bx - cx)/2 + cx;
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
else
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
inter_x = (cx - ax)/2 + ax;
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
got_x = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!got_x || !got_y)
|
|
|
|
{
|
|
|
|
/* At least two of the lines are not parallel to the axis */
|
|
|
|
/*first line */
|
|
|
|
if (ax != bx && ay != by)
|
2004-07-05 04:50:25 +08:00
|
|
|
line_definition (ax, ay, bx, by, &line1_grad, &line1_const);
|
2003-10-19 17:44:46 +08:00
|
|
|
else
|
2004-07-05 04:50:25 +08:00
|
|
|
line_definition (ax, ay, cx, cy, &line1_grad, &line1_const);
|
2003-10-19 17:44:46 +08:00
|
|
|
/* second line */
|
|
|
|
if (bx != cx && by != cy)
|
2004-07-05 04:50:25 +08:00
|
|
|
line_definition (bx, by, cx, cy, &line2_grad, &line2_const);
|
2003-10-19 17:44:46 +08:00
|
|
|
else
|
2004-07-05 04:50:25 +08:00
|
|
|
line_definition (ax, ay, cx, cy, &line2_grad, &line2_const);
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Intersection point */
|
|
|
|
|
|
|
|
if (!got_x)
|
|
|
|
inter_x = /*rint*/((line2_const - line1_const)/(line1_grad - line2_grad));
|
|
|
|
if (!got_y)
|
|
|
|
inter_y = /*rint*/((line1_grad * inter_x + line1_const));
|
|
|
|
|
2003-10-24 21:28:46 +08:00
|
|
|
center_pnt->x = (gint) inter_x;
|
|
|
|
center_pnt->y = (gint) inter_y;
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gdouble
|
|
|
|
arc_angle (GdkPoint *pnt,
|
2004-07-05 04:50:25 +08:00
|
|
|
GdkPoint *center)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
|
|
|
/* Get angle (in degress) of point given origin of center */
|
2004-10-29 05:09:33 +08:00
|
|
|
gint16 shift_x;
|
|
|
|
gint16 shift_y;
|
2003-10-19 17:44:46 +08:00
|
|
|
gdouble offset_angle;
|
|
|
|
|
2004-10-29 05:09:33 +08:00
|
|
|
shift_x = pnt->x - center->x;
|
2003-10-19 17:44:46 +08:00
|
|
|
shift_y = -pnt->y + center->y;
|
|
|
|
offset_angle = atan2 (shift_y, shift_x);
|
|
|
|
|
|
|
|
if (offset_angle < 0)
|
2004-10-29 05:09:33 +08:00
|
|
|
offset_angle += 2.0 * G_PI;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2003-10-20 05:03:21 +08:00
|
|
|
return offset_angle * 360 / (2*G_PI);
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-11-16 22:10:20 +08:00
|
|
|
arc_drawing_details (GfigObject *obj,
|
|
|
|
gdouble *minang,
|
|
|
|
GdkPoint *center_pnt,
|
|
|
|
gdouble *arcang,
|
|
|
|
gdouble *radius,
|
|
|
|
gint draw_cnts,
|
|
|
|
gint do_scale)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
2004-10-29 05:09:33 +08:00
|
|
|
DobjPoints *pnt1 = NULL;
|
|
|
|
DobjPoints *pnt2 = NULL;
|
|
|
|
DobjPoints *pnt3 = NULL;
|
|
|
|
DobjPoints dpnts[3];
|
|
|
|
gdouble ang1, ang2, ang3;
|
|
|
|
gdouble maxang;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
pnt1 = obj->points;
|
|
|
|
|
|
|
|
if (!pnt1)
|
|
|
|
return; /* Not fully drawn */
|
|
|
|
|
|
|
|
pnt2 = pnt1->next;
|
|
|
|
|
|
|
|
if (!pnt2)
|
|
|
|
return; /* Not fully drawn */
|
|
|
|
|
|
|
|
pnt3 = pnt2->next;
|
|
|
|
|
|
|
|
if (!pnt3)
|
|
|
|
return; /* Still not fully drawn */
|
|
|
|
|
|
|
|
if (draw_cnts)
|
|
|
|
{
|
|
|
|
draw_sqr (&pnt1->pnt);
|
|
|
|
draw_sqr (&pnt2->pnt);
|
|
|
|
draw_sqr (&pnt3->pnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_scale)
|
|
|
|
{
|
|
|
|
/* Adjust pnts for scaling */
|
|
|
|
/* Warning struct copies here! and casting to double <-> int */
|
|
|
|
/* Too complex fix me - to much hacking */
|
|
|
|
gdouble xy[2];
|
|
|
|
int j;
|
|
|
|
|
|
|
|
dpnts[0] = *pnt1;
|
|
|
|
dpnts[1] = *pnt2;
|
|
|
|
dpnts[2] = *pnt3;
|
|
|
|
|
|
|
|
pnt1 = &dpnts[0];
|
|
|
|
pnt2 = &dpnts[1];
|
|
|
|
pnt3 = &dpnts[2];
|
|
|
|
|
|
|
|
for (j = 0 ; j < 3; j++)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
xy[0] = dpnts[j].pnt.x;
|
|
|
|
xy[1] = dpnts[j].pnt.y;
|
|
|
|
if (selvals.scaletoimage)
|
|
|
|
scale_to_original_xy (&xy[0], 1);
|
|
|
|
else
|
|
|
|
scale_to_xy (&xy[0], 1);
|
|
|
|
dpnts[j].pnt.x = xy[0];
|
|
|
|
dpnts[j].pnt.y = xy[1];
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
arc_details (&pnt1->pnt, &pnt2->pnt, &pnt3->pnt, center_pnt, radius);
|
2004-10-26 06:02:32 +08:00
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
ang1 = arc_angle (&pnt1->pnt, center_pnt);
|
|
|
|
ang2 = arc_angle (&pnt2->pnt, center_pnt);
|
|
|
|
ang3 = arc_angle (&pnt3->pnt, center_pnt);
|
|
|
|
|
|
|
|
/* Find min/max angle */
|
|
|
|
|
|
|
|
maxang = ang1;
|
|
|
|
|
|
|
|
if (ang3 > maxang)
|
|
|
|
maxang = ang3;
|
2004-10-26 06:02:32 +08:00
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
*minang = ang1;
|
|
|
|
|
|
|
|
if (ang3 < *minang)
|
|
|
|
*minang = ang3;
|
|
|
|
|
|
|
|
if (ang2 > *minang && ang2 < maxang)
|
|
|
|
*arcang = maxang - *minang;
|
|
|
|
else
|
|
|
|
*arcang = maxang - *minang - 360;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-11-16 22:10:20 +08:00
|
|
|
d_draw_arc (GfigObject * obj)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
|
|
|
GdkPoint center_pnt;
|
2004-10-29 05:09:33 +08:00
|
|
|
gdouble radius, minang, arcang;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
g_assert (obj != NULL);
|
|
|
|
|
|
|
|
if (!obj)
|
|
|
|
return;
|
|
|
|
|
2004-10-29 05:09:33 +08:00
|
|
|
arc_drawing_details (obj, &minang, ¢er_pnt, &arcang, &radius,
|
|
|
|
TRUE, FALSE);
|
2003-10-24 21:28:46 +08:00
|
|
|
gfig_draw_arc (center_pnt.x, center_pnt.y, radius, radius, minang, arcang);
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-11-16 22:10:20 +08:00
|
|
|
d_paint_arc (GfigObject *obj)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
|
|
|
/* first point center */
|
|
|
|
/* Next point is radius */
|
|
|
|
gdouble *line_pnts;
|
2004-10-29 05:09:33 +08:00
|
|
|
gint seg_count = 0;
|
|
|
|
gint i = 0;
|
|
|
|
gdouble ang_grid;
|
|
|
|
gdouble ang_loop;
|
|
|
|
gdouble radius;
|
|
|
|
gint loop;
|
2003-10-19 17:44:46 +08:00
|
|
|
GdkPoint first_pnt, last_pnt;
|
2003-10-24 21:28:46 +08:00
|
|
|
gboolean first = TRUE;
|
2003-10-19 17:44:46 +08:00
|
|
|
GdkPoint center_pnt;
|
2004-10-29 05:09:33 +08:00
|
|
|
gdouble minang, arcang;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
g_assert (obj != NULL);
|
|
|
|
|
|
|
|
if (!obj)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* No cnt pnts & must scale */
|
|
|
|
arc_drawing_details (obj, &minang, ¢er_pnt, &arcang, &radius, FALSE, TRUE);
|
|
|
|
|
|
|
|
seg_count = 360; /* Should make a smoth-ish curve */
|
|
|
|
|
|
|
|
/* +3 because we MIGHT do pie selection */
|
|
|
|
line_pnts = g_new0 (gdouble, 2 * seg_count + 3);
|
|
|
|
|
|
|
|
/* Lines */
|
2004-10-29 05:09:33 +08:00
|
|
|
ang_grid = 2.0 * G_PI / 360.0;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
if (arcang < 0.0)
|
|
|
|
{
|
|
|
|
/* Swap - since we always draw anti-clock wise */
|
|
|
|
minang += arcang;
|
|
|
|
arcang = -arcang;
|
|
|
|
}
|
|
|
|
|
2004-10-29 05:09:33 +08:00
|
|
|
minang = minang * (2.0 * G_PI / 360.0); /* min ang is in degrees - need in rads*/
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
for (loop = 0 ; loop < abs ((gint)arcang) ; loop++)
|
|
|
|
{
|
2004-10-29 05:09:33 +08:00
|
|
|
gdouble lx, ly;
|
2003-10-19 17:44:46 +08:00
|
|
|
GdkPoint calc_pnt;
|
2004-10-26 06:02:32 +08:00
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
ang_loop = (gdouble)loop * ang_grid + minang;
|
|
|
|
|
2004-10-29 05:09:33 +08:00
|
|
|
lx = radius * cos (ang_loop);
|
2003-10-19 17:44:46 +08:00
|
|
|
ly = -radius * sin (ang_loop); /* y grows down screen and angs measured from x clockwise */
|
|
|
|
|
|
|
|
calc_pnt.x = RINT (lx + center_pnt.x);
|
|
|
|
calc_pnt.y = RINT (ly + center_pnt.y);
|
|
|
|
|
|
|
|
/* Miss out duped pnts */
|
|
|
|
if (!first)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
if (calc_pnt.x == last_pnt.x && calc_pnt.y == last_pnt.y)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
|
2003-10-24 21:28:46 +08:00
|
|
|
line_pnts[i++] = calc_pnt.x;
|
|
|
|
line_pnts[i++] = calc_pnt.y;
|
|
|
|
last_pnt = calc_pnt;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
if (first)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
first_pnt = calc_pnt;
|
|
|
|
first = FALSE;
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Reverse line if approp */
|
|
|
|
if (selvals.reverselines)
|
|
|
|
reverse_pairs_list (&line_pnts[0], i/2);
|
|
|
|
|
|
|
|
/* One go */
|
2004-11-17 06:45:35 +08:00
|
|
|
if (obj->style.paint_type == PAINT_BRUSH_TYPE)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
|
|
|
gfig_paint (selvals.brshtype,
|
2004-07-05 04:50:25 +08:00
|
|
|
gfig_context->drawable_id,
|
|
|
|
i, line_pnts);
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (line_pnts);
|
|
|
|
}
|
|
|
|
|
2004-11-16 22:10:20 +08:00
|
|
|
static GfigObject *
|
|
|
|
d_copy_arc (GfigObject *obj)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
2004-11-16 22:10:20 +08:00
|
|
|
GfigObject *nc;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
g_assert (obj->type == ARC);
|
|
|
|
|
2004-07-08 01:52:16 +08:00
|
|
|
nc = d_new_object (ARC, obj->points->pnt.x, obj->points->pnt.y);
|
2003-10-19 17:44:46 +08:00
|
|
|
nc->points->next = d_copy_dobjpoints (obj->points->next);
|
|
|
|
|
|
|
|
return nc;
|
|
|
|
}
|
|
|
|
|
2004-07-07 03:32:55 +08:00
|
|
|
void
|
2004-11-14 10:50:33 +08:00
|
|
|
d_arc_object_class_init (void)
|
2004-07-07 03:32:55 +08:00
|
|
|
{
|
2004-11-16 22:10:20 +08:00
|
|
|
GfigObjectClass *class = &dobj_class[ARC];
|
2004-07-07 03:32:55 +08:00
|
|
|
|
|
|
|
class->type = ARC;
|
|
|
|
class->name = "Arc";
|
|
|
|
class->drawfunc = d_draw_arc;
|
|
|
|
class->paintfunc = d_paint_arc;
|
|
|
|
class->copyfunc = d_copy_arc;
|
|
|
|
}
|
|
|
|
|
2003-10-19 17:44:46 +08:00
|
|
|
void
|
|
|
|
d_update_arc (GdkPoint *pnt)
|
|
|
|
{
|
2004-10-29 05:09:33 +08:00
|
|
|
DobjPoints *pnt1 = NULL;
|
|
|
|
DobjPoints *pnt2 = NULL;
|
|
|
|
DobjPoints *pnt3 = NULL;
|
2003-10-19 17:44:46 +08:00
|
|
|
|
|
|
|
/* First two points as line only become arch when third
|
|
|
|
* point is placed on canvas.
|
|
|
|
*/
|
|
|
|
|
|
|
|
pnt1 = obj_creating->points;
|
|
|
|
|
2004-10-29 05:09:33 +08:00
|
|
|
if (!pnt1 ||
|
|
|
|
!(pnt2 = pnt1->next) ||
|
|
|
|
!(pnt3 = pnt2->next))
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
|
|
|
d_update_line (pnt);
|
|
|
|
return; /* Not fully drawn */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update a real curve */
|
|
|
|
/* Nothing to be done ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
d_arc_start (GdkPoint *pnt,
|
2004-07-05 04:50:25 +08:00
|
|
|
gint shift_down)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
|
|
|
/* Draw lines to start with -- then convert to an arc */
|
|
|
|
if (!tmp_line)
|
|
|
|
draw_sqr (pnt);
|
|
|
|
d_line_start (pnt, TRUE); /* TRUE means multiple pointed line */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
d_arc_end (GdkPoint *pnt,
|
2004-07-05 04:50:25 +08:00
|
|
|
gint shift_down)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
2004-10-29 05:09:33 +08:00
|
|
|
/* Under control point */
|
|
|
|
if (!tmp_line ||
|
|
|
|
!tmp_line->points ||
|
|
|
|
!tmp_line->points->next)
|
2003-10-19 17:44:46 +08:00
|
|
|
{
|
2003-10-20 05:03:21 +08:00
|
|
|
/* No arc created - yet. Must have three points */
|
2003-10-19 17:44:46 +08:00
|
|
|
d_line_end (pnt, TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Complete arc */
|
|
|
|
/* Convert to an arc ... */
|
|
|
|
tmp_line->type = ARC;
|
2004-07-07 03:32:55 +08:00
|
|
|
tmp_line->class = &dobj_class[ARC];
|
2003-10-19 17:44:46 +08:00
|
|
|
d_line_end (pnt, FALSE);
|
|
|
|
/*d_draw_line (newarc); Should undraw line */
|
|
|
|
if (need_to_scale)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
selvals.scaletoimage = 0;
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
/*d_draw_arc (newarc);*/
|
2004-07-05 04:50:25 +08:00
|
|
|
gtk_widget_queue_draw (gfig_context->preview);
|
2003-10-19 17:44:46 +08:00
|
|
|
if (need_to_scale)
|
2004-07-05 04:50:25 +08:00
|
|
|
{
|
|
|
|
selvals.scaletoimage = 1;
|
|
|
|
}
|
2003-10-19 17:44:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|