Utility functions for math objects.
rectanglesOverlap {P1 P2 Q1 Q2 strict}determine if the rectangles defined by the corner pointsP1 P2andQ1 Q2. Strict is a bool that indicates if the answer is strictly determined. (From: Cormen, Leiserson, and Rivests' "Algorithms", page 889)regionToBbox {r}: converts a regionrto its bounding box, returns a list of{minimum_x minimum_y maximum_x maximum_y}boxCentroid {box}: returns the centroid of the boxboxboxWidth {box}: returns the width of the boxboxboxHeight {box}: returns the height of the boxbox
A vec2 is a 2d vector, i.e. a structure that stores 2 number, and can preform operations upon it. In Tcl they are represented by a list of 2 numbers.
add {a b}: adds the respective pairs of x and y values togethersub {a b}: subracts the respective pairs of Xb and Yb from Xa and Yascale {a args}: if args is 1 value, scale both values by it, if it's 2 values, scale Xa by Xargs and Ya by Yargsrotate {a theta}: rotate the values in a by thetadistance {a b}: calculates the euclidean distance (the length of a line segment between the two points)normalize {a}: normalizes the vector by dividing each value by the magnitude of the vectordot {a b}: calculate the dot product of the two vectors, basically, calculates how much two vectors point in the same direction.distanceToLineSegment {a v w}: returns the distance to the line segment defined by v and wmidpoint {a b}: returns the midpoint of the line segment defined bya b.
A region is an arbitrary oriented chunk of a plane. The archetypal region is the region of a program/page, which is the quadrilateral area of space that is covered by that page. A region is defined by a set of vertices and a set of edges among those vertices.
create {vertices edges {angle 0}}: create a region with the given vertices and edges, and optional angle.vertices {r}: return the vertices of the regionredges {r}: return the edges of the regionrangle {r}: return the angle of the regionrwidth {r}: return the width of the regionrin screen space, acounting for rotation.height {r}: return the height of the regionrin screen space, acounting for rotation.top {r}: return the vec2 point at the top of the regionrleft {r}: return the vec2 point to the left of the regionrright {r}: return the vec2 point to the right of the regionrbottom {r}: return the vec2 point at the bottom of the regionrbottomleft {r}: return the vec2 point at the bottom left of the regionrbottomright {r}: return the vec2 point at the bottom right of the regionrtopleft {r}: return the vec2 point at the top left of the regionrtopright {r}: return the vec2 point at the top right of the regionrmapVertices {varname r body}: apply the body for each vectorvarnamein regionrdistance {r1 r2}: calculate the distance between regionsr1andr2contains {r p}: check if the regionrcontains the pointpintersects {r1 r2}: check if regionr1intersects with regionr2centroid {r}: only works for rectangular regions! returns the point that is the centroid of the regionrrotate {r angle}: returns a regionr'that has been rotated byanglescale {r args}: Accepts values inpx,%, and unmarked. If 1 arg, scale all by that arg, otherwise acceptsX<unit> width Y<unit> heightmove {r args}: Moves the region left/right/up/down on the x and y axies of the region, not the global x and y. Args in the format<AMMOUNT><UNIT> <DIRECTION>where unit is one of the units that scale supports, and direction is left/right/up/down.
- Rewrite in C
- Triangulate a region
- Average the centroids of all triangles in a region
- Rename
regionToBbox - Assert that
boxis actually a box - Optimize
scale - Allow areas in regions to be filled/unfilled
CC-BY-SA 2023 Arcade Wise (We can change the license if y'all want, I just wanted to avoid copyright issues)