PreviousUpNext

15.3.438  src/lib/std/2d/xgeometry.api

## xgeometry.api
#
# The api of the basic geometry types and operations.

# Compiled by:
#     src/lib/std/standard.lib


###            "Life without geometry is pointless."

###            "Let no one ignorant of Geometry enter here."    -- Pythagoras





# This api is implemented in:
#
#     src/lib/std/2d/xgeometry.pkg

# Used in:
#     src/lib/x-kit/draw/band.pkg
#     src/lib/x-kit/draw/scan-convert.pkg


api Xgeometry {


    # Geometric types (from Xlib::h) 
    #
    Point =
        POINT
          { row:  Int,
            col:  Int
          };

    Line =
        LINE (Point, Point);

    Size =
        SIZE
          { wide:  Int,
            high:  Int
          };

    # Screen rectangles represented as
    # upper-left corner plus size.
    #
    # For two-corner box representation see
    #     src/lib/x-kit/draw/box2.pkg
    Box =
        BOX
          { row:   Int,
            col:   Int,
            wide:  Int,
            high:  Int
          };

    Arc = ARC { row:  Int,
                col:  Int,

                wide:  Int,
                high:  Int,

                angle1:  Int,
                angle2:  Int
              };

    # The size and position of a window
    # relative to its parent.
    #
    # Note that position does not take
    # border_thickness into account.
    #
    Window_Site
        =
        WINDOW_SITE
          {
            upperleft:     Point,
            size:          Size,
            border_thickness:  Int              # In pixels.
          };



    # Points: 
    #
    package point:  api {

        zero:      Point;                       # Point (0,0).

        row:       Point -> Int;
        col:       Point -> Int;

        scale:    (Point, Int  ) -> Point;

        add:      (Point, Point) -> Point;
        subtract: (Point, Point) -> Point;

        add_size: (Point, Size ) -> Point;
        clip:     (Point, Size ) -> Point;      # Clip point to be within box defined by point::zero and size, using orthogonal projection..

        ne:       (Point, Point) -> Bool;       # x1 != x2 or  y1 != y2.
        eq:       (Point, Point) -> Bool;       # x1 == x2 and y1 == y2.
        lt:       (Point, Point) -> Bool;       # x1 <  x2 and y1 <  y2.
        le:       (Point, Point) -> Bool;       # x1 <= x2 and y1 <= y2
        gt:       (Point, Point) -> Bool;       # x1 >  x2 and y1 >  y2
        ge:       (Point, Point) -> Bool;       # x1 >= x2 and y1 >= y2

        in_box:   (Point, Box  ) -> Bool;       # TRUE iff point is within box.

        bounding_box:   List(Point)  -> Box;    # Construct bounding box for given points.
                                                # Empty list returns BOX { col=>0, row=>0, wide=>0, high=>0 };
    };


    package size:  api {
        #
        add:        (Size, Size) -> Size;
        subtract:   (Size, Size) -> Size;
        scale:      (Size, Int ) -> Size;
        eq:         (Size, Size) -> Bool;
    };
    #


    package box:  api {

        make:         (Point, Size) -> Box;
        upperleft:     Box -> Point;
        lowerright:    Box -> Point;
        size:          Box -> Size;
        middle:        Box -> Point;

        upperleft_and_size:  Box -> (Point, Size);

        clip_point:    (Box, Point) -> Point;           # Clip point to be within box, using orthogonal projection.
        translate:     (Box, Point) -> Box;             # box.upperleft += point.
        rtranslate:    (Box, Point) -> Box;             # box.upperleft -= point.
        intersect:     (Box, Box) -> Bool;              # TRUE iff the boxes overlap.
        exception INTERSECTION;
        intersection:  (Box,   Box) -> Box;             # Construct largest box contained by both input boxes.
        union:         (Box,   Box) -> Box;             # Construct smallest box containing  both input boxes.
        xor:           (Box,   Box) -> List(Box);       # Construct the symmetric difference of two boxes.
        in_box:        (Box,   Box) -> Bool;            # TRUE iff fixt box is within second.
    };


};


## COPYRIGHT (c) 1990, 1991 by John H. Reppy.  See SMLNJ-COPYRIGHT file for details.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2013,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext