point() method of GnomeCanvasArc




OK, this is currently just a cut-and-paste of GnomeCanvasEllipse's point
method. The required modification is to check not only whether the point
is in the ellipse, but also whether it's in the arc of the ellipse we're
displaying. The return value is the distance from the x, y coordinates to
the arc.
static double
gnome_canvas_arc_point (GnomeCanvasItem *item, double x, double y, int cx,
int cy, GnomeCanvasItem **actual_item)
{
        GnomeCanvasArc *arc;
        GnomeCanvasRE *re;
        double dx, dy;
        double scaled_dist;
        double outline_dist;
        double center_dist;
        double width;
        double a, b;
        double diamx, diamy;

        re = GNOME_CANVAS_RE (item);
        arc = GNOME_CANVAS_ARC (item);
        
        *actual_item = item;

        if (re->outline_set) {
                if (re->width_pixels)
                        width = re->width / item->canvas->pixels_per_unit;
                else
                        width = re->width;
        } else
                width = 0.0;

        /* Compute the distance between the center of the ellipse and
         * the point, with the ellipse considered as being scaled to a
         * circle.  */

        dx = x - (re->x1 + re->x2) / 2.0;
        dy = y - (re->y1 + re->y2) / 2.0;
        center_dist = sqrt (dx * dx + dy * dy);

        a = dx / ((re->x2 + width - re->x1) / 2.0);
        b = dy / ((re->y2 + width - re->y1) / 2.0);
        scaled_dist = sqrt (a * a + b * b);

        /* If the scaled distance is greater than 1, then we are outside.
Compu
te the distance from
         * the point to the edge of the circle, then scale back to the
original 
un-scaled coordinate
         * system.
         */
        if (scaled_dist > 1.0)
                return (center_dist / scaled_dist) * (scaled_dist - 1.0);

        /* We are inside the outer edge of the arc.  If it is filled, then
we ar
e "inside".
         * Otherwise, do the same computation as above, but also check
whether w
e are inside the
         * outline.
         */

        if (re->fill_set)
                return 0.0;

        if (scaled_dist > GNOME_CANVAS_EPSILON)
                outline_dist = (center_dist / scaled_dist) * (1.0 -
scaled_dist)
 - width;
        else {
                /* Handle very small distance */

                diamx = re->x2 - re->x1;
                diamy = re->y2 - re->y1;

                if (diamx < diamy)
                        outline_dist = (diamx - width) / 2.0;
                else
                        outline_dist = (diamy - width) / 2.0;
        }

        if (outline_dist < 0.0)
                return 0.0;

        return outline_dist;
}






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