((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/2d-primitives" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.") (tags "egg")) (section 2 "2d-primitives" (toc) (section 3 "Description" (p "A collection of primitives and linear algebra common for 2D graphics and 2D games.")) (section 3 "Author" (p "Richard van Roy (pluizer)")) (section 3 "Requirements" (p "none")) (section 3 "Documentation" (section 4 "Floating points" (def (sig (procedure "(fmod numer denom)" (id fmod))) (p "Returns the floating-point remainder of numer/denom (rounded towards zero).")) (def (sig (procedure "(clamp f mmin mmax)" (id clamp))) (p "Clamp a floating-point number to a minimum and a maximum.")) (def (sig (procedure "(sqr x)" (id sqr))) (p "Square a number.")) (def (sig (constant "(float-min)" (id float-min))) (p "Minimum representable floating-point number.")) (def (sig (constant "infinity" (id infinity))))) (section 4 "Constants" (def (sig (constant "epsilon" (id epsilon)))) (def (sig (constant "pi" (id pi)))) (def (sig (constant "pi/2" (id pi/2)))) (def (sig (constant "2pi" (id 2pi)))) (def (sig (constant "-pi" (id -pi)))) (def (sig (constant "360/2pi" (id 360/2pi)))) (def (sig (constant "2pi/360" (id 2pi/360))))) (section 4 "Angles" (def (sig (procedure "(radian->degree radians)" (id radian->degree)))) (def (sig (procedure "(degree->radian degrees)" (id degree->radian)))) (def (sig (procedure "(flip-radian-h radians)" (id flip-radian-h)))) (def (sig (procedure "(flip-radian-v radians)" (id flip-radian-v)))) (def (sig (procedure "(flip-degree-h degrees)" (id flip-degree-h)))) (def (sig (procedure "(flip-degree-v degrees)" (id flip-degree-v))))) (section 4 "Vectors" (def (sig (procedure "(vect:create x y)" (id vect:create))) (p "Returs a new vector")) (def (sig (procedure "(vect? obj)" (id vect?)))) (def (sig (procedure "(vect:x v)" (id vect:x)))) (def (sig (procedure "(vect:y v)" (id vect:y)))) (def (sig (procedure "(zero-vect)" (id zero-vect))) (p "Constant for the zero vector.")) (def (sig (procedure "(vect=? a b #!optional (epsilon .001)" (id #f))) (p "Check if two vectors are equal.")) (def (sig (procedure "(vect+ a b)" (id vect+))) (p "Add two vectors.")) (def (sig (procedure "(vect- a #!optional b)" (id vect-))) (p "Subtract two vectors or negate a vector.")) (def (sig (procedure "(vect* v s)" (id vect*))) (p "Scalar multiplication.")) (def (sig (procedure "(vect:dot a b)" (id vect:dot))) (p "Vector dot product.")) (def (sig (procedure "(vect:cross a b)" (id vect:cross))) (p "2D vector cross product analog. The cross product of 2D vectors results in a 3D vector with only a z component. This function returns the magnitude of the z value.")) (def (sig (procedure "(vect:perp v)" (id vect:perp))) (p "Returns a perpendicular vector. <procedure>(90 degree rotation)</procedure><br/>")) (def (sig (procedure "(vect:vperp v)" (id vect:vperp))) (p "Returns a perpendicular vector. <procedure>(-90 degree rotation)</procedure><br/>")) (def (sig (procedure "(vect:project a b)" (id vect:project))) (p "Returns the vector projection of /a/ onto /b/.")) (def (sig (procedure "(angle->vect a)" (id angle->vect))) (p "Returns the unit length vector for the given angle (in radians).")) (def (sig (procedure "(vect->angle v)" (id vect->angle))) (p "Returns the angular direction v is pointing in (in radians).")) (def (sig (procedure "(vect:rotate a b)" (id vect:rotate))) (p "Uses complex number multiplication to rotate /a/ by /b/. Scaling will occur if /a/ is not a unit vector.")) (def (sig (procedure "(vect:unrotate a b)" (id vect:unrotate))) (p "Inverse of vect:rotate")) (def (sig (procedure "(vect:length-squared v)" (id vect:length-squared))) (p "Returns the squared length of v. Faster than /(vect:length)/ when you only need to compare lengths.")) (def (sig (procedure "(vect:length v)" (id vect:length))) (p "Returns the length of v.")) (def (sig (procedure "(vect:lerp v1 v2 t)" (id vect:lerp))) (p "Linearly interpolate between /a/ and /b/.")) (def (sig (procedure "(vect:normalize v)" (id vect:normalize))) (p "Returns a normalized copy of v.")) (def (sig (procedure "(vect:clamp v len)" (id vect:clamp))) (p "Clamp v to length len.")) (def (sig (procedure "(vect:lerp-const v1 v2 dist)" (id vect:lerp-const))) (p "Linearly interpolate between v1 towards v2 by distance d.")) (def (sig (procedure "(vect:dist v1 v2)" (id vect:dist))) (p "Returns the distance between v1 and v2.")) (def (sig (procedure "(vect:dist-squared v1 v2)" (id vect:dist-squared))) (p "Returns the squared distance between v1 and v2. Faster than /(vect:distance)/ when you only need to compare distances.")) (def (sig (procedure "(vect:near? a b dist)" (id vect:near?))) (p "Returns true if the distance between v1 and v2 is less than dist.")) (def (sig (procedure "(vect:spherical-lerp a b t)" (id vect:spherical-lerp))) (p "Spherical linearly interpolate between /a/ and /b/.")) (def (sig (procedure "(vect:spherical-lerp-const a b angle)" (id vect:spherical-lerp-const))) (p "Spherical linearly interpolate between /a/ towards /b/ by no more than angle /angle/ in radians."))) (section 4 "Bounding Boxes" (def (sig (procedure "(rect:create l r b t)" (id rect:create))) (p "Returs a new bounding box.")) (def (sig (procedure "(rect? obj)" (id rect?))) (p "Can also be a line.")) (def (sig (procedure "(rect:l rect)" (id rect:l)))) (def (sig (procedure "(rect:r rect)" (id rect:r)))) (def (sig (procedure "(rect:b rect)" (id rect:b)))) (def (sig (procedure "(rect:t rect)" (id rect:t)))) (def (sig (procedure "(rect:for-circle p r)" (id rect:for-circle))) (p "Constructs a /rect/ for a circle with the given position and radius.")) (def (sig (procedure "(rect:intersects? a b)" (id rect:intersects?))) (p "Returns true if /a/ and /b/ intersect.")) (def (sig (procedure "(rect:contains? rect other)" (id rect:contains?))) (p "Returns true if /other/ lies completely within /rect/.")) (def (sig (procedure "(rect:constains-vect? rect v)" (id rect:constains-vect?))) (p "Returns true if /rect/ contains /v/.")) (def (sig (procedure "(rect:merge a b)" (id rect:merge))) (p "Returns a bounding box that holds both bounding boxes.")) (def (sig (procedure "(rect:expand rect v)" (id rect:expand))) (p "Returns a bounding box that holds both /rect/ and /v/.")) (def (sig (procedure "(rect:center rect)" (id rect:center))) (p "Returns the center of a bounding box.")) (def (sig (procedure "(rect:area rect)" (id rect:area))) (p "Returns the area of the bounding box.")) (def (sig (procedure "(rect:merged-area a b)" (id rect:merged-area))) (p "Merges /a/ and /b/ and returns the area of the merged bounding box.")) (def (sig (procedure "(rect:segment-query rect a b)" (id rect:segment-query))) (p "Returns the fraction along the segment query the bounding box is hit. Returns /infinity/ if it doesn't hit.")) (def (sig (procedure "(rect:intersects-segment? rect a b)" (id rect:intersects-segment?))) (p "Return true if the bounding box intersects the line segment with ends /a/ and /b/.")) (def (sig (procedure "(rect- rect vect)" (id rect-))) (p "Substracts a vector from a rectangle.")) (def (sig (procedure "(rect+ rect vect)" (id rect+))) (p "Adds a vector to a rectangle."))) (section 4 "Lines" (def (sig (procedure "(line:create a b)" (id line:create))) (p "Makes a line from two vectors")) (def (sig (procedure "(line? obj)" (id line?))) (p "Can also be a rect."))) (section 4 "Polygons" (def (sig (syntax "(polygon:create vects)" (id polygon:create))) (p "Creates a new polygon from a list of vectors.")) (def (sig (procedure "(polygon->vects polygon)" (id polygon->vects))) (p "Converts a polygon to a list of vertices.")) (def (sig (procedure "(polygon:triangulate polygon)" (id polygon:triangulate))) (p "Triangulates the given polygon and returns an array of vectors.")) (def (sig (procedure "(polygon:triangulate->triangles polygon)" (id polygon:triangulate->triangles))) (p "Same as polygon-triangulate but returns a list of triangles.")) (def (sig (procedure "(polygon-convex? polygon)" (id polygon-convex?))) (p "Return #t if the given polygon is convex.")) (def (sig (procedure "(convex-hull vects)" (id convex-hull))) (p "Returns the convex hull of a group of vertices in clockwise order.")) (def (sig (procedure "(polygon:convex-hull vects)" (id polygon:convex-hull))) (p "Converts any polygon to a convex polygon."))) (section 4 "Bezier curves" (def (sig (procedure "(bezier:create control-points ...)" (id bezier:create))) (p "Creates a new bezier curve with a minimum of two control-points.")) (def (sig (procedure "(bezier:ref bezier n)" (id bezier:ref))) (p "Return the point of a bezier at position n, where 0.0 is the start of the curve and 1.0 is the end.")) (def (sig (procedure "(bezier->vects bezier accuracy)" (id bezier->vects))) (p "Returns a list of points that make of a bezier curve. A higher /accuracy/ results in a higher resolution (more points)."))) (section 4 "Colours" (def (sig (procedure "(rgb:create r g b #!optional (a 1.0)" (id #f))) (p "Creates a new RGB colour")) (def (sig (procedure "(rgb:r rgb)" (id rgb:r)))) (def (sig (procedure "(rgb:g rgb)" (id rgb:g)))) (def (sig (procedure "(rgb:b rgb)" (id rgb:b)))) (def (sig (procedure "(rgb:a rgb)" (id rgb:a)))) (def (sig (procedure "(rgb->hsv rgb)" (id rgb->hsv))) (p "Convers a rgb colour to a hsv colour.")) (def (sig (procedure "(hsv:create h s v #!optional (a 1.0)" (id #f))) (p "Creates a new HSV colour")) (def (sig (procedure "(hsv:h hsv)" (id hsv:h)))) (def (sig (procedure "(hsv:s hsv)" (id hsv:s)))) (def (sig (procedure "(hsv:v hsv)" (id hsv:v)))) (def (sig (procedure "(hsv:a hsv)" (id hsv:a)))) (def (sig (procedure "(hsv->rgb hsv)" (id hsv->rgb))) (p "Converts a hsv colour to a rgb colour."))))))