Style Functions
Constraint Functions
equal
Require that the value x
is equal to the value y
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | First value |
y | ℝ | Real Number | Second value |
lessThan
Require that the value x
is less than the value y
with optional padding padding
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | First value |
y | ℝ | Real Number | Second value |
padding | ℝ | Real Number | Padding |
greaterThan
Require that the value x
is greater than the value y
with optional padding padding
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | First value |
y | ℝ | Real Number | Second value |
padding | ℝ | Real Number | Padding |
lessThanSq
Require that the value x
is less than the value y
, with steeper penalty
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | First value |
y | ℝ | Real Number | Second value |
greaterThanSq
Require that the value x
is greater than the value y
, with steeper penalty
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | First value |
y | ℝ | Real Number | Second value |
inRange
Require that the value x
is in the range defined by [x0, x1]
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | Value |
x0 | ℝ | Real Number | Lower bound |
x1 | ℝ | Real Number | Upper bound |
contains1D
Require that an interval [l1, r1]
contains another interval [l2, r2]
. If not possible, returns 0.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
[l1, r1] | ℝ² | 2d Vector of Reals | First interval |
[l2, r2] | ℝ² | 2d Vector of Reals | Second interval |
disjointScalar
Make scalar c
disjoint from a range left, right
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
c | ℝ | Real Number | Scalar |
left | ℝ | Real Number | Left bound |
right | ℝ | Real Number | Right bound |
perpendicular
Require that the vector defined by (q, p)
is perpendicular from the vector defined by (r, p)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
q | ℝⁿ | Vector of Reals | First point |
p | ℝⁿ | Vector of Reals | Second point |
r | ℝⁿ | Vector of Reals | Third point |
collinear
Require that three points be collinear. This does not enforce a specific ordering of points, instead it takes the arrangement of points that is most easily satisfiable.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
c1 | ℝⁿ | Vector of Reals | First point |
c2 | ℝⁿ | Vector of Reals | Second point |
c3 | ℝⁿ | Vector of Reals | Third point |
collinearOrdered
Require that three points be collinear and enforces the order of these points as provided.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
c1 | ℝⁿ | Vector of Reals | First point |
c2 | ℝⁿ | Vector of Reals | Second point |
c3 | ℝⁿ | Vector of Reals | Third point |
onCanvas
Require that shape
is on the canvas
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
shape | Shape | Any Shape | Shape |
canvasWidth | ℝ | Real Number | Width of canvas |
canvasHeight | ℝ | Real Number | Height of canvas |
minSize
Require that a shape have a size greater than some constant minimum, based on the type of the shape.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
shape | Shape | Any Shape | Shape |
limit | ℝ | Real Number | Minimum size |
maxSize
Require that a shape have a size less than some constant maximum, based on the type of the shape.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
shape | Shape | Any Shape | Shape |
limit | ℝ | Real Number | Maximum size |
overlapping
Require that shape s1
overlaps shape s2
with some overlap overlap
.
based on the type of the shape, and with an optional overlap
between them
(e.g. if s1
should be overlapping s2
with margin overlap
).
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s1 | Shape | Any Shape | Shape 1 |
s2 | Shape | Any Shape | Shape 2 |
overlap | ℝ | Real Number | Overlap |
disjoint
Require that a shape s1
is disjoint from shape s2
, based on the type of the shape, and with an optional padding
between them (e.g. if s1
should be disjoint from s2
with margin padding
).
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s1 | Shape | Any Shape | Shape 1 |
s2 | Shape | Any Shape | Shape 2 |
padding | ℝ | Real Number | Padding |
touching
Require that shape s1
is touching shape s2
based on the type of the shape, and with an optional padding
between them (e.g. if s1
should be touching s2
with margin padding
).
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s1 | Shape | Any Shape | Shape 1 |
s2 | Shape | Any Shape | Shape 2 |
padding | ℝ | Real Number | Padding |
contains
Require that a shape s1
contains another shape s2
, based on the type of the shape, and with an optional padding
between the sizes of the shapes (e.g. if s1
should contain s2
with margin padding
).
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s1 | Shape | Any Shape | Shape 1 |
s2 | Shape | Any Shape | Shape 2 |
padding | ℝ | Real Number | Padding |
atDist
Require that shape s1
is at a distance of distance
from shape s2
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s1 | Shape | Any Shape | Shape 1 |
s2 | Shape | Any Shape | Shape 2 |
distance | ℝ | Real Number | Distance |
smallerThan
Require that shape s1
is smaller than s2
with some relative padding relativePadding
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s1 | Shape | Any Shape | Shape 1 |
s2 | Shape | Any Shape | Shape 2 |
relativePadding | ℝ | Real Number | Relative padding |
disjointIntervals
Make two intervals disjoint. They must be 1D intervals (line-like shapes) sharing a y-coordinate.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s1 | LineShape | Line Shape | Line 1 |
s2 | LineShape | Line Shape | Line 2 |
isLocallyConvex
The shape should be locally convex (all angles between consecutive edges would have the same sign)
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
points | (ℝⁿ)ᵐ | List of Real Vectors | points of polygonal chain |
closed | true | false | Boolean Value | whether the polygonic chain is closed |
isConvex
The enclosed area should be convex
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
points | (ℝⁿ)ᵐ | List of Real Vectors | points of polygonal chain |
closed | true | false | Boolean Value | whether the polygonic chain is closed |
isEquilateral
All edges should have the same length
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
points | (ℝⁿ)ᵐ | List of Real Vectors | points of polygonal chain |
closed | true | false | Boolean Value | whether the polygonic chain is closed |
isEquiangular
All angles between consecutive edges should be equal
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
points | (ℝⁿ)ᵐ | List of Real Vectors | points of polygonal chain |
closed | true | false | Boolean Value | whether the polygonic chain is closed |
Objective Functions
minimal
Encourage the input value to be close to negative infinity
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | Value |
maximal
Encourage the input value to be close to infinity
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | Value |
equal
Encourage the inputs to have the same value: (x - y)^2
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | First value |
y | ℝ | Real Number | Second value |
greaterThan
Encourage x to be greater than or equal to y: max(0,y - x)^2
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | First value |
y | ℝ | Real Number | Second value |
lessThan
Encourage x to be less than or equal to y: max(0,x - y)^2
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | First value |
y | ℝ | Real Number | Second value |
repelPt
Repel point a
from another scalar b
with weight weight
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
weight | ℝ | Real Number | Weight |
a | ℝⁿ | Vector of Reals | First point |
b | ℝⁿ | Vector of Reals | Second point |
repelScalar
Repel scalar c
from another scalar d
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
c | ℝ | Real Number | First scalar |
d | ℝ | Real Number | Second scalar |
below
Encourage the center of bottom
to be below the center of top
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
bottom | Shape | Any Shape | shape on the bottom |
top | Shape | Any Shape | shape on the top |
offset | ℝ | Real Number | offset |
above
Encourage the center of top
to be above the center of bottom
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
top | Shape | Any Shape | shape on the top |
bottom | Shape | Any Shape | shape on the bottom |
offset | ℝ | Real Number | offset |
leftwards
Encourage the center of left
to be leftwards to the center of right
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
left | Shape | Any Shape | shape on the left |
right | Shape | Any Shape | shape on the right |
offset | ℝ | Real Number | offset |
rightwards
Encourage the center of right
to be rightwards to the center of left
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
right | Shape | Any Shape | shape on the right |
left | Shape | Any Shape | shape on the left |
offset | ℝ | Real Number | offset |
sameCenter
Encourage shape s1
to have the same center position as shape s2
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s1 | Shape | Any Shape | a shape |
s2 | Shape | Any Shape | a shape |
notTooClose
Try to repel shapes s1
and s2
with some weight.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s1 | Shape | Any Shape | a shape |
s2 | Shape | Any Shape | a shape |
weight | ℝ | Real Number | weight of repel |
near
Try to place shape s1
near shape s2
(putting their centers at the same place).
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s1 | Shape | Any Shape | a shape |
s2 | Shape | Any Shape | a shape |
offset | ℝ | Real Number | offset |
nearPt
Try to place shape s1
near a location (x, y)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s1 | Shape | Any Shape | a shape |
x | ℝ | Real Number | `x` |
y | ℝ | Real Number | `y` |
nonDegenerateAngle
Try to place shape s1
near a location (x, y)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s0 | Shape | Any Shape | a shape |
s1 | Shape | Any Shape | a shape |
s2 | Shape | Any Shape | a shape |
strength | ℝ | Real Number | strength |
range | ℝ | Real Number | range |
centerLabelAbove
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s1 | LineShape | Line Shape | |
s2 | EquationShape | ImageShape | RectangleShape | TextShape | any of: Equation Shape, or Image Shape, or Rectangle Shape, or Text Shape | |
w | ℝ | Real Number |
centerLabel
Try to center a label s2
with respect to some shape s1
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s1 | LineShape | EquationShape | ImageShape | RectangleShape | TextShape | any of: Line Shape, or any of: Equation Shape, or Image Shape, or Rectangle Shape, or Text Shape | |
s2 | EquationShape | ImageShape | RectangleShape | TextShape | any of: Equation Shape, or Image Shape, or Rectangle Shape, or Text Shape | |
w | ℝ | Real Number | |
padding | ℝ | Real Number |
pointLineDist
Try to make distance between a point and a segment s1
equal to padding.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
point | ℝ² | 2d Vector of Reals | |
s1 | LineShape | Line Shape | |
padding | ℝ | Real Number |
isRegular
Try to make the shape regular
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
points | (ℝⁿ)ᵐ | List of Real Vectors | points of polygonal chain |
closed | true | false | Boolean Value | whether the polygonic chain is closed |
isEquilateral
Try to make the shape equilateral
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
points | (ℝⁿ)ᵐ | List of Real Vectors | points of polygonal chain |
closed | true | false | Boolean Value | whether the polygonic chain is closed |
isEquiangular
Try to make the shape equiangular
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
points | (ℝⁿ)ᵐ | List of Real Vectors | points of polygonal chain |
closed | true | false | Boolean Value | whether the polygonic chain is closed |
Computation Functions
makePath
See https://github.com/penrose/penrose/issues/716
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
start | ℝ² | 2d Vector of Reals | Start point of the path |
end | ℝ² | 2d Vector of Reals | End point of the path |
curveHeight | ℝ | Real Number | Height of the curve |
padding | ℝ | Real Number | Padding between the curve and the labels |
Returns: PathCmd (Path Command)
get
Return i
th element of list `xs, assuming lists only hold floats.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
xs | ℝⁿ | Vector of Reals | List of floats |
i | ℕ | Natural Number | Index of the element to return |
Returns: ℝ (Real Number)
rgba
Return a paint color of elements r
, g
, b
, a
(red, green, blue, opacity).
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
r | [0,1] | Real Number in Unit Interval | Red |
g | [0,1] | Real Number in Unit Interval | Green |
b | [0,1] | Real Number in Unit Interval | Blue |
a | [0,1] | Real Number in Unit Interval | Opacity |
Returns: Color (Color)
selectColor
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
color1 | Color | Color | First color |
color2 | Color | Color | Second color |
level | ℝ | Real Number | Level |
Returns: Color (Color)
hsva
Return a paint color of elements h
, s
, v
, a
(hue, saturation, value, opacity).
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
h | ℝ | Real Number | Hue in [0, 360) |
s | ℝ | Real Number | Saturation in [0, 100] |
v | ℝ | Real Number | Value in [0, 100] |
a | [0,1] | Real Number in Unit Interval | Opacity |
Returns: Color (Color)
acosh
Return acosh(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
acos
Return acos(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
asin
Return asin(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
asinh
Return asinh(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
atan
Return atan(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
atan2
Return atan2(x, y)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
y | ℝ | Real Number | `y` |
Returns: ℝ (Real Number)
atanh
Return atanh(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
cbrt
Return cbrt(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
ceil
Return ceil(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
cos
Return cos(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
cosh
Return cosh(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
exp
Return exp(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
expm1
Return expm1(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
floor
Return floor(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
log
Return log(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
log2
Return log2(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
log10
Return log10(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
log1p
Return log1p(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
pow
Return pow(x, y)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
y | ℝ | Real Number | `y` |
Returns: ℝ (Real Number)
round
Return round(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
sign
Return sign(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
sin
Return sin(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
sinh
Return sinh(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
tan
Return tan(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
tanh
Return tanh(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
trunc
Return trunc(x)
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
sum
Return the sum of elements in a vector.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
xs | ℝⁿ | Vector of Reals | elements |
Returns: ℝ (Real Number)
sumVectors
Return the sum of vectors in a list of vectors.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
vecs | (ℝⁿ)ᵐ | List of Real Vectors | vectors |
Returns: ℝⁿ (Vector of Reals)
maxList
Return the maximum of the elements in a vector.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
xs | ℝⁿ | Vector of Reals | elements |
Returns: ℝ (Real Number)
minList
Return the minimum of the elements in a vector.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
xs | ℝⁿ | Vector of Reals | elements |
Returns: ℝ (Real Number)
count
Return the number of the elements in a vector.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
xs | ℝⁿ | Vector of Reals | elements |
Returns: ℝ (Real Number)
dot
Return the dot product of v
and w
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
v | ℝⁿ | Vector of Reals | Vector `v` |
w | ℝⁿ | Vector of Reals | Vector `w` |
Returns: ℝ (Real Number)
outerProduct
Return the outer product of v
and w
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
v | ℝⁿ | Vector of Reals | Vector `v` |
w | ℝⁿ | Vector of Reals | Vector `w` |
Returns: (ℝⁿ)ᵐ (List of Real Vectors)
length
Return the length of the Line shape.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
l | LineShape | Line Shape | A line |
Returns: ℝ (Real Number)
normalize
Return the normalized version of vector v
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
v | ℝⁿ | Vector of Reals | Vector `v` |
Returns: ℝⁿ (Vector of Reals)
pathFromPoints
Given a list of points pts
, returns a PathData
that can be used as input to the Path
shape's pathData
attribute to be drawn on the screen.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
pathType | "open" | "closed" | Path Type | Path Type |
pts | (ℝ²)ⁿ | List of 2d Real Vectors | List of points |
Returns: PathCmd (Path Command)
quadraticCurveFromPoints
Given a list of points pts
, returns a PathData
that can be used as input to the Path
shape's pathData
attribute to be drawn on the screen.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
pathType | "open" | "closed" | Path Type | Path Type |
pts | (ℝ²)ⁿ | List of 2d Real Vectors | List of points |
Returns: PathCmd (Path Command)
interpolateQuadraticFromPoints
Draw a curve interpolating three given points. (Note that this is different from specifying the three control points of a quadratic Bézier curve, since a Bézier does not interpolate the middle control point.)
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
pathType | "open" | "closed" | Path Type | Path Type |
p0 | ℝ² | 2d Vector of Reals | First point |
p1 | ℝ² | 2d Vector of Reals | Second point |
p2 | ℝ² | 2d Vector of Reals | Third point |
Returns: PathCmd (Path Command)
cubicCurveFromPoints
Given a list of points pts
, returns a PathData
that can be used as input to the Path
shape's pathData
attribute to be drawn on the screen.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
pathType | "open" | "closed" | Path Type | Path type |
pts | (ℝ²)ⁿ | List of 2d Real Vectors | List of points |
Returns: PathCmd (Path Command)
unitMark
Return two points parallel to line s1
using its normal line s2
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s1 | LineShape | Line Shape | |
s2 | LineShape | Line Shape | |
padding | ℝ | Real Number |
Returns: (ℝ²)ⁿ (List of 2d Real Vectors)
unitMark2
Return two points to "cap off" the line made in unitMark
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
[start, end] | (ℝ²)ⁿ | List of 2d Real Vectors | |
t | String | String | |
size | ℝ | Real Number |
Returns: (ℝ²)ⁿ (List of 2d Real Vectors)
arc
Return series of elements that can render an arc SVG. See: https://css-tricks.com/svg-path-syntax-illustrated-guide/ for the "A" spec. Returns elements that can be passed to Path shape spec to render an SVG arc.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
pathType | "open" | "closed" | Path Type | The path type: either "open" or "closed." whether the SVG should automatically draw a line between the final point and the start point |
start | ℝ² | 2d Vector of Reals | coordinate to start drawing the arc |
end | ℝ² | 2d Vector of Reals | coordinate to finish drawing the arc |
[width, height] | ℝ² | 2d Vector of Reals | width and height of the ellipse to draw the arc along |
rotation | ℝ | Real Number | angle in degrees to rotate ellipse about its center |
largeArc | ℝ | Real Number | 0 to draw shorter of 2 arcs, 1 to draw longer |
arcSweep | ℝ | Real Number | 0 to rotate CCW, 1 to rotate CW |
Returns: PathCmd (Path Command)
repeatedArcs
Generate multiple concentric arcs. Useful for denoting equal angles.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
innerStart | ℝ² | 2d Vector of Reals | coordinate to start drawing the inner arc |
innerEnd | ℝ² | 2d Vector of Reals | coordinate to end the inner arc |
outerStart | ℝ² | 2d Vector of Reals | coordinate to start drawing the outer arc |
outerEnd | ℝ² | 2d Vector of Reals | coordinate to end the outer arc |
innerRadius | ℝ² | 2d Vector of Reals | radii of the ellipse to draw the inner arc along (width, height) |
repeat | ℤ⁺ | Positive Integer | number of times to repeat the arc |
spacing | ℝ | Real Number | spacing between arcs |
arcSweep | ℝ | Real Number | arc length to sweep |
Returns: PathCmd (Path Command)
wedge
Return series of elements that render a "wedge", which is the same as the arc above except that it's connected to the circle center and filled. Returns elements that can be passed to Path shape spec to render an SVG arc.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
center | ℝ² | 2d Vector of Reals | center of the circle on which the arc sits |
start | ℝ² | 2d Vector of Reals | coordinate to start drawing the arc |
end | ℝ² | 2d Vector of Reals | coordinate to finish drawing the arc |
radius | ℝ² | 2d Vector of Reals | width and height of the ellipse to draw the arc along (i.e. [width, height]) |
rotation | ℝ | Real Number | angle in degrees to rotate ellipse about its center |
largeArc | ℝ | Real Number | 0 to draw shorter of 2 arcs, 1 to draw longer |
arcSweep | ℝ | Real Number | 0 to rotate CCW, 1 to rotate CW |
Returns: PathCmd (Path Command)
ptOnLine
Find the point that is located at dist r along a line between p1 and p2. Returns vector representation of the point of intersection.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
p1 | ℝⁿ | Vector of Reals | start point of line segment |
p2 | ℝⁿ | Vector of Reals | endpoint of line segment |
r | ℝ | Real Number | distance from p1 to travel along the line |
Returns: ℝⁿ (Vector of Reals)
arcSweepFlag
Return 0 if direction of rotation is CCW, 1 if direction of rotation is CW.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
[x1, y1] | ℝ² | 2d Vector of Reals | x, y coordinates of the circle/ellipse that the arc is drawn on |
start | ℝ² | 2d Vector of Reals | start point of the arc |
end | ℝ² | 2d Vector of Reals | end point of the arc |
Returns: ℝ (Real Number)
angleBetween
Return the unsigned angle between vectors u, v
, in radians. Assumes that both u and v have nonzero magnitude. The returned value will be in the range [0,pi].
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
u | ℝⁿ | Vector of Reals | A vector |
v | ℝⁿ | Vector of Reals | A vector |
Returns: ℝ (Real Number)
angleFrom
Return the signed angle from vector u
to vector v
, in radians. Assumes that both u and v are 2D vectors and have nonzero magnitude. The returned value will be in the range [-pi,pi].
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
u | ℝⁿ | Vector of Reals | A vector |
v | ℝⁿ | Vector of Reals | A vector |
Returns: ℝ (Real Number)
cross2D
Return the 2D cross product of u
and v
, equal to the determinant of the 2x2 matrix [u v]
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
u | ℝ² | 2d Vector of Reals | A vector |
v | ℝ² | 2d Vector of Reals | A vector |
Returns: ℝ (Real Number)
cross
Return the 3D cross product of 3D vectors u
and v
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
u | ℝ³ | 3d Vector of Reals | A vector |
v | ℝ³ | 3d Vector of Reals | A vector |
Returns: ℝ³ (3d Vector of Reals)
lineLineIntersection
Return the intersection of a line passing through a0
and a1
with a line passing through b0
and b1
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
a0 | ℝ² | 2d Vector of Reals | First point of first line |
a1 | ℝ² | 2d Vector of Reals | Second point of first line |
b0 | ℝ² | 2d Vector of Reals | First point of second line |
b1 | ℝ² | 2d Vector of Reals | Second point of second line |
Returns: ℝ² (2d Vector of Reals)
midpoint
Return a point located at the midpoint between pts start
and end
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
start | ℝⁿ | Vector of Reals | First point |
end | ℝⁿ | Vector of Reals | Second point |
Returns: ℝⁿ (Vector of Reals)
midpointOffset
Return a point located at the midpoint of a line s1
but offset by padding
in its normal direction (for labeling).
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s1 | LineShape | Line Shape | A line |
padding | ℝ | Real Number | Padding between midpoint and label |
Returns: ℝ² (2d Vector of Reals)
chevron
Return a list of points for a chevron shape comprised of two line segments intersecting at a right angle at the midpoint of s1
, which can then be passed to pathFromPoints
to draw the chevron.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s1 | LineShape | Line Shape | A line |
padding | ℝ | Real Number | Length of each line segment |
Returns: (ℝ²)ⁿ (List of 2d Real Vectors)
innerPointOffset
Return a point located at padding
of a line s1
offset by padding
in its normal direction (for making right angle markers).
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
pt1 | ℝ² | 2d Vector of Reals | First point |
pt2 | ℝ² | 2d Vector of Reals | Second point |
pt3 | ℝ² | 2d Vector of Reals | Third point |
padding | ℝ | Real Number | Offset from line to returned point |
Returns: ℝ² (2d Vector of Reals)
ticksOnLine
Create equally spaced tick marks centered at the midpoint of a line
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
pt1 | ℝ² | 2d Vector of Reals | starting point of a line |
pt2 | ℝ² | 2d Vector of Reals | ending point of a line |
spacing | ℝ | Real Number | space in px between each tick |
numTicks | ℤ⁺ | Positive Integer | number of tick marks to create |
tickLength | ℝ | Real Number | 1/2 length of each tick |
Returns: PathCmd (Path Command)
orientedSquare
Given two orthogonal segments that intersect at intersection
, and a size len
return a path comprised of three points that describe a perpendicular mark at the angle where the segments intersect.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s1 | LineShape | Line Shape | First line segment |
s2 | LineShape | Line Shape | Second line segment |
intersection | ℝ² | 2d Vector of Reals | Point of intersection |
len | ℝ | Real Number | Side length of square marker |
Returns: PathCmd (Path Command)
triangle
Given three lines l1, l2, l3
that already form a triangle, return a path that describes the triangle (which can then be filled, etc.).
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
l1 | LineShape | Line Shape | First line |
l2 | LineShape | Line Shape | Second line |
l3 | LineShape | Line Shape | Third line |
Returns: PathCmd (Path Command)
average2
Return the average of floats x
and y
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
y | ℝ | Real Number | `y` |
Returns: ℝ (Real Number)
average
Return the average of the floats in the list xs
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
xs | ℝⁿ | Vector of Reals | `xs` |
Returns: ℝ (Real Number)
unit
Return the normalized version of vector v
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
v | ℝⁿ | Vector of Reals | `v` |
Returns: ℝⁿ (Vector of Reals)
random
Uniformly sample a random value in the range from minVal
to maxVal
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
minVal | ℝ | Real Number | minimum value |
maxVal | ℝ | Real Number | maximum value |
Returns: ℝ (Real Number)
normalRandom
Sample a normal distribution with mean 0 and standard deviation 1.
Returns: ℝ (Real Number)
triangleRandom
Sample a point from the uniform distribution over a triangle with vertices a
, b
, and c
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
a | ℝ² | 2d Vector of Reals | First vertex |
b | ℝ² | 2d Vector of Reals | Second vertex |
c | ℝ² | 2d Vector of Reals | Third vertex |
Returns: ℝⁿ (Vector of Reals)
sampleColor
Sample a random color once, with opacity alpha
and color type colorType
("rgb"
or "hsv"
).
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
alpha | [0,1] | Real Number in Unit Interval | Opacity |
colorType | "rgb" | "hsv" | Color Type | Color model |
Returns: Color (Color)
setOpacity
Set the opacity of a color color
to frac
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
color | Color | Color | Color |
frac | [0,1] | Real Number in Unit Interval | Opacity |
Returns: Color (Color)
mul
Multiply a matrix m
and a vector v
(where v
is implicitly treated as a column vector).
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
m | (ℝⁿ)ᵐ | List of Real Vectors | A matrix |
v | ℝⁿ | Vector of Reals | A vector |
Returns: ℝⁿ (Vector of Reals)
barycenter
Return the barycenter of the triangle with vertices a
, b
, c
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
a | ℝ² | 2d Vector of Reals | First vertex |
b | ℝ² | 2d Vector of Reals | Second vertex |
c | ℝ² | 2d Vector of Reals | Third vertex |
Returns: ℝ² (2d Vector of Reals)
circumcenter
Return the circumcenter of the triangle with vertices p
, q
, r
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
p | ℝ² | 2d Vector of Reals | First vertex |
q | ℝ² | 2d Vector of Reals | Second vertex |
r | ℝ² | 2d Vector of Reals | Third vertex |
Returns: ℝ² (2d Vector of Reals)
circumradius
Return the circumradius of the triangle with vertices p
, q
, r
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
p | ℝ² | 2d Vector of Reals | First vertex |
q | ℝ² | 2d Vector of Reals | Second vertex |
r | ℝ² | 2d Vector of Reals | Third vertex |
Returns: ℝ (Real Number)
incenter
Return the incenter of the triangle with vertices p
, q
, r
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
p | ℝ² | 2d Vector of Reals | First vertex |
q | ℝ² | 2d Vector of Reals | Second vertex |
r | ℝ² | 2d Vector of Reals | Third vertex |
Returns: ℝ² (2d Vector of Reals)
inradius
Return the inradius of the triangle with vertices p
, q
, r
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
p | ℝ² | 2d Vector of Reals | First vertex |
q | ℝ² | 2d Vector of Reals | Second vertex |
r | ℝ² | 2d Vector of Reals | Third vertex |
Returns: ℝ (Real Number)
sqr
Return the square of the number x
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
sqrt
Return the square root of number x
. (Note: if x < 0
you may get NaN
s)
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
max
Return the max of the numbers x
, y
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
y | ℝ | Real Number | `y` |
Returns: ℝ (Real Number)
min
Return the min of the numbers x
, y
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
y | ℝ | Real Number | `y` |
Returns: ℝ (Real Number)
abs
Return the absolute value of the number x
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
x | ℝ | Real Number | `x` |
Returns: ℝ (Real Number)
toRadians
Convert the angle theta
from degrees to radians.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
theta | ℝ | Real Number | `theta` |
Returns: ℝ (Real Number)
toDegrees
Convert the angle theta
from radians to degrees.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
theta | ℝ | Real Number | `theta` |
Returns: ℝ (Real Number)
norm
Return the Euclidean norm of the vector v
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
v | ℝⁿ | Vector of Reals | A vector |
Returns: ℝ (Real Number)
normsq
Return the Euclidean norm squared of the vector v
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
v | ℝⁿ | Vector of Reals | A vector |
Returns: ℝ (Real Number)
vdist
Return the Euclidean distance between the vectors v
and w
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
v | ℝⁿ | Vector of Reals | A vector |
w | ℝⁿ | Vector of Reals | A vector |
Returns: ℝ (Real Number)
vmul
Returns the scalar-vector product.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s | ℝ | Real Number | A scalar |
v | ℝⁿ | Vector of Reals | A vector |
Returns: ℝⁿ (Vector of Reals)
vdistsq
Return the Euclidean distance squared between the vectors v
and w
.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
v | ℝⁿ | Vector of Reals | A vector |
w | ℝⁿ | Vector of Reals | A vector |
Returns: ℝ (Real Number)
angleOf
Return the angle made by the vector v
with the positive x-axis.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
v | ℝⁿ | Vector of Reals | A vector |
Returns: ℝ (Real Number)
rot90
Rotate a 2D vector v
by 90 degrees counterclockwise.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
v | ℝ² | 2d Vector of Reals | A vector |
Returns: ℝ² (2d Vector of Reals)
rotateBy
Rotate a 2D vector v
by theta degrees counterclockwise.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
v | ℝ² | 2d Vector of Reals | A vector |
theta | ℝ | Real Number | degrees to rotate counterclockwise |
Returns: ℝ² (2d Vector of Reals)
signedDistance
Return the signed distance between a shape and a point
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s | EquationShape | ImageShape | RectangleShape | TextShape | CircleShape | PolygonShape | LineShape | PolylineShape | any of: any of: Equation Shape, or Image Shape, or Rectangle Shape, or Text Shape, or Circle Shape, or Polygon Shape, or Line Shape, or Polyline Shape | A shape |
p | ℝ² | 2d Vector of Reals | A point |
Returns: ℝ (Real Number)
unitVector
Construct a unit vector u in the direction of the given angle theta (in radians).
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
theta | ℝ | Real Number | direction |
Returns: ℝ² (2d Vector of Reals)
rayIntersect
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
S | EquationShape | ImageShape | RectangleShape | TextShape | CircleShape | PolygonShape | LineShape | PolylineShape | EllipseShape | GroupShape | any of: any of: Equation Shape, or Image Shape, or Rectangle Shape, or Text Shape, or Circle Shape, or Polygon Shape, or Line Shape, or Polyline Shape, or Ellipse Shape, or Group Shape | A shape |
p | ℝ² | 2d Vector of Reals | A point |
v | ℝ² | 2d Vector of Reals | A vector |
Returns: ℝ² (2d Vector of Reals)
rayIntersectNormal
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
S | EquationShape | ImageShape | RectangleShape | TextShape | CircleShape | PolygonShape | LineShape | PolylineShape | EllipseShape | GroupShape | any of: any of: Equation Shape, or Image Shape, or Rectangle Shape, or Text Shape, or Circle Shape, or Polygon Shape, or Line Shape, or Polyline Shape, or Ellipse Shape, or Group Shape | A shape |
p | ℝ² | 2d Vector of Reals | A point |
v | ℝ² | 2d Vector of Reals | A vector |
Returns: ℝ² (2d Vector of Reals)
closestPoint
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s | EquationShape | ImageShape | RectangleShape | TextShape | CircleShape | PolygonShape | LineShape | PolylineShape | EllipseShape | GroupShape | any of: any of: Equation Shape, or Image Shape, or Rectangle Shape, or Text Shape, or Circle Shape, or Polygon Shape, or Line Shape, or Polyline Shape, or Ellipse Shape, or Group Shape | A shape |
p | ℝ² | 2d Vector of Reals | A point |
Returns: ℝ² (2d Vector of Reals)
closestSilhouettePoint
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s | EquationShape | ImageShape | RectangleShape | TextShape | CircleShape | PolygonShape | LineShape | PolylineShape | EllipseShape | GroupShape | any of: any of: Equation Shape, or Image Shape, or Rectangle Shape, or Text Shape, or Circle Shape, or Polygon Shape, or Line Shape, or Polyline Shape, or Ellipse Shape, or Group Shape | A shape |
p | ℝ² | 2d Vector of Reals | A point |
Returns: ℝ² (2d Vector of Reals)
rectLineDist
Return the distance between a rectangle (defined using the bottom-left and top-right points) and a line (defined using start and end points)
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
bottomLeft | ℝ² | 2d Vector of Reals | bottom-left point of rectangle |
topRight | ℝ² | 2d Vector of Reals | top-right point of rectangle |
start | ℝ² | 2d Vector of Reals | start point of line |
end | ℝ² | 2d Vector of Reals | end point of line |
Returns: ℝ (Real Number)
shapeDistance
Return the distance between two shapes.
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
s1 | Shape | Any Shape | a shape |
s2 | Shape | Any Shape | a shape |
Returns: ℝ (Real Number)
signedArea
Returns the signed area enclosed by a polygonal chain given its nodes
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
points | (ℝⁿ)ᵐ | List of Real Vectors | points of polygonal chain |
closed | true | false | Boolean Value | whether the polygonic chain is closed |
Returns: ℝ (Real Number)
turningNumber
Returns the turning number of polygonal chain given its nodes
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
points | (ℝⁿ)ᵐ | List of Real Vectors | points of polygonal chain |
closed | true | false | Boolean Value | whether the polygonic chain is closed |
Returns: ℝ (Real Number)
perimeter
Returns the total length of polygonal chain given its nodes
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
points | (ℝⁿ)ᵐ | List of Real Vectors | points of polygonal chain |
closed | true | false | Boolean Value | whether the polygonic chain is closed |
Returns: ℝ (Real Number)
isoperimetricRatio
Returns the isoperimetric ratio (perimeter squared divided by enclosed area)
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
points | (ℝⁿ)ᵐ | List of Real Vectors | points of curve |
closed | true | false | Boolean Value | whether the curve is closed |
Returns: ℝ (Real Number)
elasticEnergy
Returns integral of curvature squared along the curve
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
points | (ℝⁿ)ᵐ | List of Real Vectors | points of curve |
closed | true | false | Boolean Value | whether curve is closed |
Returns: ℝ (Real Number)
totalCurvature
Returns integral of curvature along the curve
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
points | (ℝⁿ)ᵐ | List of Real Vectors | points of curve |
closed | true | false | Boolean Value | whether curve is closed |
signed | true | false | Boolean Value | whether curvature is signed |
Returns: ℝ (Real Number)
lengthK
Returns the sum of all line segment lengths raised to k
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
points | (ℝⁿ)ᵐ | List of Real Vectors | points of curve |
closed | true | false | Boolean Value | whether curve is closed |
k | ℝ | Real Number | exponent for line segments |
Returns: ℝ (Real Number)
maxCurvature
Returns the maximum value of curvature along the curve
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
points | (ℝⁿ)ᵐ | List of Real Vectors | points of curve |
closed | true | false | Boolean Value | whether curve is closed |
Returns: ℝ (Real Number)
pElasticEnergy
Returns integral of curvature raised to p
along the curve
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
points | (ℝⁿ)ᵐ | List of Real Vectors | points of curve |
closed | true | false | Boolean Value | whether curve is closed |
p | ℝ | Real Number | exponent for curvature |
Returns: ℝ (Real Number)
inflectionEnergy
Returns integral of curvature derivative raised to p
along the curve
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
points | (ℝⁿ)ᵐ | List of Real Vectors | points of curve |
closed | true | false | Boolean Value | whether curve is closed |
p | ℝ | Real Number | exponent for curvature derivative |
Returns: ℝ (Real Number)
centerOfMass
Returns center of mass for a 2D point cloud
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
points | (ℝ²)ⁿ | List of 2d Real Vectors | points of curve |
Returns: ℝ² (2d Vector of Reals)
clip
Describes clipping to a shape
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
shape | Shape | Any Shape |
Returns: ClipData (Shape clip data)
bboxPts
Return the top-right, top-left, bottom-left, bottom-right points (in that order) of the axis-aligned bounding box of the shape
Parameters:
Name | Type | Type Description | Description |
---|---|---|---|
shape | Shape | Any Shape |