Liking cljdoc? Tell your friends :D

quip.util

Miscellaneous utility functions.

Vector math functions for position/rotation/velocity calculations.

Geometric collision detection predicates.

Misc utilities.

Miscellaneous utility functions.

Vector math functions for position/rotation/velocity calculations.

Geometric collision detection predicates.

Misc utilities.
raw docstring

backgroundclj

source

blackclj

source

blueclj

source

bold-fontclj

source

bold-italic-fontclj

source

coarse-polys-collide?clj

(coarse-polys-collide? poly-a poly-b)

Predicate to determine if two polygons possibly collide.

Checks if the minimum rectangles containing the polygons overlap. If they do we should use fine-polys-collide? to check properly.

Predicate to determine if two polygons possibly collide.

Checks if the minimum rectangles containing the polygons overlap. If
they do we should use `fine-polys-collide?` to check properly.
sourceraw docstring

coarse-pos-in-poly?clj

(coarse-pos-in-poly? [x y] poly)

Predicate to determine if a point is possibly inside a polygon.

Checks if the point is contanied by the minimum rectangle containing the polygon. If the point is inside this rectangle we should use fine-pos-in-poly? to check properly.

Predicate to determine if a point is possibly inside a polygon.

Checks if the point is contanied by the minimum rectangle containing
the polygon. If the point is inside this rectangle we should use
`fine-pos-in-poly?` to check properly.
sourceraw docstring

darkenclj

(darken [_r _g _b a :as color])

Darken a colour by 30, preserving alpha component if present.

Darken a colour by 30, preserving alpha component if present.
sourceraw docstring

default-fontclj

source

default-text-sizeclj

source

direction-vectorclj

(direction-vector r)

Calculate the unit direction vector based on the rotation angle.

Calculate the unit direction vector based on the rotation angle.
sourceraw docstring

equal-pos?clj

(equal-pos? pos-a pos-b)

Predicate to check if two positions are equal.

Predicate to check if two positions are equal.
sourceraw docstring

fillclj

source

fine-polys-collide?clj

(fine-polys-collide? poly-a poly-b)

Predicate to determine if two polygons overlap.

We first check if there are any points shared by the polygons, then we check if any of the lines intersect.

If no lines intersect it is still possible that one polygon is fully containing the other. In this case one polygon will contain all the points of the other. So we can just check if the first point of poly-a is contained in poly-b or vice versa.

Predicate to determine if two polygons overlap.

We first check if there are any points shared by the polygons, then
we check if any of the lines intersect.

If no lines intersect it is still possible that one polygon is fully
containing the other. In this case one polygon will contain all the
points of the other. So we can just check if the first point of
poly-a is contained in poly-b or vice versa.
sourceraw docstring

fine-pos-in-poly?clj

(fine-pos-in-poly? pos poly)

Uses ray casting to check if a polygon encloses a pos.

We construct a line starting at our point and count how many of the polygon lines it intersects, an odd number of intersections means the point is inside the polygon.

Our line should be infinite, but in practice any large number will suffice.

Uses ray casting to check if a polygon encloses a pos.

We construct a line starting at our point and count how many of the
polygon lines it intersects, an odd number of intersections means
the point is inside the polygon.

Our line should be infinite, but in practice any large number will
suffice.
sourceraw docstring

grayclj

source

greenclj

source

greyclj

source

hex->rgbclj

(hex->rgb hex-string)
source

invertclj

(invert v)

Multiply each component of the vector by -1.

Represents a rotation of 180 degrees.

Multiply each component of the vector by -1.

Represents a rotation of 180 degrees.
sourceraw docstring

italic-bold-fontclj

source

italic-fontclj

source

large-text-sizeclj

source

lightenclj

(lighten [_r _g _b a :as color])

Lighten a colour by 30, preserving alpha component if present.

Lighten a colour by 30, preserving alpha component if present.
sourceraw docstring

lines-intersect?clj

(lines-intersect? [[x1 y1 :as p1] [x2 y2 :as p2] :as l1]
                  [[x3 y3 :as p3] [x4 y4 :as p4] :as l2])

Predicate to determine if two lines intersect.

We have decided that zero-length lines do not intersect as the complexity in determining their intersection is not worth the performance hit.

line a: (x1, y1) -> (x2, y2) line b: (x3, y3) -> (x4, y4)

lines intersect iff: 0.0 <= numerator-t/denominator-t <= 1.0 and 0.0 <= numerator-u/denominator-u <= 1.0

We can just assert that the fraction is bottom-heavy.

Predicate to determine if two lines intersect.

We have decided that zero-length lines do not intersect as the
complexity in determining their intersection is not worth the
performance hit.

line a: (x1, y1) -> (x2, y2)
line b: (x3, y3) -> (x4, y4)

lines intersect iff:
     0.0 <= numerator-t/denominator-t <= 1.0
and  0.0 <= numerator-u/denominator-u <= 1.0

We can just assert that the fraction is bottom-heavy.
sourceraw docstring

magnitudeclj

(magnitude v)

Calculate the length of a vector.

Calculate the length of a vector.
sourceraw docstring

make-posclj

(make-pos [x-factor y-factor])

Create an [x y] vector based on the supplied factors and the current game width and height.

Create an `[x y]` vector based on the supplied factors and the
current game width and height.
sourceraw docstring

ms->framesclj

(ms->frames ms)
(ms->frames ms frame-rate)

Determines the expected number of frames to be processed in ms milliseconds. Useful for defining tweens or delays based on time instead of frame count directly.

