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
rectIntersectsRect (Rectangle rect1, Rectangle rect2) yoix.graphics
rectIntersectsRect (Rectangle rect1, Number x, Number y, Number width, Number height)  
 
Returns 1 if rectangle rect1 intersects rectangle rect2 and 0 if it doesn't. The second rectangle can also be supplied by giving its width, height, and coordinates of its upper left corner (x,y).
 
 Example:   The program,
import yoix.*.*;

JFrame frame = {
    GridBagLayout layoutmanager;
    Array layout = {
        new JCanvas {
            String tag = "$_canvas";

            Rectangle rect1;
            Rectangle rect2;

            paint() {
                rect1.x = 36;
                rect1.y = 36;
                rect1.width = 3.0*72.0;
                rect1.height = 0.5*71.0;

                rect2.x = root.size.width - 5.0*72.0;
                rect2.y = root.size.height - 3.0*72.0;
                rect2.width = 4.0*72.0;
                rect2.height = 1.0*72.0;

                graphics {
                    gsave();
                    setrgbcolor(Color.red);
                    rectfill(rect1);
                    setrgbcolor(Color.blue);
                    rectfill(rect2);
                    grestore();
                }
            }
        },
        BOTH, REMAINDER,

        new JButton {
            String text = "Rectangles Intersect?";

            actionPerformed(e) {
                Rectangle rect;
                int       intersects;

                intersects = rectIntersectsRect(
                    root.components.$_canvas.rect1,
                    root.components.$_canvas.rect2
                );

                if (intersects)
                    printf("The rectangles intersect\n");
                else printf("The rectangles do not intersect\n");
            }
        },
        NONE, REMAINDER,
        72.0/16,
    };
};

frame.visible = TRUE;
draws two rectangles in a canvas and includes a button at the bottom of the frame that tells you if the rectangles intersect or not when it's pressed. The rectangles are drawn at fixed positions relative to the upper left and lower right corners of the frame, so you can make them intersect by resizing the frame.
 
 See Also:   clearRect, copyArea, drawArc, drawImage, drawLine, drawOval, drawPolygon, drawPolyline, drawRect, drawRoundRect, drawString, fillArc, fillOval, fillPolygon, fillRect, fillRoundRect, pointInPolygon, pointInRect, rectContainsRect, rectIntersectionRect, rectUnionRect, stringBounds, stringWidth

 

Yoix is a registered trademark of AT&T Inc.