Skip to content

Shapes

Package name: jitx/shapes

Board Outline Example

val outline = RoundedRectangle(10.0, 5.0, 1.0)
set-board(default-board(4, outline))
;Sets the board outline to a rounded rectangle of dimensions 10 x 5 and corner
;radius 1.0

Summary

Data Types

PolygonWithArcs

Polygon With Arcs

Functions

Function Description
to-polygon Create a polygon approximation of the polygon with arcs.
PolygonWithArcs Create a polygon with arcs from a sequence of points, arcs, and/or other nested sequences.
outline Create a polyline which traces the outline of the polygon with arcs.
to-polygon-with-arcs (+ 4) Create a polygon with arcs equivalent to the circle.

TextKind

Enum of text shape kinds

Shape

Shape

Multis

Function Description
area Return the area of the shape.
upper-extend
lower-extend

Functions

Function Description
Polyline Create a polyline from a sequence of points, arcs, and/or other nested sequences of points and/or arcs.
PolygonWithArcs Create a polygon with arcs from a sequence of points, arcs, and/or other nested sequences.
subshapes Generate a sequence of all subshapes of the given shape.
Line Create a line from a sequence of points and/or other nested sequences of points.
Union Create a union shape from a sequence of shapes and/or other nested sequences.

Dims

Dimensions

Constructors

Function Description
Dims Constructor for defstruct Dims

Functions

Function Description
transpose Create the dimensions which swap the X and Y dimensions of a.
enlarge Create the dimensions which are the dimensions of a multiplied by b.
min Create the dimensions which are the minimum for each dimension of a and b.
max Create the dimensions which are the maximum for each dimension of a and b.
Rectangle Create a rectangle using Dims to specify the rectangle's dimensions.

Operators

Function Op. Description
plus + Create the dimensions which are the sum of each dimension of a and b.

Capsule

Capsule

Constructors

Function Description
Capsule Constructor for defstruct Capsule

Functions

Function Description
outline Create a line which traces the outline of the capsule.
to-polygon-with-arcs Create a polygon with arcs equivalent to the capsule.
axis-aligned? Return true if the shape's pose angle is aligned with the X or Y axis.
to-polygon Create a polygon approximation of the capsule with approximately the given number of points.
Capsule Create a capsule anchored to a specified alignment with respect to the origin.
normalize Create an equivalent capsule with pose angle 0.0 for the given axis-aligned capsule.

Text

Text

Constructors

Function Description
Text Constructor for defstruct Text

Functions

Function Description
outline

ChamferedRectangle

Chamfered Rectangle

Constructors

Function Description
ChamferedRectangle Constructor for defstruct ChamferedRectangle

Functions

Function Description
to-polygon Create a polygon equivalent of the chamfered rectangle.
outline Create a line which traces the outline of the chamfered rectangle.
normalize Create an equivalent chamfered rectangle with pose angle 0.0 for the given axis-aligned chamfered rectangle.
ChamferedRectangle Create a chamfered rectangle anchored to a specified alignment with respect to the origin.
axis-aligned? Return true if the shape's pose angle is aligned with the X or Y axis.

Rectangle

Rectangle

Constructors

Function Description
Rectangle Constructor for defstruct Rectangle

Functions

Function Description
outline Create a line which traces the outline of the rectangle.
sw Retrieve the lower-left corner point of the rectangle.
ne Retrieve the upper-right corner point of the rectangle.
axis-aligned? Return true if the shape's pose angle is aligned with the X or Y axis.
to-polygon Create a polygon equivalent to the rectangle.
normalize Create an equivalent rectangle with pose angle 0.0 for the given axis-aligned rectangle.
Rectangle (+ 2) Create a rectangle using Dims to specify the rectangle's dimensions.

Centerable

Centerable

Multis

Function Description
angle
center

Segment

Line Segment

Constructors

Function Description
Segment Constructor for defstruct Segment

Functions

Function Description
center Find the midpoint of the segment.
angle-degrees Calculate the angle of the vector.
length Calculate the length of the segment.

Line

Line

Functions

Function Description
to-polygon Create a polygon equivalent of the FIRST SEGMENT of the line.
outline
Line Create a line from a sequence of points and/or other nested sequences of points.
to-line Create a line which approximately traces given arc.

GeneralChamferedRectangle

Chamfered Rectangle

Constructors

Function Description
GeneralChamferedRectangle Constructor for defstruct GeneralChamferedRectangle

Functions

Function Description
to-polygon Create a polygon equivalent of the general chamfered rectangle.
outline Create a line which traces the outline of the general chamfered rectangle.
GeneralChamferedRectangle (+ 2) Create a general chamfered rectangle using a CornerModifier to specify which corners are chamfered.
axis-aligned? Return true if the shape's pose angle is aligned with the X or Y axis.

Polygon

Polygon

Functions

Function Description
circle-points Create a polygon consisting of points along an arc of a circle.
to-polygon (+ 8) Create a polygon equivalent to the rectangle.
outline Create a line which traces the outline of the given polygon.
Polygon Create a polygon from a sequence of points and/or other nested sequences of points.

Difference

Difference

Constructors

Function Description
Difference Constructor for defstruct Difference

Polyline

Polyline

Functions

Function Description
Polyline Create a polyline from a sequence of points, arcs, and/or other nested sequences of points and/or arcs.
to-polygon Create a polygon approximation of the polyline.
outline (+ 1) Create a polyline which traces the outline of the polygon with arcs.

RoundedRectangle

Rounded Rectangle

Constructors

Function Description
RoundedRectangle Constructor for defstruct RoundedRectangle

Functions

Function Description
outline Create a line which traces the outline of the rounded rectangle.
RoundedRectangle Create a rounded rectangle anchored to a specified alignment with respect to the origin.
to-polygon-with-arcs Create a polygon with arcs equivalent to the rounded rectangle.
axis-aligned? Return true if the shape's pose angle is aligned with the X or Y axis.
to-polygon Create a polygon approximation of the rounded rectangle.
normalize Create an equivalent rounded rectangle with pose angle 0.0 for the given axis-aligned rounded rectangle.

GeneralRoundedRectangle

General Rounded Rectangle

Constructors

Function Description
GeneralRoundedRectangle Constructor for defstruct GeneralRoundedRectangle

Functions

Function Description
to-polygon Create a polygon approximation of the general rounded rectangle.
outline Create a line which traces the outline of the general rounded rectangle.
GeneralRoundedRectangle (+ 2) Create a general rounded rectangle using a CornerModifier to specify which corners are rounded.
to-polygon-with-arcs Create a polygon with arcs equivalent to the general rounded rectangle.
axis-aligned? Return true if the shape's pose angle is aligned with the X or Y axis.

CornerModifier

Enum for general rounded rectangle corner combinations

Functions

Function Description
GeneralRoundedRectangle (+ 1) Create a general rounded rectangle using a CornerModifier to specify which corners are rounded.
GeneralChamferedRectangle (+ 1) Create a general chamfered rectangle using a CornerModifier to specify which corners are chamfered.

Union

Union

Functions

Function Description
Union Create a union shape from a sequence of shapes and/or other nested sequences.

Point

Point

Constructors

Function Description
Point Constructor for defstruct Point

Multis

Function Description
center

Functions

Function Description
iy The truncated integer value of the Y coordinate of the point.
Point Create a point from two integer coordinates.
min Create the point which is the result of taking the minimum coordinate along each axis of the coordinates of a and b.
max Create the point which is the result of taking the maximum coordinate along each axis of the coordinates of a and b.
center Find the midpoint of the segment.
get Retrieve the X or Y coordinate of the point, using an index to select which coordinate.
Polygon Create a polygon from a sequence of points and/or other nested sequences of points.
ix The truncated integer value of the X coordinate of the point.

Operators

Function Op. Description
minus - Create the point which is the result of subtracting the coordinates of b from the coordinates of a.
divide / Create the point which is the result of dividing the coordinates of a by n.
negate - Create the point with both coordinates negated of the given point.
plus + Create the point which is the result of adding the coordinates of a and b.
times * Create the point which is the result of multiplying the coordinates of a by n.

