Logo Hywe

Goxel Module

Goxel (Geometry Engine) Provides geometric primitives and utilities for Hygrid shapes. Includes line generation, polygon cleaning, area calculations, and winding normalization.

Functions and values

Function or value Description

bounds pts

Full Usage: bounds pts

Parameters:
    pts : (int * int)[] - Array of 2D coordinate points.

Returns: int * int * int * int 4-tuple of (minX, minY, maxX, maxY).

Computes the bounding box of a polygon in grid coordinates: (minX, minY, maxX, maxY).

pts : (int * int)[]

Array of 2D coordinate points.

Returns: int * int * int * int

4-tuple of (minX, minY, maxX, maxY).

Example

 let minX, minY, maxX, maxY = Goxel.bounds [| (0, 5); (12, 2); (6, 18) |]
val minX: obj
val minY: obj
val maxX: obj
val maxY: obj

centroid pts

Full Usage: centroid pts

Parameters:
    pts : (int * int)[] - Array of 2D coordinate points.

Returns: int * int Tuple of (centerX, centerY).

Computes the arithmetic centroid (average of grid indices) of a collection of points.

pts : (int * int)[]

Array of 2D coordinate points.

Returns: int * int

Tuple of (centerX, centerY).

Example

 let cx, cy = Goxel.centroid [| (0, 0); (10, 0); (10, 10); (0, 10) |]
val cx: obj
val cy: obj

cleanPolygon sqn pts

Full Usage: cleanPolygon sqn pts

Parameters:
    sqn : Sqn - Traversal sequence.
    pts : (int * int)[] - Raw input polygon vertices.

Returns: (int * int)[] Cleaned, validated, clockwise polygon vertices.

Cleans a polygon by deduplicating sequential points, removing sawtooth aliasing, closing the loop, removing collinear points, and normalizing winding to clockwise.

sqn : Sqn

Traversal sequence.

pts : (int * int)[]

Raw input polygon vertices.

Returns: (int * int)[]

Cleaned, validated, clockwise polygon vertices.

Example

 let cleaned = Goxel.cleanPolygon Hexel.Sqn.VRCWEE [| (0, 0); (10, 0); (10, 10); (0, 10) |]
val cleaned: obj

dedupeSequential pts

Full Usage: dedupeSequential pts

Parameters:
    pts : (int * int)[] - Array of 2D coordinate points.

Returns: (int * int) array Array of points without adjacent duplicates.

Deduplicates consecutive identical coordinate points in a sequence.

pts : (int * int)[]

Array of 2D coordinate points.

Returns: (int * int) array

Array of points without adjacent duplicates.

Example

 let deduped = Goxel.dedupeSequential [| (0, 0); (0, 0); (1, 1); (2, 2); (2, 2) |]
val deduped: obj

ensureClosed pts

Full Usage: ensureClosed pts

Parameters:
    pts : (int * int)[] - Array of 2D coordinate points.

Returns: (int * int)[] Closed array of points where the last point matches the first.

Ensures a polygon coordinate sequence is closed by appending the first point to the end if not already equal.

pts : (int * int)[]

Array of 2D coordinate points.

Returns: (int * int)[]

Closed array of points where the last point matches the first.

Example

 let closed = Goxel.ensureClosed [| (0, 0); (10, 0); (10, 10); (0, 10) |]
val closed: obj

hxlLin sqn elv stt enn

Full Usage: hxlLin sqn elv stt enn

Parameters:
    sqn : Sqn - Traversal sequence.
    elv : int - Elevation layer.
    stt : Hxl - Start hexel.
    enn : Hxl - End hexel.

Returns: Hxl array Array of intermediate and endpoint Hexels forming the line.

Generates a discrete line of hexels connecting start and end hexels using integer grid mathematics.

sqn : Sqn

Traversal sequence.

elv : int

Elevation layer.

stt : Hxl

Start hexel.

enn : Hxl

