ORIGIN '~beta/basiclib/betaenv'; LIB_DEF 'guienvgraphmath' '../lib'; BODY 'private/graphmathbody'; (* * COPYRIGHT * Copyright (C) Mjolner Informatics, 1991-96 * All rights reserved. *) -- lib: attributes -- point: (* A point is defined as the intersection between a vertical line * and a horisontal line in the coordinate plane *) (# <<SLOT pointLib: attributes>>; v, h: @integer; add: (* adds the coordinates of p to the coordinates THIS(point) *) (# p: @point enter p do ... #); subtract: (* subtracts the coordinates of p from the coordinates of * THIS(point) *) (# p: @point enter p do ... #); isEqual: booleanValue (* compares THIS(point) to p and returns true if they are * equal or false if not *) (# p: @point enter p do ... #); enter (h, v) exit (h, v) #) (* point *); rectangle: (* rectangles are used to define areas on the screen, to assign * coordinate systems to graphic entities, and to specify the * location and sizes for various drawing commands. A rectangle is * defined by two points topLeft, bottomRight, which denote the * top-left corner and the bottom-right corner of the rectangle *) (# <<SLOT rectangleLib: attributes>>; topLeft: (# enter (left, top) exit (left, top) #); bottomRight: (# enter (right, bottom) exit (right, bottom) #); left, top, right, bottom: @integer; set: (* assigns the four boundary coordinates to THIS(rectangle) *) (# left, top, right, bottom: @integer enter (left, top, right, bottom) do ... #); setFromPoints: (* sets THIS(rectangle) to the smallest rectangle that * encloses the two given points p1, p2 *) (# p1, p2: @point; enter (p1, p2) do ... #); size: (* evaluate the enter part to set the width and height. * Evaluate the exit part to get the width and height *) (# w, h: @integer; enter (# enter (w, h) do ... #) exit (# do ... exit (w, h) #) #); offset: (* moves THIS(rectangle) by adding delta.h to each horizontal * coordinate and delta.v to each vertical coordinate *) (# delta: @point enter delta do ... #); inset: (* shrinks or expands THIS(rectangle). The left and right * sides are moved in by the amount specified by delta.h; the * top and bottom are moved toward the center by the amount * specified by delta.v. If delta.h or delta.v is negative, * the appropriate pair of sides is moved outward instead of * inward *) (# delta: @point enter delta do ... #); intersection: booleanValue (* calculates the rectangle that is the intersection of src1 * and src2, sets THIS(rectangle) to the intersection. Result * is set to true iff src1 and src2 indeed intersect *) (# src1, src2: @rectangle enter (src1, src2) do ... #); union: (* calculates the smallest rectangle that encloses src1 and * src2, and sets THIS(rectangle) to the result *) (# src1, src2: @rectangle enter (src1, src2) do ... #); containsPoint: booleanValue (* determines whether the pixel below and to the right of the * given coordinate point is enclosed in the specified * rectangle, and returns true if so or false if not *) (# p: @point enter p do ... #); pToAngle: (* calculates an integer angle between a line from the center * of the rectangle to thePoint and a line from the center of * the rectangle pointing straight up (12 o'clock high). The * angle is in degrees from 0 to 359, measured clockwise from * 12 oUclock, with 90 degrees at 3 o'clock, 180 at 6 o'clock, * and 270 at 9 o'clock *) (# thePoint: @point; angle: @integer enter thePoint do ... exit angle #); isEqual: booleanValue (* compares theRectangle to THIS(rectangle) and returns true * if they are equal or false if not. The two rectangles must * have identical boundary coordinates to be considered equal *) (# theRectangle: @rectangle enter theRectangle do ... #); isEmpty: booleanValue (* returns true if THIS(rectangle) is an empty rectangle or * false if not. A rectangle is considered empty if the bottom * coordinate is less than or equal to the top or the right * coordinate is less than or equal to the left *) (# do ... #); enter (topLeft, bottomRight) exit (topLeft, bottomRight) #) (* rectangle *); matrix: (# << slot matrixLib: attributes>>; (* a b 0 * c d 0 * tx ty 1 *) a, b, c, d, tx, ty: @real; inverse: ^matrix; mult: (* Multiply two matrices *) (# A, B, res: ^matrix; enter (A[], B[]) do ... exit res[] #); transformPoint: @ (# p, result: @point; enter p do ... exit result #); inverseTransformPoint: @ (# p1, p2: @point; enter p1 do ... exit p2 #); transformRectangle: @ (# r, result: @rectangle; enter r do ... exit result #); inverseTransformRectangle: (# r, result: @rectangle; enter r do ... exit result #); getInverse: @ (# get: @...; do get; exit inverse[] #); enter (a, b, c, d, tx, ty) do INNER; exit (a, b, c, d, tx, ty) #); IDmatrix: (# ID: ^matrix do ... exit ID[] #); moveMatrix: matrix (* A matrix specifying a translation *) (# itx, ity: @integer; enter (itx, ity) do ... #); scaleMatrix: matrix (* A matrix specifying a scaling *) (# enter (a, d) do ... #); rotateMatrix: matrix (* A matrix specifying a rotation *) (# theta: @real; enter theta do ... #); ovalAngle: (* Returns the angle a (in radians) and cos(a), sin(a), assuming * that (x,y) is a point on the oval with center in (cx,cy) and * horizontal radius hr and verticalradius vr, i.e. * (x,y) = (cx,cy) + (hr*cos(a),vr*sin(a)) *) (# cx, cy, hr, vr, x, y: @integer; a, cos_a, sin_a: @real; angle: @...; enter (cx, cy, hr, vr, x, y) do angle exit (a, cos_a, sin_a) #); circleAngle: (* Returns the angle a (in radians) and cos(a), sin(a), assuming * that (x,y) is a point on the circle with center in (cx,cy) and * radius r, for some r i.e. (x,y) = (cx,cy) + (r*cos(a),r*sin(a)) *) (# cx, cy, x, y: @integer; a, cos_a, sin_a: @real; angle: @...; enter (cx, cy, x, y) do angle exit (a, cos_a, sin_a) #); region: (* A region is a collection of spatially coherent points *) (# <<SLOT regionLib: attributes>>; bounds: (# theRectangle: @rectangle; do ... exit theRectangle #); allocate: (* allocates space for a new, variable-size region, * initializes it to the empty region defined by the rectangle * (0, 0)(0, 0) *) ...; dispose: (* releases the memory occupied by THIS(region). Use this only * after you are completely through with a temporary region *) ...; empty: (* destroys the previous structure of the given region, then * sets THIS(region) new to the empty region. *) ...; setFromRectangle: (* destroys the previous structure of THIS(region), and then * sets the new structure to the rectangle specified by * theRectangle *) (# theRectangle: @rectangle enter theRectangle do ... #); offset: (* moves THIS(region) on the coordinate plane, a distance of * delta.h horizontally and delta.v vertically *) (# delta: @point enter delta do ... #); inset: (* shrinks or expands THIS(region). All points on the region * boundary are moved inwards a distance of dv vertically and * dh horizontally; if dh or dv is negative, the points are * moved outwards in that direction. It leaves THIS(region) * centered at the same position, but moves the outline in - * for positive values of dh and dv - or out - for negative * values of dh and dv *) (# delta: @point enter delta do ... #); intersection: (* calculates the intersection of two regions src1 and src2, * and sets THIS(region) to the intersection. This does not * create THIS(region); space must already have been allocated * for it. THIS(region) can be one of the source regions, if * desired *) (# src1, src2: ^region enter (src1[], src2[]) do ... #); union: (* calculates the union of two regions src1 and src2, and sets * THIS(region) to the union. This does not create * THIS(region); space must already have been allocated for * THIS(region). THIS(region) can be one of the source * regions, if desired *) (# src1, src2: ^region enter (src1[], src2[]) do ... #); difference: (* subtracts src2 from src1 and sets THIS(region) to the * difference. This does not create THIS(region); space must * already have been allocated for it. THIS(region) can be one * of the source regions, if desired *) (# src1, src2: ^region enter (src1[], src2[]) do ... #); symDiff: (* calculates the difference between the union and the * intersection of src1 and src2 and places the result in * dstRgn. This does not create THIS(region); space must * already have been allocated for it. THIS(region) can be one * of the source regions, if desired *) (# src1, src2: ^region enter (src1[], src2[]) do ... #); containsPoint: booleanValue (* checks whether the pixel below and to the right of pt is * within THIS(region), and returns true if so or false if not *) (# pt: @point enter pt do ... #); containsRectangle: booleanValue (* checks whether theRectangle intersects the specified * region, and returns true if the intersection encloses at * least one bit or false if not *) (# theRectangle: @rectangle enter theRectangle do ... #); isEqual: booleanValue (* compares THIS(region) to theRegion and returns true if they * are equal or false if not. THIS(region) and theRegion must * have identical sizes, shapes, and locations to be considered * equal. If THIS(region) and theRegion are empty regions true * is returned as well *) (# theRegion: ^region enter theRegion do ... #); isEmpty: booleanValue (* returns true if THIS(region) is an empty region or false if * not *) (# do ... #); private: @...; enter (# r: ^region enter r[] do ... #) exit (# r: ^region do ... exit r[] #) #)
20.7 Graphmath Interface | © 1994-2002 Mjølner Informatics |
[Modified: Thursday August 27th 1998 at 16:23]
|