Circle

Circle

Constructors

Function Description
Circle Constructor for defstruct Circle

Functions

Function Description
to-polygon Create a polygon approximation of the circle with the given number of points.
Circle (+ 2) Create a circle using a center X coordinate, center Y coordinate, and radius.
outline Create a line which traces the outline of the circle.
to-polygon-with-arcs Create a polygon with arcs equivalent to the circle.

Arc

Arc

Constructors

Function Description
Arc Constructor for defstruct Arc

Functions

Function Description
to-polygon (+ 1) Create a polygon approximation of the arc.
outline Create a line which traces the outline of the arc.
Arc Create an arc, specifying the center with separate X and Y coordinate values instead of as a Point.
to-line Create a line which approximately traces given arc.
length Calculate the length of the arc.

EmptyShape

Empty Shape

Constructors

Function Description
EmptyShape Constructor for defstruct EmptyShape

DShape

D Shape

Constructors

Function Description
DShape Constructor for defstruct DShape

Functions

Function Description
to-polygon Create a polygon approximation of the D shape.
outline Create a line which traces the outline of the D shape.
to-polygon-with-arcs Create a polygon with arcs equivalent to the D shape.
DShape Create a D shape anchored to a specified alignment with respect to the origin.
axis-aligned? Return true if the shape's pose angle is aligned with the X or Y axis.

General Definitions

Function Description
iy The truncated integer value of the Y coordinate of the pose's center.
iangle The truncated integer value of the pose's angle.
angle-mod-90? Return true if the angle of the pose is an exact multiple of 90 degrees.
ix The truncated integer value of the X coordinate of the pose's center.

Definitions

PolygonWithArcs

Polygon With Arcs

public defstruct PolygonWithArcs <: Shape & HasMetaUtils :
    elements: Tuple<Point|Arc>

  • elements: Tuple<Point|Arc> - Elements of this polygon with arc's boundary in counter-clockwise order. Must have at least 3 points or 1 arc.

A polygon which may have sides which are circular arcs instead of line segments.

Specified with a tuple of elements (points or arcs) in counter-clockwise order. Must be non-degenerate (have at least 3 vertices or at least 1 arc) and non-self-intersecting. May be concave. The end point of each element is connected to the start point of the next element (a single point is its own start and end point). The last element is connected to the first element. The start and end points of arcs DO NOT need to also be included as standalone points in the elements tuple, doing so will result in duplicated points.

Functions

to-polygon

Create a polygon approximation of the polygon with arcs.

public defn to-polygon (p:PolygonWithArcs, num:Int)

  • p: PolygonWithArcs - The polygon with arcs to create the polygon approximation of.
  • num: Int - Controls the size of the sectors the arcs of the polygon with arcs are split into for approximation. There are num of the sectors in a whole circle.

PolygonWithArcs

Create a polygon with arcs from a sequence of points, arcs, and/or other nested sequences.

public defn PolygonWithArcs (elements:Seqable<Shape|Seqable>)

  • elements: Seqable<Shape|Seqable> - The sequence of points, arcs, and/or other nested sequences to make the polygon with arcs from.

The sequence is "flattened" first to create the tuple of points and arcs used.

outline

Create a polyline which traces the outline of the polygon with arcs.

public defn outline (p:PolygonWithArcs) -> Polyline

  • p: PolygonWithArcs - The polygon with arcs to create the outline of.
  • Returns Polyline

The polyline has width 0.0.

to-polygon-with-arcs

Create a polygon with arcs equivalent to the circle.

public defn to-polygon-with-arcs (c:Circle) -> PolygonWithArcs

  • c: Circle - The circle to create the polygon with arcs s equivalent of.
  • Returns PolygonWithArcs

to-polygon-with-arcs

Create a polygon with arcs equivalent to the capsule.

public defn to-polygon-with-arcs (c:Capsule) -> PolygonWithArcs

  • c: Capsule - The capsule to create the polygon with arcs equivalent of.
  • Returns PolygonWithArcs

May be clockwise-ordered if the capsule's pose is flipped.

to-polygon-with-arcs

Create a polygon with arcs equivalent to the D shape.

public defn to-polygon-with-arcs (d:DShape) -> PolygonWithArcs

  • d: DShape - The D shape to create the polygon with arcs equivalent of.
  • Returns PolygonWithArcs

May be clockwise-ordered if the D shape's pose is flipped.

to-polygon-with-arcs

Create a polygon with arcs equivalent to the rounded rectangle.

public defn to-polygon-with-arcs (r:RoundedRectangle) -> PolygonWithArcs

  • r: RoundedRectangle - The rounded rectangle to create the polygon with arcs equivalent of.
  • Returns PolygonWithArcs

May be clockwise-ordered if the rounded rectangle's pose is flipped.

to-polygon-with-arcs

Create a polygon with arcs equivalent to the general rounded rectangle.

public defn to-polygon-with-arcs (r:GeneralRoundedRectangle) -> PolygonWithArcs

  • r: GeneralRoundedRectangle - The general rounded rectangle to create the polygon with arcs equivalent of.
  • Returns PolygonWithArcs

May be clockwise-ordered if the general rounded rectangle 's pose is flipped.

TextKind

Enum of text shape kinds

public defenum TextKind <: Equalable & Hashable

  • StrokeFont

  • TrueTypeFont

  • BarCode

These follow Altium's definition of TextKind

Shape

Shape

public deftype Shape <: Equalable & Hashable & HasMetaUtils

Generic type which all shapes are a subtype of. Every shape has an area which can be calculated by calling area on the shape.

Multis

area

Return the area of the shape.

public defmulti area (sh:Shape) -> Double

  • Returns Double

upper-extend

public defmulti upper-extend (sh:Shape) -> Double

  • Returns Double

lower-extend

public defmulti lower-extend (sh:Shape) -> Double

  • Returns Double

Functions

Polyline

Create a polyline from a sequence of points, arcs, and/or other nested sequences of points and/or arcs.

public defn Polyline (width:Double, elements:Seqable<Shape|Seqable>)

  • elements: Seqable<Shape|Seqable> - The sequence of points, arcs, and/or other nested sequences to make the polyline from.

The sequence is "flattened" first to create the tuple of points and arcs used.

PolygonWithArcs

Create a polygon with arcs from a sequence of points, arcs, and/or other nested sequences.

public defn PolygonWithArcs (elements:Seqable<Shape|Seqable>)

  • elements: Seqable<Shape|Seqable> - The sequence of points, arcs, and/or other nested sequences to make the polygon with arcs from.

The sequence is "flattened" first to create the tuple of points and arcs used.

subshapes

Generate a sequence of all subshapes of the given shape.

public defn subshapes (s:Shape) -> Seq<Shape>

  • s: Shape - The shape whose subshapes to generate the sequence of.
  • Returns Seq<Shape>

Useful for iterating over subshapes of a union shape.

Line

Create a line from a sequence of points and/or other nested sequences of points.

public defn Line (width:Double, pts:Seqable<Shape|Seqable>)

  • pts: Seqable<Shape|Seqable> - The sequence of points and/or nested sequences of points to make the line from.

The sequence is "flattened" first to create the tuple of points used.

Union

Create a union shape from a sequence of shapes and/or other nested sequences.

public defn Union (elements:Seqable<Shape|Seqable>)

  • elements: Seqable<Shape|Seqable> - The sequence of shapes and/or other nested sequences to make the union shape from.

The sequence is "flattened" first to create the tuple of shapes used.

Dims

Dimensions

public defstruct Dims <: Equalable & Hashable :
    x: Double
    y: Double

  • x: Double - X-axis dimension Also known as width.

  • y: Double - Y-axis dimension Also known as length or height.

Specifies the horizontal and vertical extents of an object, usually a shape.

Constructors

Dims

Constructor for defstruct Dims

public defn Dims (x:Double, y:Double)

Functions

transpose

Create the dimensions which swap the X and Y dimensions of a.

public defn transpose (a:Dims) -> Dims

  • Returns Dims

enlarge

Create the dimensions which are the dimensions of a multiplied by b.

public defn enlarge (a:Dims, b:Double) -> Dims

  • Returns Dims

