GeometryUtilities

Package: Libraries.Fabrication.Geometry · Inherits from: Libraries.Language.Object

The GeometryUtilities class holds the small numeric helpers the geometry and slicing classes share. They are written in Quorum rather than calling Math, because they run in the innermost loops.

Example Code

use Libraries.Fabrication.Geometry.GeometryUtilities

class Main
    action Main
        GeometryUtilities util
        output util:FloorToInt(-1.5)                            // -2
        output util:SegmentDistance2(0, 1, -1, 0, 1, 0)         // 1
    end
end

Actions

AbsNum(number a)

The absolute value of a number.

Parameters

  • a number: The number.

Returns

number: a without its sign.

Example

use Libraries.Fabrication.Geometry.GeometryUtilities

GeometryUtilities util
output util:AbsNum(-2.5)      // 2.5

BucketByPlane(Libraries.Containers.Array<integer> planeOf, integer planeCount, Libraries.Containers.Array<integer> starts, Libraries.Containers.Array<integer> order)

Groups item indices by plane with a counting sort. Afterwards plane p owns order[starts[p]] up to (not including) order[starts[p + 1]], in the items' original order. Items whose plane is outside 0 to planeCount - 1 (use -1 to leave an item out) are skipped.

Parameters

Example

use Libraries.Containers.Array
use Libraries.Fabrication.Geometry.GeometryUtilities

GeometryUtilities util
Array<integer> planeOf
planeOf:Add(1)
planeOf:Add(0)
planeOf:Add(1)
Array<integer> starts
Array<integer> order
util:BucketByPlane(planeOf, 2, starts, order)
// plane 1 owns order[starts[1]] up to order[starts[2]]: items 0 and 2
integer i = starts:Get(1)
repeat while i < starts:Get(2)
    output order:Get(i)
    i = i + 1
end

CeilingToInt(number v)

The smallest whole number not below v.

Parameters

  • v number: The number to round up.

Returns

integer: The smallest whole number not below v.

Example

use Libraries.Fabrication.Geometry.GeometryUtilities

GeometryUtilities util
output util:CeilingToInt(2.1)      // 3

FloorToInt(number v)

The largest whole number not above v.

Parameters

  • v number: The number to round down.

Returns

integer: The largest whole number not above v.

Example

use Libraries.Fabrication.Geometry.GeometryUtilities

GeometryUtilities util
output util:FloorToInt(-1.5)      // -2

IsUsableLoop(Libraries.Fabrication.Geometry.Contour con, integer planeCount)

True for a closed loop of at least 3 points on a plane between 0 and planeCount - 1.

Parameters

Returns

boolean: True for a closed loop of at least 3 points on a plane between 0 and planeCount - 1.

Example

use Libraries.Fabrication.Geometry.Contour
use Libraries.Fabrication.Geometry.GeometryUtilities

GeometryUtilities util

Contour square
square:AddPoint(0, 0)
square:AddPoint(20, 0)
square:AddPoint(20, 20)
square:AddPoint(0, 20)
square:closed = true
square:planeIndex = 4
output util:IsUsableLoop(square, 100)      // true

Max2(number a, number b)

The larger of two numbers.

Parameters

  • a number: The first number.
  • b number: The second number.

Returns

number: a or b, whichever is larger.

Example

use Libraries.Fabrication.Geometry.GeometryUtilities

GeometryUtilities util
output util:Max2(0.4, 0.2)      // 0.4

Min2(number a, number b)

The smaller of two numbers.

Parameters

  • a number: The first number.
  • b number: The second number.

Returns

number: a or b, whichever is smaller.

Example

use Libraries.Fabrication.Geometry.GeometryUtilities

GeometryUtilities util
output util:Min2(0.4, 0.2)      // 0.2

PathLength(Libraries.Fabrication.Geometry.Contour path)

The length of a path, including the closing edge of a loop.

Parameters

Returns

number: The length (mm).

Example

use Libraries.Fabrication.Geometry.Contour
use Libraries.Fabrication.Geometry.GeometryUtilities

GeometryUtilities util

Contour square
square:AddPoint(0, 0)
square:AddPoint(20, 0)
square:AddPoint(20, 20)
square:AddPoint(0, 20)
square:closed = true
output util:PathLength(square)      // 80, closing edge included

SegmentDistance2(number px, number py, number ax, number ay, number bx, number by)

The squared distance from point p to the segment from a to b.

Parameters

  • px number: The point's x coordinate (mm).
  • py number: The point's y coordinate (mm).
  • ax number: The x coordinate of the segment's start.
  • ay number: The y coordinate of the segment's start.
  • bx number: The x coordinate of the segment's end.
  • by number: The y coordinate of the segment's end.

Returns

number: The squared distance (mm^2).

Example

use Libraries.Fabrication.Geometry.GeometryUtilities

GeometryUtilities util
output util:SegmentDistance2(5, 3, 0, 0, 10, 0)       // 9: 3 mm from the segment

SortNumbers(Libraries.Containers.Array<number> a)

Sorts numbers ascending in place (insertion sort: the lists are short scan-line crossings, where it beats anything fancier).

Parameters

Example

use Libraries.Containers.Array
use Libraries.Fabrication.Geometry.GeometryUtilities

GeometryUtilities util
Array<number> crossings
crossings:Add(12.5)
crossings:Add(3.0)
crossings:Add(7.25)
util:SortNumbers(crossings)
output crossings:Get(0)      // 3.0

Inherited Actions

3 actions from Libraries.Language.Object