End hexel.

Returns: Hxl array

Array of intermediate and endpoint Hexels forming the line.

Example

 let startPt = Hexel.AV(0, 0, 0)
 let endPt = Hexel.AV(10, 10, 0)
 let line = Goxel.hxlLin Hexel.Sqn.VRCWEE 0 startPt endPt
val startPt: obj
val endPt: obj
val line: obj

hxlPgn sqn elv vtx

Full Usage: hxlPgn sqn elv vtx

Parameters:
    sqn : Sqn - Traversal sequence.
    elv : int - Elevation layer.
    vtx : (int * int)[] - Array of 2D polygon vertices.

Returns: Hxl[] Array of Hexels forming the perimeter and segments of the polygon.

Generates a filled or outlined hexel polygon covering the region defined by integer vertices.

sqn : Sqn

Traversal sequence.

elv : int

Elevation layer.

vtx : (int * int)[]

Array of 2D polygon vertices.

Returns: Hxl[]

Array of Hexels forming the perimeter and segments of the polygon.

Example

 let boundaryHxls = Goxel.hxlPgn Hexel.Sqn.VRCWEE 0 [| (0, 0); (12, 0); (12, 12); (0, 12) |]
val boundaryHxls: obj

normalizeWinding clockwise pts

Full Usage: normalizeWinding clockwise pts

Parameters:
    clockwise : bool - True to enforce clockwise winding; false for counterclockwise.
    pts : (int * int)[] - Array of 2D polygon vertices.

Returns: (int * int)[] Array of vertices with the specified winding order.

Normalizes the vertex winding order of a polygon to clockwise or counterclockwise using signed area calculation.

clockwise : bool

True to enforce clockwise winding; false for counterclockwise.

pts : (int * int)[]

Array of 2D polygon vertices.

Returns: (int * int)[]

Array of vertices with the specified winding order.

Example

 let cwPolygon = Goxel.normalizeWinding true [| (0, 0); (10, 0); (10, 10); (0, 10); (0, 0) |]
val cwPolygon: obj

parseCoords value

Full Usage: parseCoords value

Parameters:
    value : string - Comma-separated coordinate string.

Returns: (int * int) array Array of integer (x, y) vertices.

Parses a comma-separated string of coordinates into rounded integer (int * int) grid vertices.

value : string

Comma-separated coordinate string.

Returns: (int * int) array

Array of integer (x, y) vertices.

Example

 let coords = Goxel.parseCoords "0,0, 12,0, 12,8, 0,8"
val coords: obj

parseIslands value

Full Usage: parseIslands value

Parameters:
    value : string - Hyphen-separated string of island polygon coordinates.

Returns: (int * int) array array Array of integer island vertex arrays.

Parses a hyphen-separated string of island polygons into rounded integer (int * int)[][] grid vertices.

value : string

Hyphen-separated string of island polygon coordinates.

Returns: (int * int) array array

Array of integer island vertex arrays.

Example

 let islandCoords = Goxel.parseIslands "2,2,4,2,4,4,2,4 - 6,6,8,6,8,8,6,8"
val islandCoords: obj

parsePolyIslands s

Full Usage: parsePolyIslands s

Parameters:
    s : string - Hyphen-separated string of polygon coordinates.

Returns: (float * float)[][] Array of float polygon vertex arrays.

Parses a hyphen-separated string of polygons (e.g. "0,0,10,10 - 20,20,30,30") representing multiple islands into a 2D array of float points.

s : string

Hyphen-separated string of polygon coordinates.

Returns: (float * float)[][]

Array of float polygon vertex arrays.

Example

 let islands = Goxel.parsePolyIslands "0,0,10,0,10,10 - 20,20,25,20,25,25"
val islands: obj

parsePolygon s

Full Usage: parsePolygon s

Parameters:
    s : string - Comma-separated string of coordinates.

Returns: (float * float)[] Array of (float * float) points.