min

Create the dimensions which are the minimum for each dimension of a and b.

public defn min (a:Dims, b:Dims) -> Dims

  • Returns Dims

max

Create the dimensions which are the maximum for each dimension of a and b.

public defn max (a:Dims, b:Dims) -> Dims

  • Returns Dims

Rectangle

Create a rectangle using Dims to specify the rectangle's dimensions.

public defn Rectangle (d:Dims, p:Pose = ?)

  • d: Dims - Dimensions of the rectangle
  • p: Pose - Pose of the rectangle. Default is (0.0, 0.0) with no rotation and no flip.

Operators

plus +

Create the dimensions which are the sum of each dimension of a and b.

public defn plus (a:Dims, b:Dims) -> Dims

  • Returns Dims

Capsule

Capsule

public defstruct Capsule <: Shape & Centerable & HasMetaUtils :
    height: Double
    pose: Pose
    width: Double

  • height: Double - Height of this capsule. Must be non-negative.

  • pose: Pose - Pose of this capsule. Default value is (0.0, 0.0) with no rotation and no flip.

  • width: Double - Width of this capsule. Must be non-negative.

A pill-like shape.

Formed by rounding (filleting) the corners of a rectangle to a radius of half of the shorter dimension, such that the two corners on each short side merge into one semicircle. If the width and height are equal, the shape is a circle. The pose center is the center of the rectangle. The flip of the pose affects the ordering of the capsule's points when converted to a polygon (clockwise when flipped, otherwise counter-clockwise).

Constructors

Capsule

Constructor for defstruct Capsule

public defn Capsule (width:Double, height:Double, pose:Pose = ?)

Functions

outline

Create a line which traces the outline of the capsule.

public defn outline (r:Capsule)

  • r: Capsule - The capsule to create the approximate outline of.

The line has width 0.0, has exact line segments for the straight sides of the shape, and approximates the rounded portions of the shape with segments which are approximately 1/32 of a whole circle.

to-polygon-with-arcs

Create a polygon with arcs equivalent to the capsule.

public defn to-polygon-with-arcs (c:Capsule) -> PolygonWithArcs

  • c: Capsule - The capsule to create the polygon with arcs equivalent of.
  • Returns PolygonWithArcs

May be clockwise-ordered if the capsule's pose is flipped.

axis-aligned?

Return true if the shape's pose angle is aligned with the X or Y axis.

public defn axis-aligned? (r:Rectangle|Capsule|RoundedRectangle|ChamferedRectangle|DShape|GeneralRoundedRectangle|GeneralChamferedRectangle)

  • r: Rectangle|Capsule|RoundedRectangle|ChamferedRectangle|DShape|GeneralRoundedRectangle|GeneralChamferedRectangle - The shape to check the pose of.

to-polygon

Create a polygon approximation of the capsule with approximately the given number of points.

public defn to-polygon (c:Capsule, num:Int) -> Polygon

  • c: Capsule - The capsule to create the approximate equivalent polygon of.
  • num: Int - The approximate number of points to target for the returned polygon.
  • Returns Polygon

May be clockwise-ordered if the capsule's pose is flipped. Does not work well for num less than 3, and may give a polygon with up to num + 2 points.

Capsule

Create a capsule anchored to a specified alignment with respect to the origin.

public defn Capsule (anchor:Anchor, w:Double, h:Double)

  • anchor: Anchor - Anchor to align the capsule with to the origin.
  • w: Double - Width of the capsule.
  • h: Double - Height of the capsule.

The alignment is performed with respect to the rectangular component inside the capsule, and not the bounding box of the capsule.

normalize

Create an equivalent capsule with pose angle 0.0 for the given axis-aligned capsule.

public defn normalize (r:Capsule)

  • r: Capsule - The capsule to create the equivalent of.
  • Throws Error - if the capsule's pose angle is not axis-aligned.

Text

Text

public defstruct Text <: Shape & HasMetaUtils :
    anchor: Anchor
    font: String
    hide?: True|False
    pose: Pose
    size: Double
    string: String
    text-kind: TextKind
    type: Symbol|False

  • anchor: Anchor - The alignment of this text shape with the pose.

  • font: String - The name of the font use for this text shape.

  • hide?: True|False - Whether or not this text shape is hidden.

  • pose: Pose - The location and flippedness of this text shape.

  • size: Double - The height of each character in this text shape.

  • string: String - The actual character text of this text shape.

  • text-kind: TextKind - The kind of text of this text shape.

  • type: Symbol|False - The type of the text shape.

A shape consisting of alphabetical text of specified size and location.

Constructors

Text

Constructor for defstruct Text

public defn Text (string:String, size:Double, anchor:Anchor, pose:Pose, font:String = ?, text-kind:TextKind = ?, hide?:True|False = ?, type:Symbol|False = ?)

Functions

outline

public defn outline (t:Text)

ChamferedRectangle

Chamfered Rectangle

public defstruct ChamferedRectangle <: Shape & Centerable & HasMetaUtils :
    height: Double
    pose: Pose
    radius: Double
    width: Double

  • height: Double - Height of this chamfered rectangle. Must be non-negative.

  • pose: Pose - Pose of this chamfered rectangle. Default value is (0.0, 0.0) with no rotation and no flip.

  • radius: Double - Radius of the chamfered corners of this chamfered rectangle. Must be non-negative and at most half of the minimum of the width and height.

  • width: Double - Width of this chamfered rectangle. Must be non-negative.

A rectangle with chamfered corners.

All four corners are chamfered by the same amount. Has a width, height, chamfer radius and pose. The chamfer radius is the length of the two equal legs of the isosceles right triangle cut from each corner. The pose center is the center of the rectangle. The flip of the pose affects the ordering of the chamfered rectangle's points when converted to a polygon (clockwise when flipped, otherwise counter-clockwise).

Constructors

ChamferedRectangle

Constructor for defstruct ChamferedRectangle

public defn ChamferedRectangle (width:Double, height:Double, radius:Double, pose:Pose = ?)

Functions

to-polygon

Create a polygon equivalent of the chamfered rectangle.

public defn to-polygon (r:ChamferedRectangle) -> Polygon

  • r: ChamferedRectangle - The chamfered rectangle to create the equivalent polygon of.
  • Returns Polygon

May be clockwise-ordered if the chamfered rectangle's pose is flipped.

outline

Create a line which traces the outline of the chamfered rectangle.

public defn outline (r:ChamferedRectangle)

  • r: ChamferedRectangle - The chamfered rectangle to create the outline of.

The line has width 0.0.

normalize

Create an equivalent chamfered rectangle with pose angle 0.0 for the given axis-aligned chamfered rectangle.

public defn normalize (r:ChamferedRectangle)

  • r: ChamferedRectangle - The chamfered rectangle to create the equivalent of.
  • Throws Error - if the chamfered rectangle's pose angle is not axis-aligned.

ChamferedRectangle

Create a chamfered rectangle anchored to a specified alignment with respect to the origin.

public defn ChamferedRectangle (anchor:Anchor, w:Double, h:Double, r:Double)

  • anchor: Anchor - Anchor to align the chamfered rectangle with to the origin.
  • w: Double - Width of the chamfered rectangle.
  • h: Double - Height of the chamfered rectangle.
  • r: Double - Corner chamfer radius of the chamfered rectangle.

The alignment is performed with respect to the un-chamfered rectangular bounding box of the chamfered rectangle.

axis-aligned?

Return true if the shape's pose angle is aligned with the X or Y axis.

public defn axis-aligned? (r:Rectangle|Capsule|RoundedRectangle|ChamferedRectangle|DShape|GeneralRoundedRectangle|GeneralChamferedRectangle)

  • r: Rectangle|Capsule|RoundedRectangle|ChamferedRectangle|DShape|GeneralRoundedRectangle|GeneralChamferedRectangle - The shape to check the pose of.

Rectangle

Rectangle

public defstruct Rectangle <: Shape & Centerable & HasMetaUtils :
    height: Double
    pose: Pose
    width: Double

  • height: Double - Height of this rectangle. Must be non-negative.

  • pose: Pose - Pose of this rectangle. Default value is (0.0, 0.0) with no rotation and no flip.

  • width: Double - Width of this rectangle. Must be non-negative.

