AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
pointInPolygon (Point p, Array xpoints, Array ypoints [, int count]) yoix.graphics
pointInPolygon (Point p, Number x0, Number y0, Number x1, Number y1, ...)  
 
Returns 1 if p lies inside the polygon that has vertices at the points whose x and y coordinates are supplied as numbers in the xpoints and ypoints arrays. The number of vertices in the polygon can be specified by the optional count argument, which must be less than or equal to the number of elements in both xpoints and ypoints. When count is omitted pointInPolygon chooses a value that is the minimum of the size of the xpoints and ypoints arrays. The Yoix implementation of pointInPolygon also accepts x and y coordinates of the vertices in the polygon as arguments.
 
 Example:   The program,
import yoix.*.*;

Star(double xcenter, double ycenter) {
    return(
        new Array {
            xcenter + 0, ycenter + -50,
            xcenter + 29, ycenter + 40,
            xcenter + -47, ycenter + -15,
            xcenter + 47, ycenter + -15,
            xcenter + -29, ycenter + 40,
        }
    );
}

JFrame frame = {
    Array layout = {
        new JCanvas {
            Color background = Color.black;

            Graphics graphics = {
                Color foreground = Color.yellow;
            };

            Array star;

            paint(clip) {
                this.star = Star(size.width - 72, size.height - 72*2);
                fillPolygon(this, unroll(star));
            }

            mousePressed(e) {
                int result;

                if (star != NULL)
                    result = pointInPolygon(e.location, unroll(star));
                puts(result ? "inside" : "outside");
            }
        },
    };
};

frame.visible = TRUE;
sleep(5);
exit(0);
defines a paint function in a canvas that fills a yellow five pointed star that is centered 1 inch from the right and 2 inches from the bottom of the canvas. The canvas also defines a mousePressed event handler that uses pointInPolygon to report whether the cursor was inside or outside the star when the button was pressed. The x and y coordinates of the star are returned in an array by the function named Star. The polygon is filled and queried by unrolling those coordinates using the unroll built-in and handing them to the fillPolygon and pointInPolygon built-ins.
 
 See Also:   clearRect, copyArea, drawArc, drawImage, drawLine, drawOval, drawPolygon, drawPolyline, drawRect, drawRoundRect, drawString, fillArc, fillOval, fillPolygon, fillRect, fillRoundRect, pointInRect, rectContainsRect, rectIntersectionRect, rectIntersectsRect, rectUnionRect, stringBounds, stringWidth

 

Yoix is a registered trademark of AT&T Inc.