Optionally takes a specific framerate (in case you want to use the :average-fps in the game state for a more stable result).

Minimum returned value is 1.

Determines the expected number of frames to be processed in `ms`
milliseconds. Useful for defining tweens or delays based on time
instead of frame count directly.

Optionally takes a specific framerate (in case you want to use the
`:average-fps` in the game state for a more stable result).

Minimum returned value is 1.
sourceraw docstring

normalizeclj

(normalize v)

Calculate the unit vector of a given vector.

We calculate the reciprocal of the magnitude of the vector and multiply the components by this factor to avoid multiple division operations.

Calculate the unit vector of a given vector.

We calculate the reciprocal of the magnitude of the vector and
multiply the components by this factor to avoid multiple division
operations.
sourceraw docstring

orthogonalsclj

(orthogonals [x y])

Calculate the two orthogonal vectors to a given 2D vector.

Y axis is inverted so this returns [90-degrees-right-vector 90-degrees-left-vector]

Calculate the two orthogonal vectors to a given 2D vector.

Y axis is inverted so this returns [90-degrees-right-vector
                                    90-degrees-left-vector]
sourceraw docstring

poly-linesclj

(poly-lines poly)

Construct the lines that make up a polygon from its points.

Construct the lines that make up a polygon from its points.
sourceraw docstring

poly-w-hclj

(poly-w-h poly)
source

polys-collide?clj

(polys-collide? poly-a poly-b)

Predicate to check if two polygons overlap.

The fine-polys-collide? predicate is expensive so we only do it if the cheaper coarse-polys-collide? says this is a possible collision.

Predicate to check if two polygons overlap.

The `fine-polys-collide?` predicate is expensive so we only do it if
the cheaper `coarse-polys-collide?` says this is a possible
collision.
sourceraw docstring

pos->rayclj

(pos->ray [x y])

Creates an arbitrarily long line starting at the specified pos.

When doing poly->point collision detection a point lying on a horizontal edge of a poly would cause a division by zero if we used a horizontal ray.

This would be handled, but would not count as a collision so we increment y to make it much less likely that the intersecting lines are parallel.

Creates an arbitrarily long line starting at the specified pos.

When doing poly->point collision detection a point lying on a
horizontal edge of a poly would cause a division by zero if we used
a horizontal ray.

This would be handled, but would not count as a collision so we
increment y to make it much less likely that the intersecting lines
are parallel.
sourceraw docstring

pos-in-poly?clj

(pos-in-poly? pos poly)

Predicate to check if a pos is inside a polygon.

The fine-pos-in-poly? predicate is expensive so we only do it if the cheaper coarse-pos-in-poly? says this is a possible collision.

Predicate to check if a pos is inside a polygon.

The `fine-pos-in-poly?` predicate is expensive so we only do it if
the cheaper `coarse-pos-in-poly?` says this is a possible
collision.
sourceraw docstring

pos-in-rect?clj

(pos-in-rect? [ax ay] [bx1 by1 bx2 by2])

Predicate to check if a position is inside a rectangle.

Predicate to check if a position is inside a rectangle.
sourceraw docstring

rects-overlap?clj

(rects-overlap? [ax1 ay1 ax2 ay2] [bx1 by1 bx2 by2])

Predicate to determine if two rectangles overlap.

Predicate to determine if two rectangles overlap.
sourceraw docstring

redclj

source

rotate-vectorclj

(rotate-vector [x y :as v] r)

Rotate a vector about the origin by r degrees.

Checks first for r representing an integer number of rotations, in with case the vector will be unchanged.

Rotate a vector about the origin by `r` degrees.

Checks first for `r` representing an integer number of rotations, in
with case the vector will be unchanged.
sourceraw docstring

rotation-angleclj

(rotation-angle [x y])

Calculate the rotation angle of a vector.

Calculate the rotation angle of a vector.
sourceraw docstring

small-text-sizeclj

source

squared-magnitudeclj

(squared-magnitude [x y z])

Sum the squares of the components of a vector.

The if check on z is a lot faster than doing an apply or reduce across the vector.

Sum the squares of the components of a vector.

The `if` check on `z` is a lot faster than doing an `apply` or
`reduce` across the vector.
sourceraw docstring

strokeclj

source

title-text-sizeclj

source

unit-vectorclj

(unit-vector v)

Calculate the unit vector of a given vector.

Calculate the unit vector of a given vector.
sourceraw docstring

v<clj

(v< a b)

Determine if the magnitude of a vector a is less than the magnitude of vector b.

We can just compare the component squares to avoid the costly sqrt operations.

Determine if the magnitude of a vector `a` is less than the magnitude
of vector `b`.

We can just compare the component squares to avoid the costly `sqrt`
operations.
sourceraw docstring

v<=clj

(v<= a b)

Determine if the magnitude of a vector a is less than or equal to the magnitude of vector b.

We can just compare the component squares to avoid the costly sqrt operations.

Determine if the magnitude of a vector `a` is less than or equal to
the magnitude of vector `b`.

We can just compare the component squares to avoid the costly `sqrt`
operations.
sourceraw docstring

whiteclj

source

wrap-trans-rotclj

(wrap-trans-rot [x y] r f)

Perform a translation, a rotation, invoke the supplied function (probably drawing a sprite, then reset the transform matrix to the identity.

Perform a translation, a rotation, invoke the supplied
function (probably drawing a sprite, then reset the transform matrix
to the identity.
sourceraw docstring

zero-vector?clj

(zero-vector? v)

Predicate to check if a vector has length 0.

Predicate to check if a vector has length 0.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close