A rectangle with a width, height, and pose.

The pose center is the center of the rectangle. May be non-axis-aligned if the pose has non-zero rotation angle. The flip of the pose affects the ordering of the rectangle's points when converted to a polygon (clockwise when flipped, otherwise counter-clockwise).

Constructors

Rectangle

Constructor for defstruct Rectangle

public defn Rectangle (width:Double, height:Double, pose:Pose = ?)

Functions

outline

Create a line which traces the outline of the rectangle.

public defn outline (r:Rectangle)

  • r: Rectangle - The rectangle to create the outline of.

sw

Retrieve the lower-left corner point of the rectangle.

public defn sw (r:Rectangle)

  • r: Rectangle - The rectangle to retrieve the lower-left corner point of.

ne

Retrieve the upper-right corner point of the rectangle.

public defn ne (r:Rectangle)

  • r: Rectangle - The rectangle to retrieve the bottom-left corner point of.

axis-aligned?

Return true if the shape's pose angle is aligned with the X or Y axis.

public defn axis-aligned? (r:Rectangle|Capsule|RoundedRectangle|ChamferedRectangle|DShape|GeneralRoundedRectangle|GeneralChamferedRectangle)

  • r: Rectangle|Capsule|RoundedRectangle|ChamferedRectangle|DShape|GeneralRoundedRectangle|GeneralChamferedRectangle - The shape to check the pose of.

to-polygon

Create a polygon equivalent to the rectangle.

public defn to-polygon (r:Rectangle) -> Polygon

  • r: Rectangle - The rectangle to create the equivalent polygon of.
  • Returns Polygon

May be clockwise-ordered if the rectangle's pose is flipped.

normalize

Create an equivalent rectangle with pose angle 0.0 for the given axis-aligned rectangle.

public defn normalize (r:Rectangle)

  • r: Rectangle - The rectangle to create the equivalent of.
  • Throws Error - if the rectangle's pose angle is not axis-aligned.

Rectangle

Create a rectangle using Dims to specify the rectangle's dimensions.

public defn Rectangle (d:Dims, p:Pose = ?)

  • d: Dims - Dimensions of the rectangle
  • p: Pose - Pose of the rectangle. Default is (0.0, 0.0) with no rotation and no flip.

Rectangle

Create a rectangle anchored to a specified alignment with respect to the origin.

public defn Rectangle (anchor:Anchor, w:Double, h:Double)

  • anchor: Anchor - Anchor to align the rectangle with to the origin.
  • w: Double - Width of the rectangle.
  • h: Double - Height of the rectangle.

Rectangle

Create a rectangle with the coordinates of its bottom-left and upper-right points.

public defn Rectangle (x1:Double, y1:Double, x2:Double, y2:Double)

  • x1: Double - X coordinate of the bottom-left corner of the rectangle.
  • y1: Double - Y coordinate of the bottom-left corner of the rectangle.
  • x2: Double - X coordinate of the upper-right corner of the rectangle.
  • y2: Double - Y coordinate of the upper-right corner of the rectangle.

Centerable

Centerable

public deftype Centerable

Shapes which are subtypes of this type have a defined center point and pose angle, which can be obtained by calling the center and angle functions, respectively, on the shape.

Multis

angle

public defmulti angle (sh:Centerable) -> Double

  • Returns Double

center

public defmulti center (sh:Centerable) -> Point

  • Returns Point

Segment

Line Segment

public defstruct Segment <: Shape & HasMetaUtils :
    source: Point
    target: Point

  • source: Point - Start point of this line segment.

  • target: Point - End point of this line segment.

A line segment specified by its start and end point.

Constructors

Segment

Constructor for defstruct Segment

public defn Segment (source:Point, target:Point)

Functions

center

Find the midpoint of the segment.

public defn center (seg:Segment) -> Point

  • seg: Segment - The segment to find the midpoint of.
  • Returns Point

In other words, the average of the start and end points of the segment.

angle-degrees

Calculate the angle of the vector.

public defn angle-degrees (seg:Segment) -> Double

  • seg: Segment - The segment to find the angle of.
  • Returns Double

The angle is in degrees counter-clockwise from the positive X axis of the line from the source to the target of the segment.

length

Calculate the length of the segment.

public defn length (seg:Segment) -> Double

  • seg: Segment - The segment to calculate the length of.
  • Returns Double

Line

Line

public defstruct Line <: Shape & HasMetaUtils :
    points: Tuple<Point>
    width: Double

  • points: Tuple<Point> - Points along this line's centerline. Must be at least 2 points.

  • width: Double - Thickness of this line. Must be non-negative.

A thick polyline consisting of one or more straight line segments. Has a width (thickness) and a tuple of points along its centerline.

Functions

to-polygon

Create a polygon equivalent of the FIRST SEGMENT of the line.

public defn to-polygon (l:Line, six-vertices?:True|False = ?)

  • l: Line - The line to create the polygon equivalent of.
  • six-vertices?: True|False - Whether or not to include an extra vertex at either end to create a six point polygon instead of four.
  • Throws Error - if the line's width is not positive

WARNING: Only does the first segment of the line, not all segments.

outline

public defn outline (l:Line)

Line

Create a line from a sequence of points and/or other nested sequences of points.

public defn Line (width:Double, pts:Seqable<Shape|Seqable>)

  • pts: Seqable<Shape|Seqable> - The sequence of points and/or nested sequences of points to make the line from.

The sequence is "flattened" first to create the tuple of points used.

to-line

Create a line which approximately traces given arc.

public defn to-line (a:Arc, num:Int) -> Line

  • a: Arc - The arc to create the approximate line of.
  • num: Int - The approximate number of points in the returned line.
  • Returns Line

GeneralChamferedRectangle

Chamfered Rectangle

public defstruct GeneralChamferedRectangle <: Shape & Centerable & HasMetaUtils :
    height: Double
    pose: Pose
    radii: Tuple<Double>
    width: Double

  • height: Double - Height of this general chamfered rectangle. Must be non-negative.

  • pose: Pose - Pose of this general chamfered rectangle. Default value is (0.0, 0.0) with no rotation and no flip.

  • radii: Tuple<Double> - Tuple of the four radii of the chamfered corners of this general chamfered rectangle, in counter-clockwise order starting from the bottom left. Must all be non-negative. The sum of the radii of the two corners on each side must not exceed the length of the side.

  • width: Double - Width of this general chamfered rectangle. Must be non-negative.

A rectangle with chamfered corners of different radii. Specified with a width, a height, a tuple of four corner chamfer radii, and a pose. The pose center is the center of the rectangle. The chamfer radius of each corner is the equal length of the two legs of the isosceles right triangle which are cut from the corner. A corner chamfer radius of 0.0 indicates no chamfer for the corner. The tuple of radii is ordered starting with the bottom-left corner going counter-clockwise. The flip of the pose affects the ordering of the general rounded rectangle's points when converted to a polygon (clockwise when flipped, otherwise counter-clockwise).

Constructors

GeneralChamferedRectangle

Constructor for defstruct GeneralChamferedRectangle

public defn GeneralChamferedRectangle (width:Double, height:Double, radii:Tuple<Double>, pose:Pose = ?)

Functions

to-polygon

Create a polygon equivalent of the general chamfered rectangle.

public defn to-polygon (r:GeneralChamferedRectangle) -> Polygon

  • r: GeneralChamferedRectangle - The general chamfered rectangle to create the equivalent polygon of.
  • Returns Polygon

May be clockwise-ordered if the general chamfered rectangle's pose is flipped.

outline

Create a line which traces the outline of the general chamfered rectangle.

public defn outline (r:GeneralChamferedRectangle)

  • r: GeneralChamferedRectangle - The general chamfered rectangle to create the outline of.

The line has width 0.0.

GeneralChamferedRectangle

Create a general chamfered rectangle using a CornerModifier to specify which corners are chamfered.