Parses a comma-separated string of coordinate numbers (e.g. "0,0,10,0,10,10,0,10") into an array of 2D float points.

s : string

Comma-separated string of coordinates.

Returns: (float * float)[]

Array of (float * float) points.

Example

 let points = Goxel.parsePolygon "0,0, 10,0, 10,10, 0,10"
val points: obj

pointInPolygon (arg1, arg1) poly

Full Usage: pointInPolygon (arg1, arg1) poly

Parameters:
    arg0 : int
    arg1 : int
    poly : (int * int)[] - Polygon vertex array.

Returns: bool True if the point is inside the polygon; otherwise false.

Tests whether a 2D integer point lies inside or on the boundary of a polygon using the ray casting algorithm.

arg0 : int
arg1 : int
poly : (int * int)[]

Polygon vertex array.

Returns: bool

True if the point is inside the polygon; otherwise false.

Example

 let isInside = Goxel.pointInPolygon (5, 5) [| (0, 0); (10, 0); (10, 10); (0, 10) |]
val isInside: obj

polygonArea pts

Full Usage: polygonArea pts

Parameters:
    pts : (int * int)[] - Array of 2D polygon vertices.

Returns: int64 Polygon area as a 64-bit integer.

Calculates the area of a simple polygon in logical grid units using Gauss's area formula (Shoelace algorithm).

pts : (int * int)[]

Array of 2D polygon vertices.

Returns: int64

Polygon area as a 64-bit integer.

Example

 let area = Goxel.polygonArea [| (0, 0); (10, 0); (10, 10); (0, 10); (0, 0) |]
val area: obj

polygonWithHolesArea outer holes

Full Usage: polygonWithHolesArea outer holes

Parameters:
    outer : (int * int)[] - Outer boundary polygon vertices.
    holes : (int * int)[][] - Array of inner hole polygons.

Returns: int64 Net usable area as a 64-bit integer.

Calculates the net area of a polygon by subtracting the total area of any interior holes (islands).

outer : (int * int)[]

Outer boundary polygon vertices.

holes : (int * int)[][]

Array of inner hole polygons.

Returns: int64

Net usable area as a 64-bit integer.

Example

 let outer = [| (0, 0); (20, 0); (20, 20); (0, 20); (0, 0) |]
 let hole = [| (5, 5); (15, 5); (15, 15); (5, 15); (5, 5) |]
 let net = Goxel.polygonWithHolesArea outer [| hole |]
val outer: (int * int) array
val hole: (int * int) array
val net: obj

removeCollinear pts

Full Usage: removeCollinear pts

Parameters:
    pts : (int * int)[] - Array of 2D polygon vertices.

Returns: (int * int)[] Simplified array of vertices with intermediate collinear points removed.

Removes collinear points from a polygon sequence using integer cross products.

pts : (int * int)[]

Array of 2D polygon vertices.

Returns: (int * int)[]

Simplified array of vertices with intermediate collinear points removed.

Example

 let simplified = Goxel.removeCollinear [| (0, 0); (5, 0); (10, 0); (10, 10) |]
val simplified: obj

removeSawtooth sqn arr

Full Usage: removeSawtooth sqn arr

Parameters:
    sqn : Sqn - Traversal sequence.
    arr : (int * int)[] - Array of integer 2D coordinate points.

Returns: (int * int)[] Filtered array of points with oscillating sawtooth artifacts removed.

Removes aliasing/sawtooth artifacts from a sequence of hex coordinates along the primary axis.

sqn : Sqn

Traversal sequence.

arr : (int * int)[]

Array of integer 2D coordinate points.

Returns: (int * int)[]

Filtered array of points with oscillating sawtooth artifacts removed.

Example

 let smoothed = Goxel.removeSawtooth Hexel.Sqn.VRCWEE [| (0, 0); (2, 1); (4, 0); (6, 1); (8, 0) |]
val smoothed: obj

Type something to start searching.