public defn GeneralChamferedRectangle (w:Double, h:Double, r:Double, m:CornerModifier, p:Pose = ?)

  • w: Double - Width of the general chamfered rectangle.
  • h: Double - Height of the general chamfered rectangle.
  • r: Double - Corner radius of the general chamfered rectangle.
  • m: CornerModifier - Which corners to make chamfered of the general chamfered rectangle.
  • p: Pose - Pose of the general chamfered rectangle. Default is (0.0, 0.0) with no rotation and no flip.

GeneralChamferedRectangle

Create a general chamfered rectangle anchored to a specified alignment with respect to the origin and using a CornerModifier to specify which corners are chamfered.

public defn GeneralChamferedRectangle (anchor:Anchor, w:Double, h:Double, r:Double, m:CornerModifier)

  • anchor: Anchor - Anchor to align the general chamfered rectangle with to the origin.
  • w: Double - Width of the general chamfered rectangle.
  • h: Double - Height of the general chamfered rectangle.
  • r: Double - Corner radius of the general chamfered rectangle.
  • m: CornerModifier - Which corners to make chamfered of the general chamfered rectangle.

GeneralChamferedRectangle

Create a general chamfered rectangle anchored to a specified alignment with respect to the origin.

public defn GeneralChamferedRectangle (anchor:Anchor, w:Double, h:Double, r:Tuple<Double>)

  • anchor: Anchor - Anchor to align the general chamfered rectangle with to the origin.
  • w: Double - Width of the general chamfered rectangle.
  • h: Double - Height of the general chamfered rectangle.
  • r: Tuple<Double> - Tuple of four chamfer radii of the corners of the general chamfered rectangle, starting from the bottom-left going counter-clockwise.

axis-aligned?

Return true if the shape's pose angle is aligned with the X or Y axis.

public defn axis-aligned? (r:Rectangle|Capsule|RoundedRectangle|ChamferedRectangle|DShape|GeneralRoundedRectangle|GeneralChamferedRectangle)

  • r: Rectangle|Capsule|RoundedRectangle|ChamferedRectangle|DShape|GeneralRoundedRectangle|GeneralChamferedRectangle - The shape to check the pose of.

Polygon

Polygon

public defstruct Polygon <: Shape & HasMetaUtils :
    points: Tuple<Point>

  • points: Tuple<Point> - Vertices of this polygon in counter-clockwise order.

A polygon specified by its vertices in counter-clockwise order.

Must be non-degenerate (have at least 3 vertices) and be non-self-intersecting. May be concave.

Functions

circle-points

Create a polygon consisting of points along an arc of a circle.

public defn circle-points (radius:Double, off:Double, tot:Double, num:Int) -> Polygon

  • radius: Double - The radius of the arc to sample points from.
  • off: Double - The starting angle of the arc to sample points from.
  • tot: Double - The counter-clockwise sweep angle of the arc to sample points from.
  • num: Int - The number of divisions to divide the arc into. The total number of points of the polygon will be num + 1.
  • Returns Polygon

Specified with a starting angle, sweep angle, and number of divisions.

to-polygon

Create a polygon equivalent to the rectangle.

public defn to-polygon (r:Rectangle) -> Polygon

  • r: Rectangle - The rectangle to create the equivalent polygon of.
  • Returns Polygon

May be clockwise-ordered if the rectangle's pose is flipped.

to-polygon

Create a polygon approximation of the capsule with approximately the given number of points.

public defn to-polygon (c:Capsule, num:Int) -> Polygon

  • c: Capsule - The capsule to create the approximate equivalent polygon of.
  • num: Int - The approximate number of points to target for the returned polygon.
  • Returns Polygon

May be clockwise-ordered if the capsule's pose is flipped. Does not work well for num less than 3, and may give a polygon with up to num + 2 points.

to-polygon

Create a polygon approximation of the rounded rectangle.

public defn to-polygon (r:RoundedRectangle, num:Int) -> Polygon

  • r: RoundedRectangle - The rounded rectangle to create the approximate equivalent polygon of.
  • num: Int - The approximate total number of points to target for the rounded portions of the returned polygon.
  • Returns Polygon

May be clockwise-ordered if the rounded rectangle's pose is flipped. Does not work well for num less than 4, and it is recommended that num is a multiple of 4.

to-polygon

Create a polygon equivalent of the chamfered rectangle.

public defn to-polygon (r:ChamferedRectangle) -> Polygon

  • r: ChamferedRectangle - The chamfered rectangle to create the equivalent polygon of.
  • Returns Polygon

May be clockwise-ordered if the chamfered rectangle's pose is flipped.

to-polygon

Create a polygon approximation of the D shape.

public defn to-polygon (r:DShape, num:Int) -> Polygon

  • r: DShape - The D shape to create the approximate equivalent polygon of.
  • num: Int - Four times the approximate number of points to target for each rounded portion of the returned polygon.
  • Returns Polygon

May be clockwise-ordered if the D shape's pose is flipped. Does not work well for num less than 4, and it is recommended that num is a multiple of 4.

to-polygon

Create a polygon approximation of the general rounded rectangle.

public defn to-polygon (r:GeneralRoundedRectangle, num:Int) -> Polygon

  • r: GeneralRoundedRectangle - The general rounded rectangle to create the approximate equivalent polygon of.
  • num: Int - Four times the approximate number of points to target for each rounded portion of the returned polygon.
  • Returns Polygon

May be clockwise-ordered if the general rounded rectangle's pose is flipped. Does not work well for num less than 4, and it is recommended that num is a multiple of 4.

to-polygon

Create a polygon equivalent of the general chamfered rectangle.

public defn to-polygon (r:GeneralChamferedRectangle) -> Polygon

  • r: GeneralChamferedRectangle - The general chamfered rectangle to create the equivalent polygon of.
  • Returns Polygon

May be clockwise-ordered if the general chamfered rectangle's pose is flipped.

to-polygon

Create a polygon approximation of the circle with the given number of points.

public defn to-polygon (c:Circle, num:Int) -> Polygon

  • c: Circle - The circle to create the approximate polygon of.
  • num: Int - The number of points in the returned polygon.
  • Returns Polygon

to-polygon

Create a polygon approximation of the arc.

public defn to-polygon (a:Arc, num:Int) -> Polygon

  • a: Arc - The arc to create the approximate polygon of.
  • num: Int - The approximate number of points in the returned polygon.
  • Returns Polygon

Approximates the region enclosed by the arc and the chord connecting the start and end points of the arc, with approximately the given number of points.

outline

Create a line which traces the outline of the given polygon.

public defn outline (p:Polygon)

  • p: Polygon - The polygon to create the outline of.

The line has width 0.0.

Polygon

Create a polygon from a sequence of points and/or other nested sequences of points.

public defn Polygon (pts:Seqable<Point|Seqable>)

  • pts: Seqable<Point|Seqable> - The sequence of points and/or nested sequences of points to make the polygon from.

The sequence is "flattened" first to create the tuple of points used.

Difference

Difference

public defstruct Difference <: Shape & HasMetaUtils :
    shape1: Shape
    shape2: Shape

  • shape1: Shape - The shape from which there is a subtraction to form this difference shape.

  • shape2: Shape - The shape that is subtracted from shape1 to form this difference shape.

A shape formed from subtracting one shape from another. The subtraction is not commutative, i.e. swapping the two shapes that comprise a difference shape will produce a different shape.

Constructors

Difference

Constructor for defstruct Difference

public defn Difference (shape:Shape, shape:Shape)

Polyline

Polyline

public defstruct Polyline <: Shape & HasMetaUtils :
    elements: Tuple<Point|Arc>
    width: Double

  • elements: Tuple<Point|Arc> - Elements along this line's centerline. Must have at least 2 points or 1 arc.

  • width: Double - Thickness of this polyline. Must be non-negative.

A thick polyline consisting of straight line segments and arcs.

Specified with a width (thickness) and a tuple of one or more elements. Each element is either a single point or a circular arc and represents a portion of the centerline of the polyline. The end point of each element (except the last element) is connected to the start point of the next element (a single point is its own start and end point). The start and end points of arcs DO NOT need to also be included as standalone points in the elements tuple, doing so will result in duplicated points.

Functions

Polyline

Create a polyline from a sequence of points, arcs, and/or other nested sequences of points and/or arcs.

public defn Polyline (width:Double, elements:Seqable<Shape|Seqable>)

  • elements: Seqable<Shape|Seqable> - The sequence of points, arcs, and/or other nested sequences to make the polyline from.

The sequence is "flattened" first to create the tuple of points and arcs used.

to-polygon

Create a polygon approximation of the polyline.

public defn to-polygon (l:Polyline)

  • l: Polyline - The polyline to create the polygon approximation of.
  • Throws Error - if the polyline's width is not positive

outline

Create a polyline which traces the outline of the polygon with arcs.

public defn outline (p:PolygonWithArcs) -> Polyline

  • p: PolygonWithArcs - The polygon with arcs to create the outline of.
  • Returns Polyline

The polyline has width 0.0.

outline

public defn outline (l:Polyline)

RoundedRectangle

Rounded Rectangle

public defstruct RoundedRectangle <: Shape & Centerable & HasMetaUtils :
    height: Double
    pose: Pose
    radius: Double
    width: Double

  • height: Double - Height of this rounded rectangle. Must be non-negative.

  • pose: Pose - Pose of this rounded rectangle. Default value is (0.0, 0.0) with no rotation and no flip.

  • radius: Double - Radius of the rounded corners of this rounded rectangle. Must be non-negative and at most half of the minimum of the width and height.

  • width: Double - Width of this rounded rectangle. Must be non-negative.

A rectangle with rounded (filleted) corners.

All four corners are rounded to the same radius. Has a width, height, corner radius and pose. The pose center is the center of the rectangle. The flip of the pose affects the ordering of the rounded rectangle's points when converted to a polygon (clockwise when flipped, otherwise counter-clockwise).

Constructors

RoundedRectangle

Constructor for defstruct RoundedRectangle

public defn RoundedRectangle (width:Double, height:Double, radius:Double, pose:Pose = ?)

Functions

outline

Create a line which traces the outline of the rounded rectangle.

public defn outline (r:RoundedRectangle)

  • r: RoundedRectangle - The rounded rectangle to create the approximate outline of.

The line has width 0.0, has exact line segments for the straight sides of the shape, and approximates the rounded portions of the shape with segments which are approximately 1/32 of a whole circle.

RoundedRectangle

Create a rounded rectangle anchored to a specified alignment with respect to the origin.

public defn RoundedRectangle (anchor:Anchor, w:Double, h:Double, r:Double)

  • anchor: Anchor - Anchor to align the rounded rectangle with to the origin.
  • w: Double - Width of the rounded rectangle.
  • h: Double - Height of the rounded rectangle.
  • r: Double - Corner radius of the rounded rectangle.

The alignment is performed with respect to the un-rounded rectangular bounding box of the rounded rectangle.

to-polygon-with-arcs

Create a polygon with arcs equivalent to the rounded rectangle.

public defn to-polygon-with-arcs (r:RoundedRectangle) -> PolygonWithArcs

  • r: RoundedRectangle - The rounded rectangle to create the polygon with arcs equivalent of.
  • Returns PolygonWithArcs

May be clockwise-ordered if the rounded rectangle's pose is flipped.

axis-aligned?

Return true if the shape's pose angle is aligned with the X or Y axis.

public defn axis-aligned? (r:Rectangle|Capsule|RoundedRectangle|ChamferedRectangle|DShape|GeneralRoundedRectangle|GeneralChamferedRectangle)

  • r: Rectangle|Capsule|RoundedRectangle|ChamferedRectangle|DShape|GeneralRoundedRectangle|GeneralChamferedRectangle - The shape to check the pose of.

to-polygon

Create a polygon approximation of the rounded rectangle.

public defn to-polygon (r:RoundedRectangle, num:Int) -> Polygon

  • r: RoundedRectangle - The rounded rectangle to create the approximate equivalent polygon of.
  • num: Int - The approximate total number of points to target for the rounded portions of the returned polygon.
  • Returns Polygon

May be clockwise-ordered if the rounded rectangle's pose is flipped. Does not work well for num less than 4, and it is recommended that num is a multiple of 4.

normalize

Create an equivalent rounded rectangle with pose angle 0.0 for the given axis-aligned rounded rectangle.

public defn normalize (r:RoundedRectangle)

  • r: RoundedRectangle - The rounded rectangle to create the equivalent of.
  • Throws Error - if the rounded rectangle's pose angle is not axis-aligned.

GeneralRoundedRectangle

General Rounded Rectangle

public defstruct GeneralRoundedRectangle <: Shape & HasMetaUtils :
    height: Double
    pose: Pose
    radii: Tuple<Double>
    width: Double

  • height: Double - Height of this general rounded rectangle. Must be non-negative.

  • pose: Pose - Pose of this rounded rectangle. Default value is (0.0, 0.0) with no rotation and no flip.

  • radii: Tuple<Double> - Tuple of the four radii of each of the rounded corners of this general rounded rectangle, in counter-clockwise order starting from the bottom left. Must all be non-negative. The sum of the radii of the two corners on each side must not exceed the length of the side.

  • width: Double - Width of this general rounded rectangle. Must be non-negative.

A rectangle with rounded (filleted) corners of different radii.

Specified with a width, height, a tuple of four corner radii, and a pose. The pose center is the center of the rectangle. The tuple of radii is ordered starting with the bottom-left corner going counter-clockwise. A corner radius of 0.0 indicates no rounding. The flip of the pose affects the ordering of the general rounded rectangle's points when converted to a polygon (clockwise when flipped, otherwise counter-clockwise).

Constructors

GeneralRoundedRectangle

Constructor for defstruct GeneralRoundedRectangle

public defn GeneralRoundedRectangle (width:Double, height:Double, radii:Tuple<Double>, pose:Pose = ?)

Functions

to-polygon

Create a polygon approximation of the general rounded rectangle.

public defn to-polygon (r:GeneralRoundedRectangle, num:Int) -> Polygon

  • r: GeneralRoundedRectangle - The general rounded rectangle to create the approximate equivalent polygon of.
  • num: Int - Four times the approximate number of points to target for each rounded portion of the returned polygon.
  • Returns Polygon

May be clockwise-ordered if the general rounded rectangle's pose is flipped. Does not work well for num less than 4, and it is recommended that num is a multiple of 4.

outline

Create a line which traces the outline of the general rounded rectangle.

public defn outline (r:GeneralRoundedRectangle)

  • r: GeneralRoundedRectangle - The general rounded rectangle to create the approximate outline of.

The line has width 0.0, has exact line segments for the straight sides of the shape, and approximates the rounded portions of the shape with segments which are approximately 1/32 of a whole circle.

GeneralRoundedRectangle

Create a general rounded rectangle using a CornerModifier to specify which corners are rounded.

public defn GeneralRoundedRectangle (w:Double, h:Double, r:Double, m:CornerModifier, p:Pose = ?)

  • w: Double - Width of the general rounded rectangle.
  • h: Double - Height of the general rounded rectangle.
  • r: Double - Corner radius of the general rounded rectangle.
  • m: CornerModifier - Which corners to make rounded of the general rounded rectangle.
  • p: Pose - Pose of the general rounded rectangle. Default is (0.0, 0.0) with no rotation and no flip.

GeneralRoundedRectangle

Create a general rounded rectangle anchored to a specified alignment with respect to the origin and using a CornerModifier to specify which corners are rounded.

public defn GeneralRoundedRectangle (anchor:Anchor, w:Double, h:Double, r:Double, m:CornerModifier)

  • anchor: Anchor - Anchor to align the general rounded rectangle with to the origin.
  • w: Double - Width of the general rounded rectangle.
  • h: Double - Height of the general rounded rectangle.
  • r: Double - Corner radius of the general rounded rectangle.
  • m: CornerModifier - Which corners to make rounded of the general rounded rectangle.

GeneralRoundedRectangle

Create a general rounded rectangle anchored to a specified alignment with respect to the origin.

public defn GeneralRoundedRectangle (anchor:Anchor, w:Double, h:Double, r:Tuple<Double>)

  • anchor: Anchor - Anchor to align the general rounded rectangle with to the origin.
  • w: Double - Width of the general rounded rectangle.
  • h: Double - Height of the general rounded rectangle.
  • r: Tuple<Double> - Tuple of four radii of the corners of the general rounded rectangle, starting from the bottom-left going counter-clockwise.

to-polygon-with-arcs

Create a polygon with arcs equivalent to the general rounded rectangle.

public defn to-polygon-with-arcs (r:GeneralRoundedRectangle) -> PolygonWithArcs

  • r: GeneralRoundedRectangle - The general rounded rectangle to create the polygon with arcs equivalent of.
  • Returns PolygonWithArcs

May be clockwise-ordered if the general rounded rectangle 's pose is flipped.

axis-aligned?

Return true if the shape's pose angle is aligned with the X or Y axis.

public defn axis-aligned? (r:Rectangle|Capsule|RoundedRectangle|ChamferedRectangle|DShape|GeneralRoundedRectangle|GeneralChamferedRectangle)

  • r: Rectangle|Capsule|RoundedRectangle|ChamferedRectangle|DShape|GeneralRoundedRectangle|GeneralChamferedRectangle - The shape to check the pose of.

CornerModifier

Enum for general rounded rectangle corner combinations

public defenum CornerModifier <: Equalable & Hashable

  • CornerModifierNone - represents no corners

  • CornerModifierAll - represents all corners

  • CornerModifierBottomLeft

  • CornerModifierBottomRight

  • CornerModifierUpperLeft

  • CornerModifierUpperRight

  • CornerModifierUpperLeftAndRight - upper left and upper right corners

  • CornerModifierBottomLeftAndRight - bottom left and bottom right corners

  • CornerModifierUpperAndBottomLeft - upper left and bottom left corners

  • CornerModifierUpperAndBottomRight - upper right and bottom right corners

This definition defines 10 options of combinations of zero or more corners of a rectangle. Used for specifying which corners to apply an operation to, for example when specifying which corners are rounded when constructing a general rounded rectangle. The options include no corners, all corners, each individual corner, and pairs of corners on each side of the rectangle.

Functions

GeneralRoundedRectangle

Create a general rounded rectangle using a CornerModifier to specify which corners are rounded.

public defn GeneralRoundedRectangle (w:Double, h:Double, r:Double, m:CornerModifier, p:Pose = ?)

  • w: Double - Width of the general rounded rectangle.
  • h: Double - Height of the general rounded rectangle.
  • r: Double - Corner radius of the general rounded rectangle.
  • m: CornerModifier - Which corners to make rounded of the general rounded rectangle.
  • p: Pose - Pose of the general rounded rectangle. Default is (0.0, 0.0) with no rotation and no flip.

GeneralRoundedRectangle

Create a general rounded rectangle anchored to a specified alignment with respect to the origin and using a CornerModifier to specify which corners are rounded.

public defn GeneralRoundedRectangle (anchor:Anchor, w:Double, h:Double, r:Double, m:CornerModifier)

  • anchor: Anchor - Anchor to align the general rounded rectangle with to the origin.
  • w: Double - Width of the general rounded rectangle.
  • h: Double - Height of the general rounded rectangle.
  • r: Double - Corner radius of the general rounded rectangle.
  • m: CornerModifier - Which corners to make rounded of the general rounded rectangle.

GeneralChamferedRectangle

Create a general chamfered rectangle using a CornerModifier to specify which corners are chamfered.

public defn GeneralChamferedRectangle (w:Double, h:Double, r:Double, m:CornerModifier, p:Pose = ?)

  • w: Double - Width of the general chamfered rectangle.
  • h: Double - Height of the general chamfered rectangle.
  • r: Double - Corner radius of the general chamfered rectangle.
  • m: CornerModifier - Which corners to make chamfered of the general chamfered rectangle.
  • p: Pose - Pose of the general chamfered rectangle. Default is (0.0, 0.0) with no rotation and no flip.

GeneralChamferedRectangle

Create a general chamfered rectangle anchored to a specified alignment with respect to the origin and using a CornerModifier to specify which corners are chamfered.

public defn GeneralChamferedRectangle (anchor:Anchor, w:Double, h:Double, r:Double, m:CornerModifier)

  • anchor: Anchor - Anchor to align the general chamfered rectangle with to the origin.
  • w: Double - Width of the general chamfered rectangle.
  • h: Double - Height of the general chamfered rectangle.
  • r: Double - Corner radius of the general chamfered rectangle.
  • m: CornerModifier - Which corners to make chamfered of the general chamfered rectangle.

Union

Union

public defstruct Union <: Shape & HasMetaUtils :
    shapes: Tuple<Shape>

  • shapes: Tuple<Shape> - The shapes which comprise this union shape.

A shape formed from the joining of one or more other shapes together.

Functions

Union

Create a union shape from a sequence of shapes and/or other nested sequences.

public defn Union (elements:Seqable<Shape|Seqable>)

  • elements: Seqable<Shape|Seqable> - The sequence of shapes and/or other nested sequences to make the union shape from.

The sequence is "flattened" first to create the tuple of shapes used.

Point

Point

public defstruct Point <: Shape & Centerable & HasMetaUtils :
    x: Double
    y: Double

  • x: Double - X-axis coordinate of this point.

  • y: Double - Y-axis coordinate of this point.

A single 2D point with an X and a Y coordinate. A point is centerable and has zero area.

Constructors

Point

Constructor for defstruct Point

public defn Point (x:Double, y:Double)

Multis

center

public defmulti center (sh:Centerable) -> Point

  • Returns Point

Functions

iy

The truncated integer value of the Y coordinate of the point.

public defn iy (p:Point)

Point

Create a point from two integer coordinates.

public defn Point (x:Int, y:Int)

min

Create the point which is the result of taking the minimum coordinate along each axis of the coordinates of a and b.

public defn min (a:Point, b:Point)

max

Create the point which is the result of taking the maximum coordinate along each axis of the coordinates of a and b.

public defn max (a:Point, b:Point)

center

Find the midpoint of the segment.

public defn center (seg:Segment) -> Point

  • seg: Segment - The segment to find the midpoint of.
  • Returns Point

In other words, the average of the start and end points of the segment.

get

Retrieve the X or Y coordinate of the point, using an index to select which coordinate.

public defn get (p:Point, i:Int) -> Double

  • p: Point - The point to retrieve the coordinate of.
  • i: Int - Index to select which coordinate to retrieve (0 for X, 1 for Y).
  • Returns Double
  • Throws Error - if i is not 0 or 1.

Index 0 is the X coordinate, 1 is the Y coordinate.

Polygon

Create a polygon from a sequence of points and/or other nested sequences of points.

public defn Polygon (pts:Seqable<Point|Seqable>)

  • pts: Seqable<Point|Seqable> - The sequence of points and/or nested sequences of points to make the polygon from.

The sequence is "flattened" first to create the tuple of points used.

ix

The truncated integer value of the X coordinate of the point.

public defn ix (p:Point)

Operators

minus -

Create the point which is the result of subtracting the coordinates of b from the coordinates of a.

public defn minus (a:Point, b:Point)

divide /

Create the point which is the result of dividing the coordinates of a by n.

public defn divide (a:Point, n:Double)

negate -

Create the point with both coordinates negated of the given point.

public defn negate (a:Point)

plus +

Create the point which is the result of adding the coordinates of a and b.

public defn plus (a:Point, b:Point)

times *

Create the point which is the result of multiplying the coordinates of a by n.

public defn times (a:Double, b:Point)

Circle

Circle

public defstruct Circle <: Shape & Centerable & HasMetaUtils :
    radius: Double

  • radius: Double - Radius of this circle. Must be non-negative.

A circle specified by its center point and radius.

If the radius is 0.0 then the actual shape of the circle is a point.

Constructors

Circle

Constructor for defstruct Circle

public defn Circle (center:Point = ?, radius:Double)

Functions

to-polygon

Create a polygon approximation of the circle with the given number of points.

public defn to-polygon (c:Circle, num:Int) -> Polygon

  • c: Circle - The circle to create the approximate polygon of.
  • num: Int - The number of points in the returned polygon.
  • Returns Polygon

Circle

Create a circle using a center X coordinate, center Y coordinate, and radius.

public defn Circle (x:Double, y:Double, radius:Double)

  • x: Double - X coordinate of the center of the circle.
  • y: Double - Y coordinate of the center of the circle.
  • radius: Double - Radius of the circle

Circle

Create a circle anchored to a specific alignment with respect to a point.

public defn Circle (anchor:Anchor, x:Double, y:Double, radius:Double)

  • anchor: Anchor - Anchor to align the circle with to the point (x, y).
  • x: Double - X coordinate of the point to align the circle's anchor to.
  • y: Double - Y coordinate of the point to align the circle's anchor to.
  • radius: Double - Radius of the circle

Circle

Create a circle anchored to a specific alignment with respect to the origin.

public defn Circle (anchor:Anchor, radius:Double)

  • anchor: Anchor - Anchor to align the circle with to the origin.
  • radius: Double - Radius of the circle.

outline

Create a line which traces the outline of the circle.

public defn outline (c:Circle)

  • c: Circle - The circle to create the approximate outline of.

The line has width 0.0 and approximates the circle with 32 segments.

to-polygon-with-arcs

Create a polygon with arcs equivalent to the circle.

public defn to-polygon-with-arcs (c:Circle) -> PolygonWithArcs

  • c: Circle - The circle to create the polygon with arcs s equivalent of.
  • Returns PolygonWithArcs

Arc

Arc

public defstruct Arc <: Shape & HasMetaUtils :
    angle: Double
    center: Point
    radius: Double
    start-angle: Double

  • angle: Double - Sweep angle of this arc in degrees counter-clockwise. A negative value indicates a clockwise sweep. Must be between -360.0 and 360.0 inclusive. A sweep angle of 0.0 indicates a single-point arc. A sweep angle of exactly -360.0 or 360.0 indicates a full circle.

  • center: Point - Center point of this arc.

  • radius: Double - Radius of this arc. Must be non-negative. If the radius is 0.0 then the actual shape is considered to be a point at the center of this arc.

  • start-angle: Double - Starting angle of this arc in degrees counter-clockwise from the positive X axis. Must be non-negative and strictly less than 360.0.

A circular arc specified by its center point, radius, starting angle, and sweep angle.

Constructors

Arc

Constructor for defstruct Arc

public defn Arc (center:Point, radius:Double, start-angle:Double, angle:Double)

Functions

to-polygon

Create a polygon approximation of the arc.

public defn to-polygon (a:Arc, num:Int) -> Polygon

  • a: Arc - The arc to create the approximate polygon of.
  • num: Int - The approximate number of points in the returned polygon.
  • Returns Polygon

Approximates the region enclosed by the arc and the chord connecting the start and end points of the arc, with approximately the given number of points.

to-polygon

Create a polygon approximation of the region created by "thickening" the arc.

public defn to-polygon (a:Arc, width:Double, num:Int = ?)

  • a: Arc - The arc to create the approximate polygon of.
  • width: Double - The width of the "thickened" arc region to create the approximate polygon of.
  • num: Int - The approximate number of points in each half of the returned polygon. Default is 32.

The returned polygon will have approximately num number of points.

outline

Create a line which traces the outline of the arc.

public defn outline (a:Arc)

  • a: Arc - The arc to create the approximate outline of.

The line has width 0.0 and approximates the arc with segments which are 1/32 of a whole circle.

Arc

Create an arc, specifying the center with separate X and Y coordinate values instead of as a Point.

public defn Arc (x:Double, y:Double, radius:Double, start-angle:Double, angle:Double) -> Arc

  • x: Double - X coordinate of the center of the arc.
  • y: Double - Y coordinate of the center of the arc.
  • start-angle: Double - Starting angle of the arc in degrees counter-clockwise from the positive X axis.
  • angle: Double - Counter-clockwise sweep angle of the arc.
  • Returns Arc

to-line

Create a line which approximately traces given arc.

public defn to-line (a:Arc, num:Int) -> Line

  • a: Arc - The arc to create the approximate line of.
  • num: Int - The approximate number of points in the returned line.
  • Returns Line

length

Calculate the length of the arc.

public defn length (a:Arc) -> Double

  • a: Arc - The arc to calculate the length of.
  • Returns Double

EmptyShape

Empty Shape

public defstruct EmptyShape <: Shape & HasMetaUtils :

An empty shape. Empty shapes have zero area and no pose.

Constructors

EmptyShape

Constructor for defstruct EmptyShape

public defn EmptyShape ()

DShape

D Shape

public defstruct DShape <: Shape & Centerable & HasMetaUtils :
    height: Double
    pose: Pose
    radius: Double
    width: Double

  • height: Double - Height of this D shape. Must be non-negative.

  • pose: Pose - Pose of this D shape. Default value is (0.0, 0.0) with no rotation and no flip.

  • radius: Double - Radius of the two rounded corners of this D shape. Must be non-negative and at most the minimum of the width and half of the height.

  • width: Double - Width of this D shape. Must be non-negative.

A rectangle with only its two right corners (top and bottom) rounded.

Similar to he shape of the letter "D". The two right corners are rounded to the same radius, and the top left corners are normal (unrounded). Has a width, height, corner radius and pose. The pose center is the center of the rectangle. The flip of the pose affects the ordering of the chamfered rectangle's points when converted to a polygon (clockwise when flipped, otherwise counter-clockwise).

Constructors

DShape

Constructor for defstruct DShape

public defn DShape (width:Double, height:Double, radius:Double, pose:Pose = ?)

Functions

to-polygon

Create a polygon approximation of the D shape.

public defn to-polygon (r:DShape, num:Int) -> Polygon

  • r: DShape - The D shape to create the approximate equivalent polygon of.
  • num: Int - Four times the approximate number of points to target for each rounded portion of the returned polygon.
  • Returns Polygon

May be clockwise-ordered if the D shape's pose is flipped. Does not work well for num less than 4, and it is recommended that num is a multiple of 4.

outline

Create a line which traces the outline of the D shape.

public defn outline (r:DShape)

  • r: DShape - The D shape to create the approximate outline of.

The line has width 0.0, has exact line segments for the straight sides of the shape, and approximates the rounded portions of the shape with segments which are approximately 1/32 of a whole circle.

to-polygon-with-arcs

Create a polygon with arcs equivalent to the D shape.

public defn to-polygon-with-arcs (d:DShape) -> PolygonWithArcs

  • d: DShape - The D shape to create the polygon with arcs equivalent of.
  • Returns PolygonWithArcs

May be clockwise-ordered if the D shape's pose is flipped.

DShape

Create a D shape anchored to a specified alignment with respect to the origin.

public defn DShape (anchor:Anchor, w:Double, h:Double, r:Double)

  • anchor: Anchor - Anchor to align the D shape with to the origin.
  • w: Double - Width of the D shape.
  • h: Double - Height of the D shape.
  • r: Double - Corner radius of the D shape.

The alignment is performed with respect to the un-rounded rectangular bounding box of the D shape.

axis-aligned?

Return true if the shape's pose angle is aligned with the X or Y axis.

public defn axis-aligned? (r:Rectangle|Capsule|RoundedRectangle|ChamferedRectangle|DShape|GeneralRoundedRectangle|GeneralChamferedRectangle)

  • r: Rectangle|Capsule|RoundedRectangle|ChamferedRectangle|DShape|GeneralRoundedRectangle|GeneralChamferedRectangle - The shape to check the pose of.

General Definitions

iy

The truncated integer value of the Y coordinate of the pose's center.

public defn iy (p:Pose)

iangle

The truncated integer value of the pose's angle.

public defn iangle (p:Pose)

angle-mod-90?

Return true if the angle of the pose is an exact multiple of 90 degrees.

public defn angle-mod-90? (p:Pose)

  • p: Pose - The pose to check the angle of.

ix

The truncated integer value of the X coordinate of the pose's center.

public defn ix (p:Pose)

Related Packages

Forwarded by package: jitx