From 1032717d787b85e9b601e06936ab1ff4d98fa163 Mon Sep 17 00:00:00 2001 From: Jake Beamish Date: Thu, 5 Dec 2024 15:15:11 +0000 Subject: [PATCH] fix(docs): triangle class not annotated correctly --- CHANGELOG.md | 4 ++++ docs/AABB.html | 2 +- docs/AABB.js.html | 4 ++-- docs/Circle.html | 2 +- docs/Circle.js.html | 4 ++-- docs/LCG.html | 4 ++-- docs/Line.html | 2 +- docs/Line.js.html | 4 ++-- docs/Mulberry32.html | 4 ++-- docs/PRNG.html | 2 +- docs/Path.html | 2 +- docs/Path.js.html | 4 ++-- docs/Plot.html | 4 ++-- docs/Plot.js.html | 4 ++-- docs/Quadtree.html | 2 +- docs/Quadtree.js.html | 4 ++-- docs/Random.js.html | 4 ++-- docs/Triangle.html | 3 +++ docs/Triangle.js.html | 8 ++++++-- docs/Triangle_Triangle.html | 3 --- docs/Vector.html | 2 +- docs/Vector.js.html | 4 ++-- docs/XORShift32.html | 4 ++-- docs/data/search.json | 2 +- docs/global.html | 4 ++-- docs/index.html | 4 ++-- docs/utils.js.html | 4 ++-- source/Triangle.js | 4 ++++ 28 files changed, 55 insertions(+), 43 deletions(-) create mode 100644 docs/Triangle.html delete mode 100644 docs/Triangle_Triangle.html diff --git a/CHANGELOG.md b/CHANGELOG.md index cf21dbe..430b601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Documentation for Triangle class. - Tags in changelog link to github. +### Fixed + +- Incorrect Triangle class JSDoc annotation caused class methods to be hidden. + ## [4.2.0] - 2024-12-05 ### Added diff --git a/docs/AABB.html b/docs/AABB.html index cd7c654..6122da1 100644 --- a/docs/AABB.html +++ b/docs/AABB.html @@ -1,3 +1,3 @@ Class: AABB
On this page

AABB

Class representing an AABB.

Constructor

new AABB(x, y, width, height)

Create an AABB using centre position, width, and height.

Parameters:
NameTypeDescription
x*

The x value of the centre.

y*

The y value of the centre.

width*

The width measured from the centre.

height*

The height measured from the centre.

Classes

AABB

Methods

contains(point) → {boolean}

Check if this AABB contains a Vector.

Parameters:
NameTypeDescription
pointVector

The vector to check.

Returns:
Type: 
boolean

intersects(range) → {boolean}

Check if this aabb intersects another AABB.

Parameters:
NameTypeDescription
rangeAABB

The target AABB to check.

Returns:
Type: 
boolean

lines() → {Array.<Line>}

Create an array of Lines containing a line for each side of the AABB.

Returns:
  • An array of Lines that can be added to a Plot using Plot#add.
Type: 
Array.<Line>

(static) fromCorners(topLeft, topRight, bottomRight, bottomLeft) → {AABB}

Create an AABB from four corner Vectors.

Parameters:
NameTypeDescription
topLeftVector
topRightVector
bottomRightVector
bottomLeftVector
Returns:
  • A new AABB object.
Type: 
AABB
\ No newline at end of file +
On this page

AABB

Class representing an AABB.

Constructor

new AABB(x, y, width, height)

Create an AABB using centre position, width, and height.

Parameters:
NameTypeDescription
x*

The x value of the centre.

y*

The y value of the centre.

width*

The width measured from the centre.

height*

The height measured from the centre.

Classes

AABB

Methods

contains(point) → {boolean}

Check if this AABB contains a Vector.

Parameters:
NameTypeDescription
pointVector

The vector to check.

Returns:
Type: 
boolean

intersects(range) → {boolean}

Check if this aabb intersects another AABB.

Parameters:
NameTypeDescription
rangeAABB

The target AABB to check.

Returns:
Type: 
boolean

lines() → {Array.<Line>}

Create an array of Lines containing a line for each side of the AABB.

Returns:
  • An array of Lines that can be added to a Plot using Plot#add.
Type: 
Array.<Line>

(static) fromCorners(topLeft, topRight, bottomRight, bottomLeft) → {AABB}

Create an AABB from four corner Vectors.

Parameters:
NameTypeDescription
topLeftVector
topRightVector
bottomRightVector
bottomLeftVector
Returns:
  • A new AABB object.
Type: 
AABB
\ No newline at end of file diff --git a/docs/AABB.js.html b/docs/AABB.js.html index 64eb90c..c8c2e87 100644 --- a/docs/AABB.js.html +++ b/docs/AABB.js.html @@ -1,6 +1,6 @@ Source: AABB.js
On this page

AABB.js

import { Vector } from "./Vector.js";
+    
On this page

AABB.js

import { Vector } from "./Vector.js";
 import { Line } from "./Line.js";
 
 /** Class representing an AABB. */
@@ -88,4 +88,4 @@
 		return lines;
 	}
 }
-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/Circle.html b/docs/Circle.html index d1fc8a4..1e31d0e 100644 --- a/docs/Circle.html +++ b/docs/Circle.html @@ -1,3 +1,3 @@ Class: Circle
On this page

Circle

Class representing a circle.

Constructor

new Circle(x, y, radius, options)

Create a circle.

Parameters:
NameTypeDescription
xnumber

The x value of the centre.

ynumber

The y value of the centre.

radiusnumber

The radius.

optionsObject
Properties
NameTypeAttributesDefaultDescription
strokestring<optional>
"black"
strokeWidthnumber<optional>
0.1
fillstring<optional>
"none"

Classes

Circle

Methods

toSVGElement() → {SVGElement}

Returns:
Type: 
SVGElement
\ No newline at end of file +
On this page

Circle

Class representing a circle.

Constructor

new Circle(x, y, radius, options)

Create a circle.

Parameters:
NameTypeDescription
xnumber

The x value of the centre.

ynumber

The y value of the centre.

radiusnumber

The radius.

optionsObject
Properties
NameTypeAttributesDefaultDescription
strokestring<optional>
"black"
strokeWidthnumber<optional>
0.1
fillstring<optional>
"none"

Classes

Circle

Methods

toSVGElement() → {SVGElement}

Returns:
Type: 
SVGElement
\ No newline at end of file diff --git a/docs/Circle.js.html b/docs/Circle.js.html index 467bbe2..64e22ae 100644 --- a/docs/Circle.js.html +++ b/docs/Circle.js.html @@ -1,6 +1,6 @@ Source: Circle.js
On this page

Circle.js

/** Class representing a circle. */
+    
On this page

Circle.js

/** Class representing a circle. */
 export class Circle {
 	/**
 	 * Create a circle.
@@ -45,4 +45,4 @@
 		return element;
 	}
 }
-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/LCG.html b/docs/LCG.html index b42745a..9af4d17 100644 --- a/docs/LCG.html +++ b/docs/LCG.html @@ -1,4 +1,4 @@ Class: LCG
On this page

LCG

LCG (Linear Congruential Generator) Pseudorandom Number Generator Class

Constructor

new LCG(seed)

Implements the LCG algorithm to generate pseudorandom numbers.

This class provides the LCG algorithm for generating psuedorandom numbers to the PRNG class.

Parameters:
NameTypeDescription
seednumber

The seed value for the LCG PRNG.

Implements
Example
const rng = new LCG(123456789);
-console.log(rng.next()); // Generates a pseudorandom number

Classes

LCG

Implements the LCG algorithm to generate pseudorandom numbers.

Methods

next() → {number}

Generates the next pseudorandom number.

Returns:

A number in the range [0 to this.modulus - 1).

Type: 
number
\ No newline at end of file +
On this page

LCG

LCG (Linear Congruential Generator) Pseudorandom Number Generator Class

Constructor

new LCG(seed)

Implements the LCG algorithm to generate pseudorandom numbers.

This class provides the LCG algorithm for generating psuedorandom numbers to the PRNG class.

Parameters:
NameTypeDescription
seednumber

The seed value for the LCG PRNG.

Implements
Example
const rng = new LCG(123456789);
+console.log(rng.next()); // Generates a pseudorandom number

Classes

LCG

Implements the LCG algorithm to generate pseudorandom numbers.

Methods

next() → {number}

Generates the next pseudorandom number.

Returns:

A number in the range [0 to this.modulus - 1).

Type: 
number
\ No newline at end of file diff --git a/docs/Line.html b/docs/Line.html index df1cf29..bdd74ad 100644 --- a/docs/Line.html +++ b/docs/Line.html @@ -1,3 +1,3 @@ Class: Line
On this page

Line

Class representing a line.

Constructor

new Line(a, b)

Create a line between two Vectors.

Parameters:
NameTypeAttributesDefaultDescription
aVector

The startpoint.

bVector

The endpoint.

options.strokestring<optional>
"black"
options.strokeWidthnumber<optional>
0.1

Classes

Line

Methods

intersects(target) → {boolean|Array}

Check if this line intersects another shape. Currently only Line is supported.

Parameters:
NameTypeDescription
targetobject

The target.

Returns:
  • False if lines don't intersect, otherwise returns the intersection point [x,y]
Type: 
boolean | Array

isContainedBy(line) → {boolean}

Check if this line lies directly on top of a longer line.

Parameters:
NameTypeDescription
lineLine

The target line to check against.

Returns:
  • True if this line's startpoint and endpoint are both on the line being checked against, otherwise False.
Type: 
boolean

isDuplicate(line) → {boolean}

Check if this line is the same as another line.

Parameters:
NameTypeDescription
lineLine

The target line to compare to.

Returns:

True if startpoints and endpoints are identical or in reverse.

Type: 
boolean

length() → {number}

Get the length.

Returns:

The distance from the startpoint to the endpoint. Uses the Vector#distance method.

Type: 
number

toSVGElement() → {SVGElement}

Returns:
Type: 
SVGElement

(static) fromArray(array) → {Line}

Create a Line from an array of numbers.

Parameters:
NameTypeDescription
arrayArray.<number>

[x1, y1, x2, y2].

Returns:
Type: 
Line

(static) lineIntersection(line1, line2) → {boolean|Array}

Check if two lines intersect.

Parameters:
NameTypeDescription
line1Line
line2Line
Returns:
  • False if lines don't intersect, otherwise returns the intersection point [x,y]
Type: 
boolean | Array
\ No newline at end of file +
On this page

Line

Class representing a line.

Constructor

new Line(a, b)

Create a line between two Vectors.

Parameters:
NameTypeAttributesDefaultDescription
aVector

The startpoint.

bVector

The endpoint.

options.strokestring<optional>
"black"
options.strokeWidthnumber<optional>
0.1

Classes

Line

Methods

intersects(target) → {boolean|Array}

Check if this line intersects another shape. Currently only Line is supported.

Parameters:
NameTypeDescription
targetobject

The target.

Returns:
  • False if lines don't intersect, otherwise returns the intersection point [x,y]
Type: 
boolean | Array

isContainedBy(line) → {boolean}

Check if this line lies directly on top of a longer line.

Parameters:
NameTypeDescription
lineLine

The target line to check against.

Returns:
  • True if this line's startpoint and endpoint are both on the line being checked against, otherwise False.
Type: 
boolean

isDuplicate(line) → {boolean}

Check if this line is the same as another line.

Parameters:
NameTypeDescription
lineLine

The target line to compare to.

Returns:

True if startpoints and endpoints are identical or in reverse.

Type: 
boolean

length() → {number}

Get the length.

Returns:

The distance from the startpoint to the endpoint. Uses the Vector#distance method.

Type: 
number

toSVGElement() → {SVGElement}

Returns:
Type: 
SVGElement

(static) fromArray(array) → {Line}

Create a Line from an array of numbers.

Parameters:
NameTypeDescription
arrayArray.<number>

[x1, y1, x2, y2].

Returns:
Type: 
Line

(static) lineIntersection(line1, line2) → {boolean|Array}

Check if two lines intersect.

Parameters:
NameTypeDescription
line1Line
line2Line
Returns:
  • False if lines don't intersect, otherwise returns the intersection point [x,y]
Type: 
boolean | Array
\ No newline at end of file diff --git a/docs/Line.js.html b/docs/Line.js.html index fb591ed..c2f3ef7 100644 --- a/docs/Line.js.html +++ b/docs/Line.js.html @@ -1,6 +1,6 @@ Source: Line.js
On this page

Line.js

import { Vector } from "./Vector.js";
+    
On this page

Line.js

import { Vector } from "./Vector.js";
 /** Class representing a line. */
 export class Line {
 	/**
@@ -139,4 +139,4 @@
 		return element;
 	}
 }
-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/Mulberry32.html b/docs/Mulberry32.html index 87b1776..e981730 100644 --- a/docs/Mulberry32.html +++ b/docs/Mulberry32.html @@ -1,6 +1,6 @@ Class: Mulberry32
On this page

Mulberry32

Mulberry32 Pseudorandom Number Generator Class

Constructor

new Mulberry32(seed)

Implements the Mulberry32 algorithm to generate pseudorandom numbers.

This class provides the Mulberry32 method of generating psuedorandom numbers to the PRNG class.

The Mulberry32 algorithm was written by Tommy Ettinger in 2017 and is released to the public domain, meaning it can be freely used, modified, and distributed without restrictions.

Parameters:
NameTypeDescription
seednumber

The seed value for the Mulberry32 PRNG.

Implements
Example
const rng = new Mulberry32(123456789);
+    
On this page

Mulberry32

Mulberry32 Pseudorandom Number Generator Class

Constructor

new Mulberry32(seed)

Implements the Mulberry32 algorithm to generate pseudorandom numbers.

This class provides the Mulberry32 method of generating psuedorandom numbers to the PRNG class.

The Mulberry32 algorithm was written by Tommy Ettinger in 2017 and is released to the public domain, meaning it can be freely used, modified, and distributed without restrictions.

Parameters:
NameTypeDescription
seednumber

The seed value for the Mulberry32 PRNG.

Implements
Example
const rng = new Mulberry32(123456789);
 console.log(rng.next()); // Generates a pseudorandom number

Classes

Mulberry32

Implements the Mulberry32 algorithm to generate pseudorandom numbers.

Methods

next() → {number}

Generates the next psuedo-random number.

Returns:

A number in the range [0-1).

Type: 
number
Example
// Returns a random number in the range [0-1)
 const rng = new Mulberry32();
-console.log(rng.next());
\ No newline at end of file +console.log(rng.next());
\ No newline at end of file diff --git a/docs/PRNG.html b/docs/PRNG.html index 35f9c4f..a279dc3 100644 --- a/docs/PRNG.html +++ b/docs/PRNG.html @@ -1,3 +1,3 @@ Class: PRNG
On this page

PRNG

new PRNG(optionsopt)

Creates an instance of PRNG.

Parameters:
NameTypeAttributesDefaultDescription
optionsObject<optional>
{}

The configuration options for the PRNG.

Properties
NameTypeAttributesDefaultDescription
seednumber<optional>
Date.now()

The default seed value for the PRNG is the current timestamp.

algorithmPRNGAlgorithm<optional>
XORShift32

The algorithm to use for generating psuedo-random numbers.

Classes

PRNG

Methods

randomBipolarFloat() → {number}

Generate a random float in the range [-1, 1).

Returns:
  • A number between -1 (inclusive) and 1 (exclusive).
Type: 
number

randomChance(chanceopt) → {boolean}

Returns a boolean based on a specified probability.

Parameters:
NameTypeAttributesDefaultDescription
chancenumber<optional>
0.5

The probability of returning true (between 0 and 1).

Returns:
  • True if the random float is less than the chance, otherwise false.
Type: 
boolean

randomElement(array) → {*}

Select a random element from an array.

Parameters:
NameTypeDescription
arrayarray

The array from which to select an element.

Returns:
  • A randomly selected element from the array.
Type: 
*

randomFloat(maxopt, minopt) → {number}

Generate a random float in the range [0, 1).

Parameters:
NameTypeAttributesDefaultDescription
maxnumber<optional>
1

A single argument specifies a range of between 0 and that number.

minnumber<optional>
0

Two numeric arguments specifies a range.

Returns:
  • A floating-point number in a given range, 0 (inclusive) and 1 (exclusive) if called without arguments.
Type: 
number

randomInteger(min, max) → {number}

Generate a random integer from a specified range of values.

Parameters:
NameTypeDescription
minnumber

The minimum integer value (inclusive).

maxnumber

The maximum integer value (exclusive).

Returns:
  • A random integer between min (inclusive) and max (exclusive).
Type: 
number

randomUnitVector() → {Vector}

Generate a random unit vector.

Returns:
  • A Vector with a magnitude of 1 and a random angle between 0 and TWO_PI.
Type: 
Vector

randomWeighted(choices) → {function|number|string}

Selects an option probabalistically from a set of weighted choices.

Parameters:
NameTypeDescription
choicesArray.<Object>

An array of objects with option and weight properties.

Properties
NameTypeDescription
optionfunction | number | string

The outcome of the choice.

weightnumber

The weight of the choice. Higher weights (relative to the other choices) increase the likelihood of selection.

Returns:
  • The selected option.
Type: 
function | number | string
\ No newline at end of file +
On this page

PRNG

new PRNG(optionsopt)

Creates an instance of PRNG.

Parameters:
NameTypeAttributesDefaultDescription
optionsObject<optional>
{}

The configuration options for the PRNG.

Properties
NameTypeAttributesDefaultDescription
seednumber<optional>
Date.now()

The default seed value for the PRNG is the current timestamp.

algorithmPRNGAlgorithm<optional>
XORShift32

The algorithm to use for generating psuedo-random numbers.

Classes

PRNG

Methods

randomBipolarFloat() → {number}

Generate a random float in the range [-1, 1).

Returns:
  • A number between -1 (inclusive) and 1 (exclusive).
Type: 
number

randomChance(chanceopt) → {boolean}

Returns a boolean based on a specified probability.

Parameters:
NameTypeAttributesDefaultDescription
chancenumber<optional>
0.5

The probability of returning true (between 0 and 1).

Returns:
  • True if the random float is less than the chance, otherwise false.
Type: 
boolean

randomElement(array) → {*}

Select a random element from an array.

Parameters:
NameTypeDescription
arrayarray

The array from which to select an element.

Returns:
  • A randomly selected element from the array.
Type: 
*

randomFloat(maxopt, minopt) → {number}

Generate a random float in the range [0, 1).

Parameters:
NameTypeAttributesDefaultDescription
maxnumber<optional>
1

A single argument specifies a range of between 0 and that number.

minnumber<optional>
0

Two numeric arguments specifies a range.

Returns:
  • A floating-point number in a given range, 0 (inclusive) and 1 (exclusive) if called without arguments.
Type: 
number

randomInteger(min, max) → {number}

Generate a random integer from a specified range of values.

Parameters:
NameTypeDescription
minnumber

The minimum integer value (inclusive).

maxnumber

The maximum integer value (exclusive).

Returns:
  • A random integer between min (inclusive) and max (exclusive).
Type: 
number

randomUnitVector() → {Vector}

Generate a random unit vector.

Returns:
  • A Vector with a magnitude of 1 and a random angle between 0 and TWO_PI.
Type: 
Vector

randomWeighted(choices) → {function|number|string}

Selects an option probabalistically from a set of weighted choices.

Parameters:
NameTypeDescription
choicesArray.<Object>

An array of objects with option and weight properties.

Properties
NameTypeDescription
optionfunction | number | string

The outcome of the choice.

weightnumber

The weight of the choice. Higher weights (relative to the other choices) increase the likelihood of selection.

Returns:
  • The selected option.
Type: 
function | number | string
\ No newline at end of file diff --git a/docs/Path.html b/docs/Path.html index 71a89a9..c9c37d5 100644 --- a/docs/Path.html +++ b/docs/Path.html @@ -1,3 +1,3 @@ Class: Path
On this page

Path

Class representing a path.

Constructor

new Path(points, optionsopt)

Parameters:
NameTypeAttributesDescription
pointsArray.<Vector>

An array of Vectors from which a Path is made.

optionsObject<optional>
Properties
NameTypeAttributesDefaultDescription
strokestring<optional>
"black"
strokeWidthnumber<optional>
0.1
fillstring<optional>
"none"
isClosedboolean<optional>
false

A flag to optionally close the Path.

Classes

Path
\ No newline at end of file +
On this page

Path

Class representing a path.

Constructor

new Path(points, optionsopt)

Parameters:
NameTypeAttributesDescription
pointsArray.<Vector>

An array of Vectors from which a Path is made.

optionsObject<optional>
Properties
NameTypeAttributesDefaultDescription
strokestring<optional>
"black"
strokeWidthnumber<optional>
0.1
fillstring<optional>
"none"
isClosedboolean<optional>
false

A flag to optionally close the Path.

Classes

Path
\ No newline at end of file diff --git a/docs/Path.js.html b/docs/Path.js.html index 5a8c529..1d2c4c7 100644 --- a/docs/Path.js.html +++ b/docs/Path.js.html @@ -1,6 +1,6 @@ Source: Path.js
On this page

Path.js

/** Class representing a path. */
+    
On this page

Path.js

/** Class representing a path. */
 export class Path {
 	/**
 	 * @param {Array<Vector>} points - An array of [Vectors]{@link Vector} from which a Path is made.
@@ -51,4 +51,4 @@
 		return pathElement;
 	}
 }
-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/Plot.html b/docs/Plot.html index 2a15630..f6b39a7 100644 --- a/docs/Plot.html +++ b/docs/Plot.html @@ -1,6 +1,6 @@ Class: Plot
On this page

Plot

Plot is an object that is able to create, display and download SVG documents.

Constructor

new Plot(optionsopt)

Parameters:
NameTypeAttributesDescription
optionsobject<optional>

An object containing configuration for Plot.

Properties
NameTypeAttributesDefaultDescription
sizeobject<optional>

An object with width and height properties to be used as dimensions of the Plot.

Properties
NameTypeAttributesDefaultDescription
widthnumber<optional>
100

The width of the Plot.

heightnumber<optional>
100

The height of the Plot.

titlestring<optional>
"Untitled"

The title of the Plot.

unitsstring<optional>
"mm"

The units of measurement to be used (i.e. "mm" or "in").

backgroundColorstring<optional>
"transparent"

The background colour of the plot, as a hex value or HTML color name.

seednumber<optional>

The seed to be used for the Plot. Defaults to an 8 digit hexadecimal integer.

strokestring<optional>
"black"

The foreground colour of the plot, as a hex value or HTML color name.

strokeWidthnumber<optional>
1

The line width of the Plot. Defaults to 1 unit. (1mm)

minimumLineLengthnumber<optional>
0.1

Lines shorter than this length are not drawn.

Classes

Plot

Methods

add(shape)

Adds shapes to the plot.

Parameters:
NameTypeDescription
shapeLine | Circle | Path | Array

An object or array of objects to be added to the plot.

Example
import { Plot, Line, Circle } from "@jakebeamish/penplotting";
+    
On this page

Plot

Plot is an object that is able to create, display and download SVG documents.

Constructor

new Plot(optionsopt)

Parameters:
NameTypeAttributesDescription
optionsobject<optional>

An object containing configuration for Plot.

Properties
NameTypeAttributesDefaultDescription
sizeobject<optional>

An object with width and height properties to be used as dimensions of the Plot.

Properties
NameTypeAttributesDefaultDescription
widthnumber<optional>
100

The width of the Plot.

heightnumber<optional>
100

The height of the Plot.

titlestring<optional>
"Untitled"

The title of the Plot.

unitsstring<optional>
"mm"

The units of measurement to be used (i.e. "mm" or "in").

backgroundColorstring<optional>
"transparent"

The background colour of the plot, as a hex value or HTML color name.

seednumber<optional>

The seed to be used for the Plot. Defaults to an 8 digit hexadecimal integer.

strokestring<optional>
"black"

The foreground colour of the plot, as a hex value or HTML color name.

strokeWidthnumber<optional>
1

The line width of the Plot. Defaults to 1 unit. (1mm)

minimumLineLengthnumber<optional>
0.1

Lines shorter than this length are not drawn.

Classes

Plot

Methods

add(shape)

Adds shapes to the plot.

Parameters:
NameTypeDescription
shapeLine | Circle | Path | Array

An object or array of objects to be added to the plot.

Example
import { Plot, Line, Circle } from "@jakebeamish/penplotting";
 
 const plot = new Plot({
     backgroundColor: "#ffffff"
@@ -16,4 +16,4 @@
     plot.add([line, circlesArray]);
 }
 
-plot.draw();

addCirclesToSVG()

Adds the Circles in this Plot's circles array to it's SVG element.

addLinesToSVG()

Adds the Lines in this Plot's lines array to it's SVG element.

addPathsToSVG()

Adds the Paths in this Plot's paths array to it's SVG element.

(private) addSingleShape(shape)

Adds a single shape to the appropriate array. Used by Plot#add.

Parameters:
NameTypeDescription
shapeLine | Path | Circle

appendSVG()

Appends this plot's SVG element to the document body.

clear()

Empty out any existing HTML UI and SVG document elements on the page, in order to regenerate a Plot.

createUI(timeTaken)

Creates HTML UI and adds it to the document body.

Parameters:
NameTypeDescription
timeTakennumber

deduplicateLines()

Removes duplicated Lines from this Plot's lines array.

downloadSVG()

Download the Plot as an SVG file.

draw()

Generates the SVG and UI and appends them to the document body. Must be called after defining a Plot.generate() function.

filename() → {string}

Returns:
  • The file name to be used for the Plot's SVG file, as a string in the format Title_ffffffff_210x297mm.svg
Type: 
string

removeOverlappingLines()

Removes overlapping Lines from this Plot's lines array.

removeShortLines(minimumLength)

Removes Lines in this Plot's lines array that are shorter than a specified minimum length.

Parameters:
NameTypeDescription
minimumLengthnumber
\ No newline at end of file +plot.draw();

addCirclesToSVG()

Adds the Circles in this Plot's circles array to it's SVG element.

addLinesToSVG()

Adds the Lines in this Plot's lines array to it's SVG element.

addPathsToSVG()

Adds the Paths in this Plot's paths array to it's SVG element.

(private) addSingleShape(shape)

Adds a single shape to the appropriate array. Used by Plot#add.

Parameters:
NameTypeDescription
shapeLine | Path | Circle

appendSVG()

Appends this plot's SVG element to the document body.

clear()

Empty out any existing HTML UI and SVG document elements on the page, in order to regenerate a Plot.

createUI(timeTaken)

Creates HTML UI and adds it to the document body.

Parameters:
NameTypeDescription
timeTakennumber

deduplicateLines()

Removes duplicated Lines from this Plot's lines array.

downloadSVG()

Download the Plot as an SVG file.

draw()

Generates the SVG and UI and appends them to the document body. Must be called after defining a Plot.generate() function.

filename() → {string}

Returns:
  • The file name to be used for the Plot's SVG file, as a string in the format Title_ffffffff_210x297mm.svg
Type: 
string

removeOverlappingLines()

Removes overlapping Lines from this Plot's lines array.

removeShortLines(minimumLength)

Removes Lines in this Plot's lines array that are shorter than a specified minimum length.

Parameters:
NameTypeDescription
minimumLengthnumber
\ No newline at end of file diff --git a/docs/Plot.js.html b/docs/Plot.js.html index e0b793f..63810ca 100644 --- a/docs/Plot.js.html +++ b/docs/Plot.js.html @@ -1,6 +1,6 @@ Source: Plot.js
On this page

Plot.js

import { unseededRandomHex } from "./Random.js";
+    
On this page

Plot.js

import { unseededRandomHex } from "./Random.js";
 import { hexToDec } from "./utils.js";
 import { decToHex } from "./utils.js";
 import { Line } from "./Line.js";
@@ -416,4 +416,4 @@
 		this.addPlotInfo(header, timeTaken);
 	}
 }
-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/Quadtree.html b/docs/Quadtree.html index 0a5a944..fe28832 100644 --- a/docs/Quadtree.html +++ b/docs/Quadtree.html @@ -1,3 +1,3 @@ Class: Quadtree
On this page

Quadtree

Class representing a quadtree.

This implementation is adapted from CodingTrain/QuadTree, which is licensed under an MIT License.

Constructor

new Quadtree(boundary, capacity)

Create a quadtree.

Parameters:
NameTypeDescription
boundaryAABB

The bounding box of the quadtree.

capacitynumber

The number of points that can be inserted into Quadtree without subdividing.

Classes

Quadtree

Methods

insert(point)

Add a point into this quadtree.

Parameters:
NameTypeDescription
pointVector

query(range) → {Array.<Vector>}

Check for points in a given range and return them in an array.

Parameters:
NameTypeDescription
rangeAABB

The bounding box of the query.

Returns:
Type: 
Array.<Vector>

show(plot)

For each boundary of this quadtree and all it's children, create Lines from those rectangles and add them to a Plot.

Parameters:
NameTypeDescription
plotPlot
\ No newline at end of file +
On this page

Quadtree

Class representing a quadtree.

This implementation is adapted from CodingTrain/QuadTree, which is licensed under an MIT License.

Constructor

new Quadtree(boundary, capacity)

Create a quadtree.

Parameters:
NameTypeDescription
boundaryAABB

The bounding box of the quadtree.

capacitynumber

The number of points that can be inserted into Quadtree without subdividing.

Classes

Quadtree

Methods

insert(point)

Add a point into this quadtree.

Parameters:
NameTypeDescription
pointVector

query(range) → {Array.<Vector>}

Check for points in a given range and return them in an array.

Parameters:
NameTypeDescription
rangeAABB

The bounding box of the query.

Returns:
Type: 
Array.<Vector>

show(plot)

For each boundary of this quadtree and all it's children, create Lines from those rectangles and add them to a Plot.

Parameters:
NameTypeDescription
plotPlot
\ No newline at end of file diff --git a/docs/Quadtree.js.html b/docs/Quadtree.js.html index c43b9bb..290bcf9 100644 --- a/docs/Quadtree.js.html +++ b/docs/Quadtree.js.html @@ -1,6 +1,6 @@ Source: Quadtree.js
On this page

Quadtree.js

import { AABB } from "./AABB.js";
+    
On this page

Quadtree.js

import { AABB } from "./AABB.js";
 
 /**
  * Class representing a quadtree.
@@ -125,4 +125,4 @@
 		}
 	}
 }
-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/Random.js.html b/docs/Random.js.html index 93d82a1..5d64592 100644 --- a/docs/Random.js.html +++ b/docs/Random.js.html @@ -1,6 +1,6 @@ Source: Random.js
On this page

Random.js

import { Vector } from "./Vector.js";
+    
On this page

Random.js

import { Vector } from "./Vector.js";
 
 /**
  * A PRNGAlgorithm is a class that implements some technique for random number
@@ -275,4 +275,4 @@
 		decimal,
 	};
 }
-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/Triangle.html b/docs/Triangle.html new file mode 100644 index 0000000..b928577 --- /dev/null +++ b/docs/Triangle.html @@ -0,0 +1,3 @@ +Class: Triangle
On this page

Triangle

Class representing a triangle.

\ No newline at end of file diff --git a/docs/Triangle.js.html b/docs/Triangle.js.html index caa3dae..7eb0da3 100644 --- a/docs/Triangle.js.html +++ b/docs/Triangle.js.html @@ -1,8 +1,12 @@ Source: Triangle.js
On this page

Triangle.js

import { Vector } from "./Vector.js";
+    
On this page

Triangle.js

import { Vector } from "./Vector.js";
 import { Line } from "./Line.js";
 
+
+/**
+ * Class representing a triangle.
+ */
 export class Triangle {
 	/**
 	 * Create a triangle.
@@ -30,4 +34,4 @@
 		];
 	}
 }
-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/Triangle_Triangle.html b/docs/Triangle_Triangle.html deleted file mode 100644 index 9ada57a..0000000 --- a/docs/Triangle_Triangle.html +++ /dev/null @@ -1,3 +0,0 @@ -Class: Triangle
On this page

Triangle

\ No newline at end of file diff --git a/docs/Vector.html b/docs/Vector.html index 64ba616..f7506d3 100644 --- a/docs/Vector.html +++ b/docs/Vector.html @@ -1,3 +1,3 @@ Class: Vector
On this page

Vector

Class representing a Vector.

Constructor

new Vector(x, y)

Create a vector from coordinates.

Parameters:
NameTypeDefaultDescription
xnumber0

x

ynumber0

y

Classes

Vector

Methods

add(vector) → {Vector}

Add a vector to this vector.

Parameters:
NameTypeDescription
vectorVector
Returns:
Type: 
Vector

clone() → {Vector}

Make a copy of this vector.

Returns:
Type: 
Vector

distance(vector) → {number}

Calculate the distance to another vector from this vector

Parameters:
NameTypeDescription
vectorVector
Returns:
Type: 
number

equals(vector) → {boolean}

Check if this vector is equivalent to another vector.

Parameters:
NameTypeDescription
vectorVector
Returns:
Type: 
boolean

getAngle() → {number}

Get the angle of this vector with respect to the positive x-axis.

Returns:

Angle in radians

Type: 
number

getMagnitude() → {number}

Get the magnitude of this vector.

Returns:

The magnitude (Euclidean distance) of this vector

Type: 
number

isOnLine(line) → {boolean}

Check if this vector is a point on a Line.

Parameters:
NameTypeDescription
lineLine
Returns:
Type: 
boolean

multiply(scalar) → {Vector}

Multiply this vector by a scalar.

Parameters:
NameTypeDescription
scalarnumber
Returns:
Type: 
Vector

nearestNeighbour(array, n) → {Array.<Vector>}

Finds the n nearest neighbours to this vector, from a given array of vectors.

Parameters:
NameTypeDescription
arrayArray.<Vector>

An array of Vectors to check.

nnumber

The number of neighbours to find (must be > 0).

Returns:
Type: 
Array.<Vector>

normalize() → {Vector}

Normalize this vector by setting it's magnitude to 1.

Returns:
Type: 
Vector

rotate(angle) → {Vector}

Rotate this vector by a specified angle.

Parameters:
NameTypeDescription
anglenumber

The angle to rotate the vector by, in radians.

Returns:

This vector after rotation.

Type: 
Vector

setMagnitude(magnitude) → {Vector}

Set the magnitude of this vector.

Parameters:
NameTypeDescription
magnitudenumber
Returns:
Type: 
Vector

subtract(vector) → {Vector}

Subtract a vector from this vector.

Parameters:
NameTypeDescription
vectorVector
Returns:
Type: 
Vector

toArray() → {array}

Create an array from the vector's components.

Returns:

[x, y]

Type: 
array

(static) add(v1, v2) → {Vector}

Add two vectors.

Parameters:
NameTypeDescription
v1Vector
v2Vector
Returns:
Type: 
Vector

(static) cross(v1, v2) → {number}

Calculate the cross product of two 2D vectors.

Parameters:
NameTypeDescription
v1Vector
v2Vector
Returns:
Type: 
number

(static) distance(v1, v2) → {number}

Calculate the distance between two vectors.

Parameters:
NameTypeDescription
v1Vector
v2Vector
Returns:
Type: 
number

(static) dot(v1, v2) → {number}

Calculate the dot product of two vectors.

Parameters:
NameTypeDescription
v1Vector
v2Vector
Returns:
Type: 
number

(static) fromAngle(angle, magnitudeopt) → {Vector}

Create a vector from an angle.

Parameters:
NameTypeAttributesDefaultDescription
anglenumber

The angle of the vector in radians.

magnitudenumber<optional>
1

The magnitude of the vector.

Returns:
Type: 
Vector

(static) fromArray(array) → {Vector}

Create a vector from an array.

Parameters:
NameTypeDescription
arrayarray

[x, y]

Returns:
Type: 
Vector

(static) lerp(v1, v2, amount) → {Vector}

Linear interpolation between vectors.

Parameters:
NameTypeDescription
v1Vector
v2Vector
amountnumber
Returns:
Type: 
Vector

(static) subtract(v1, v2) → {Vector}

Subtract two vectors.

Parameters:
NameTypeDescription
v1Vector
v2Vector
Returns:
Type: 
Vector
\ No newline at end of file +
On this page

Vector

Class representing a Vector.

Constructor

new Vector(x, y)

Create a vector from coordinates.

Parameters:
NameTypeDefaultDescription
xnumber0

x

ynumber0

y

Classes

Vector

Methods

add(vector) → {Vector}

Add a vector to this vector.

Parameters:
NameTypeDescription
vectorVector
Returns:
Type: 
Vector

clone() → {Vector}

Make a copy of this vector.

Returns:
Type: 
Vector

distance(vector) → {number}

Calculate the distance to another vector from this vector

Parameters:
NameTypeDescription
vectorVector
Returns:
Type: 
number

equals(vector) → {boolean}

Check if this vector is equivalent to another vector.

Parameters:
NameTypeDescription
vectorVector
Returns:
Type: 
boolean

getAngle() → {number}

Get the angle of this vector with respect to the positive x-axis.

Returns:

Angle in radians

Type: 
number

getMagnitude() → {number}

Get the magnitude of this vector.

Returns:

The magnitude (Euclidean distance) of this vector

Type: 
number

isOnLine(line) → {boolean}

Check if this vector is a point on a Line.

Parameters:
NameTypeDescription
lineLine
Returns:
Type: 
boolean

multiply(scalar) → {Vector}

Multiply this vector by a scalar.

Parameters:
NameTypeDescription
scalarnumber
Returns:
Type: 
Vector

nearestNeighbour(array, n) → {Array.<Vector>}

Finds the n nearest neighbours to this vector, from a given array of vectors.

Parameters:
NameTypeDescription
arrayArray.<Vector>

An array of Vectors to check.

nnumber

The number of neighbours to find (must be > 0).

Returns:
Type: 
Array.<Vector>

normalize() → {Vector}

Normalize this vector by setting it's magnitude to 1.

Returns:
Type: 
Vector

rotate(angle) → {Vector}

Rotate this vector by a specified angle.

Parameters:
NameTypeDescription
anglenumber

The angle to rotate the vector by, in radians.

Returns:

This vector after rotation.

Type: 
Vector

setMagnitude(magnitude) → {Vector}

Set the magnitude of this vector.

Parameters:
NameTypeDescription
magnitudenumber
Returns:
Type: 
Vector

subtract(vector) → {Vector}

Subtract a vector from this vector.

Parameters:
NameTypeDescription
vectorVector
Returns:
Type: 
Vector

toArray() → {array}

Create an array from the vector's components.

Returns:

[x, y]

Type: 
array

(static) add(v1, v2) → {Vector}

Add two vectors.

Parameters:
NameTypeDescription
v1Vector
v2Vector
Returns:
Type: 
Vector

(static) cross(v1, v2) → {number}

Calculate the cross product of two 2D vectors.

Parameters:
NameTypeDescription
v1Vector
v2Vector
Returns:
Type: 
number

(static) distance(v1, v2) → {number}

Calculate the distance between two vectors.

Parameters:
NameTypeDescription
v1Vector
v2Vector
Returns:
Type: 
number

(static) dot(v1, v2) → {number}

Calculate the dot product of two vectors.

Parameters:
NameTypeDescription
v1Vector
v2Vector
Returns:
Type: 
number

(static) fromAngle(angle, magnitudeopt) → {Vector}

Create a vector from an angle.

Parameters:
NameTypeAttributesDefaultDescription
anglenumber

The angle of the vector in radians.

magnitudenumber<optional>
1

The magnitude of the vector.

Returns:
Type: 
Vector

(static) fromArray(array) → {Vector}

Create a vector from an array.

Parameters:
NameTypeDescription
arrayarray

[x, y]

Returns:
Type: 
Vector

(static) lerp(v1, v2, amount) → {Vector}

Linear interpolation between vectors.

Parameters:
NameTypeDescription
v1Vector
v2Vector
amountnumber
Returns:
Type: 
Vector

(static) subtract(v1, v2) → {Vector}

Subtract two vectors.

Parameters:
NameTypeDescription
v1Vector
v2Vector
Returns:
Type: 
Vector
\ No newline at end of file diff --git a/docs/Vector.js.html b/docs/Vector.js.html index f60f4e3..16ec8aa 100644 --- a/docs/Vector.js.html +++ b/docs/Vector.js.html @@ -1,6 +1,6 @@ Source: Vector.js
On this page

Vector.js

import { lerp } from "./utils.js";
+    
On this page

Vector.js

import { lerp } from "./utils.js";
 
 /**
  * Class representing a Vector.
@@ -277,4 +277,4 @@
     return neighbours;
   }
 }
-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/XORShift32.html b/docs/XORShift32.html index 451b857..e698407 100644 --- a/docs/XORShift32.html +++ b/docs/XORShift32.html @@ -1,6 +1,6 @@ Class: XORShift32
On this page

XORShift32

XORShift32 Pseudorandom Number Generator Class

Constructor

new XORShift32(seed)

Implements the XORShift32 algorithm to generate pseudorandom numbers.

This class provides the XORShift32 method of generating psuedorandom numbers to the PRNG class. It uses bitwise operations to generate a sequence of pseudorandom 32-bit unsigned integers.

The XORShift algorithm was written by George Marsaglia in 2003 and is released to the public domain, meaning it can be freely used, modified, and distributed without restrictions.

Parameters:
NameTypeDescription
seednumber

The seed value for the PRNG.

Implements
See
  • Marsaglia, G. (2003) "XORShift RNGs", Journal of Statistical Software https://www.jstatsoft.org/article/view/v008i14
Example
const prng = new XORShift32(123456789);
+    
On this page

XORShift32

XORShift32 Pseudorandom Number Generator Class

Constructor

new XORShift32(seed)

Implements the XORShift32 algorithm to generate pseudorandom numbers.

This class provides the XORShift32 method of generating psuedorandom numbers to the PRNG class. It uses bitwise operations to generate a sequence of pseudorandom 32-bit unsigned integers.

The XORShift algorithm was written by George Marsaglia in 2003 and is released to the public domain, meaning it can be freely used, modified, and distributed without restrictions.

Parameters:
NameTypeDescription
seednumber

The seed value for the PRNG.

Implements
See
  • Marsaglia, G. (2003) "XORShift RNGs", Journal of Statistical Software https://www.jstatsoft.org/article/view/v008i14
Example
const prng = new XORShift32(123456789);
 console.log(prng.next()); // Generates a pseudorandom number

Classes

XORShift32

Implements the XORShift32 algorithm to generate pseudorandom numbers.

Methods

next() → {number}

Generates the next psuedo-random number.

Returns:

A number in the range [0-1).

Type: 
number
Example
// Returns a random number in the range [0-1)
 const rng = new XORShift32();
-console.log(rng.next());
\ No newline at end of file +console.log(rng.next());
\ No newline at end of file diff --git a/docs/data/search.json b/docs/data/search.json index 9cf559c..fb94793 100644 --- a/docs/data/search.json +++ b/docs/data/search.json @@ -1 +1 @@ -{"list":[{"title":"AABB","link":"AABB","description":"

Create an AABB using centre position, width, and height.

"},{"title":"AABB#contains","link":"contains","description":"

Check if this AABB contains a {@link Vector}.

"},{"title":"AABB#intersects","link":"intersects","description":"

Check if this aabb intersects another AABB.

"},{"title":"AABB#lines","link":"lines","description":"

Create an array of [Lines]{@link Line}\ncontaining a line for each side of the AABB.

"},{"title":"AABB.fromCorners","link":"fromCorners","description":"

Create an AABB from four corner [Vectors]{@link Vector}.

"},{"title":"Circle","link":"Circle","description":"

Create a circle.

"},{"title":"Circle#toSVGElement","link":"toSVGElement"},{"title":"LCG","link":"LCG","description":"

This class provides the LCG algorithm for generating psuedorandom\nnumbers to the {@link PRNG} class.

"},{"title":"LCG#next","link":"next","description":"

Generates the next pseudorandom number.

"},{"title":"Line","link":"Line","description":"

Create a line between two [Vectors]{@link Vector}.

"},{"title":"Line#intersects","link":"intersects","description":"

Check if this line intersects another shape.\nCurrently only {@link Line} is supported.

"},{"title":"Line#isContainedBy","link":"isContainedBy","description":"

Check if this line lies directly on top of a longer line.

"},{"title":"Line#isDuplicate","link":"isDuplicate","description":"

Check if this line is the same as another line.

"},{"title":"Line#length","link":"length","description":"

Get the length.

"},{"title":"Line#toSVGElement","link":"toSVGElement"},{"title":"Line.fromArray","link":"fromArray","description":"

Create a Line from an array of numbers.

"},{"title":"Line.lineIntersection","link":"lineIntersection","description":"

Check if two lines intersect.

"},{"title":"Mulberry32","link":"Mulberry32","description":"

This class provides the Mulberry32 method of generating psuedorandom\nnumbers to the {@link PRNG} class.

\n

The Mulberry32 algorithm was written by Tommy Ettinger in 2017 and is released to the public domain, meaning it can be freely used, modified, and distributed without restrictions.

"},{"title":"Mulberry32#next","link":"next","description":"

Generates the next psuedo-random number.

"},{"title":"PRNG","link":"PRNG","description":"

Creates an instance of PRNG.

"},{"title":"PRNG#randomBipolarFloat","link":"randomBipolarFloat","description":"

Generate a random float in the range [-1, 1).

"},{"title":"PRNG#randomChance","link":"randomChance","description":"

Returns a boolean based on a specified probability.

"},{"title":"PRNG#randomElement","link":"randomElement","description":"

Select a random element from an array.

"},{"title":"PRNG#randomFloat","link":"randomFloat","description":"

Generate a random float in the range [0, 1).

"},{"title":"PRNG#randomInteger","link":"randomInteger","description":"

Generate a random integer from a specified range of values.

"},{"title":"PRNG#randomUnitVector","link":"randomUnitVector","description":"

Generate a random unit vector.

"},{"title":"PRNG#randomWeighted","link":"randomWeighted","description":"

Selects an option probabalistically from a set of weighted choices.

"},{"title":"PRNGAlgorithm","link":"PRNGAlgorithm","description":"

A PRNGAlgorithm is a class that implements some technique for random number\ngeneration. It should have a seed and max value, as well as a next function.

"},{"title":"Path","link":"Path"},{"title":"Plot","link":"Plot"},{"title":"Plot#add","link":"add"},{"title":"Plot#addCirclesToSVG","link":"addCirclesToSVG","description":"

Adds the [Circles]{@link Circle} in this Plot's circles array to it's SVG element.

"},{"title":"Plot#addLinesToSVG","link":"addLinesToSVG","description":"

Adds the [Lines]{@link Line} in this Plot's lines array to it's SVG element.

"},{"title":"Plot#addPathsToSVG","link":"addPathsToSVG","description":"

Adds the [Paths]{@link Path} in this Plot's paths array to it's SVG element.

"},{"title":"Plot#addSingleShape","link":"addSingleShape","description":"

Adds a single shape to the appropriate array. Used by {@link Plot#add}.

"},{"title":"Plot#appendSVG","link":"appendSVG","description":"

Appends this plot's SVG element to the document body.

"},{"title":"Plot#clear","link":"clear","description":"

Empty out any existing HTML UI and SVG document elements on the page, in order to regenerate a Plot.

"},{"title":"Plot#createUI","link":"createUI","description":"

Creates HTML UI and adds it to the document body.

"},{"title":"Plot#deduplicateLines","link":"deduplicateLines","description":"

Removes duplicated [Lines]{@link Line} from this Plot's lines array.

"},{"title":"Plot#downloadSVG","link":"downloadSVG","description":"

Download the {@link Plot} as an SVG file.

"},{"title":"Plot#draw","link":"draw","description":"

Generates the SVG and UI and appends them to the document body.\nMust be called after defining a Plot.generate() function.

"},{"title":"Plot#filename","link":"filename"},{"title":"Plot#removeOverlappingLines","link":"removeOverlappingLines","description":"

Removes overlapping [Lines]{@link Line} from this Plot's lines array.

"},{"title":"Plot#removeShortLines","link":"removeShortLines","description":"

Removes [Lines]{@link Line} in this Plot's lines array that are shorter than a specified minimum length.

"},{"title":"Quadtree","link":"Quadtree","description":"

Create a quadtree.

"},{"title":"Quadtree#insert","link":"insert","description":"

Add a point into this quadtree.

"},{"title":"Quadtree#query","link":"query","description":"

Check for points in a given range and return them in an array.

"},{"title":"Quadtree#show","link":"show","description":"

For each boundary of this quadtree and all it's children,\ncreate [Lines]{@link Line} from those rectangles and add them to a {@link Plot}.

"},{"title":"Triangle#Triangle","link":"Triangle","description":"

Create a triangle.

"},{"title":"Triangle#lines","link":"lines","description":"

Create an array of [Lines]{@link Line}\ncontaining a line for each side of the Triangle.

"},{"title":"Vector","link":"Vector","description":"

Create a vector from coordinates.

"},{"title":"Vector#add","link":"add","description":"

Add a vector to this vector.

"},{"title":"Vector#clone","link":"clone","description":"

Make a copy of this vector.

"},{"title":"Vector#distance","link":"distance","description":"

Calculate the distance to another vector from this vector

"},{"title":"Vector#equals","link":"equals","description":"

Check if this vector is equivalent to another vector.

"},{"title":"Vector#getAngle","link":"getAngle","description":"

Get the angle of this vector with respect to the positive x-axis.

"},{"title":"Vector#getMagnitude","link":"getMagnitude","description":"

Get the magnitude of this vector.

"},{"title":"Vector#isOnLine","link":"isOnLine","description":"

Check if this vector is a point on a {@link Line}.

"},{"title":"Vector#multiply","link":"multiply","description":"

Multiply this vector by a scalar.

"},{"title":"Vector#nearestNeighbour","link":"nearestNeighbour","description":"

Finds the n nearest neighbours to this vector, from a given array of vectors.

"},{"title":"Vector#normalize","link":"normalize","description":"

Normalize this vector by setting it's magnitude to 1.

"},{"title":"Vector#rotate","link":"rotate","description":"

Rotate this vector by a specified angle.

"},{"title":"Vector#setMagnitude","link":"setMagnitude","description":"

Set the magnitude of this vector.

"},{"title":"Vector#subtract","link":"subtract","description":"

Subtract a vector from this vector.

"},{"title":"Vector#toArray","link":"toArray","description":"

Create an array from the vector's components.

"},{"title":"Vector.add","link":"add","description":"

Add two vectors.

"},{"title":"Vector.cross","link":"cross","description":"

Calculate the cross product of two 2D vectors.

"},{"title":"Vector.distance","link":"distance","description":"

Calculate the distance between two vectors.

"},{"title":"Vector.dot","link":"dot","description":"

Calculate the dot product of two vectors.

"},{"title":"Vector.fromAngle","link":"fromAngle","description":"

Create a vector from an angle.

"},{"title":"Vector.fromArray","link":"fromArray","description":"

Create a vector from an array.

"},{"title":"Vector.lerp","link":"lerp","description":"

Linear interpolation between vectors.

"},{"title":"Vector.subtract","link":"subtract","description":"

Subtract two vectors.

"},{"title":"XORShift32","link":"XORShift32","description":"

This class provides the XORShift32 method of generating psuedorandom\nnumbers to the {@link PRNG} class. It uses bitwise operations\nto generate a sequence of pseudorandom 32-bit unsigned integers.

\n

The XORShift algorithm was written by George Marsaglia in 2003 and is\nreleased to the public domain, meaning it can be freely used, modified,\nand distributed without restrictions.

"},{"title":"XORShift32#next","link":"next","description":"

Generates the next psuedo-random number.

"},{"title":"decToHex","link":"decToHex","description":"

Convert a decimal number into a hexadecimal string.

"},{"title":"fract","link":"fract"},{"title":"hexToDec","link":"hexToDec","description":"

Convert a hexadecimal string to a decimal number.

"},{"title":"lerp","link":"lerp","description":"

Linear interpolation between two values

"},{"title":"map","link":"map","description":"

Re-maps a number from one range to another.

"},{"title":"sinFract","link":"sinFract","description":"

Generates pseudo-random numbers from x and y co-ordinates. This\ntechnique is adapted from The Art of Code's YouTube video on value noise.

"},{"title":"unseededRandomHex","link":"unseededRandomHex","description":"

Uses Math.random() to make a hexadecimal string for\nsetting the seed of a {@link Plot} to be used in a seedable {@link PRNG} such as {@link LCG}

"},{"title":"wrap","link":"wrap","description":"

Constrain an input number to within a specified range, and wrapping it around to min when it exceeds max (and vice versa)

"}]} \ No newline at end of file +{"list":[{"title":"AABB","link":"AABB","description":"

Create an AABB using centre position, width, and height.

"},{"title":"AABB#contains","link":"contains","description":"

Check if this AABB contains a {@link Vector}.

"},{"title":"AABB#intersects","link":"intersects","description":"

Check if this aabb intersects another AABB.

"},{"title":"AABB#lines","link":"lines","description":"

Create an array of [Lines]{@link Line}\ncontaining a line for each side of the AABB.

"},{"title":"AABB.fromCorners","link":"fromCorners","description":"

Create an AABB from four corner [Vectors]{@link Vector}.

"},{"title":"Circle","link":"Circle","description":"

Create a circle.

"},{"title":"Circle#toSVGElement","link":"toSVGElement"},{"title":"LCG","link":"LCG","description":"

This class provides the LCG algorithm for generating psuedorandom\nnumbers to the {@link PRNG} class.

"},{"title":"LCG#next","link":"next","description":"

Generates the next pseudorandom number.

"},{"title":"Line","link":"Line","description":"

Create a line between two [Vectors]{@link Vector}.

"},{"title":"Line#intersects","link":"intersects","description":"

Check if this line intersects another shape.\nCurrently only {@link Line} is supported.

"},{"title":"Line#isContainedBy","link":"isContainedBy","description":"

Check if this line lies directly on top of a longer line.

"},{"title":"Line#isDuplicate","link":"isDuplicate","description":"

Check if this line is the same as another line.

"},{"title":"Line#length","link":"length","description":"

Get the length.

"},{"title":"Line#toSVGElement","link":"toSVGElement"},{"title":"Line.fromArray","link":"fromArray","description":"

Create a Line from an array of numbers.

"},{"title":"Line.lineIntersection","link":"lineIntersection","description":"

Check if two lines intersect.

"},{"title":"Mulberry32","link":"Mulberry32","description":"

This class provides the Mulberry32 method of generating psuedorandom\nnumbers to the {@link PRNG} class.

\n

The Mulberry32 algorithm was written by Tommy Ettinger in 2017 and is released to the public domain, meaning it can be freely used, modified, and distributed without restrictions.

"},{"title":"Mulberry32#next","link":"next","description":"

Generates the next psuedo-random number.

"},{"title":"PRNG","link":"PRNG","description":"

Creates an instance of PRNG.

"},{"title":"PRNG#randomBipolarFloat","link":"randomBipolarFloat","description":"

Generate a random float in the range [-1, 1).

"},{"title":"PRNG#randomChance","link":"randomChance","description":"

Returns a boolean based on a specified probability.

"},{"title":"PRNG#randomElement","link":"randomElement","description":"

Select a random element from an array.

"},{"title":"PRNG#randomFloat","link":"randomFloat","description":"

Generate a random float in the range [0, 1).

"},{"title":"PRNG#randomInteger","link":"randomInteger","description":"

Generate a random integer from a specified range of values.

"},{"title":"PRNG#randomUnitVector","link":"randomUnitVector","description":"

Generate a random unit vector.

"},{"title":"PRNG#randomWeighted","link":"randomWeighted","description":"

Selects an option probabalistically from a set of weighted choices.

"},{"title":"PRNGAlgorithm","link":"PRNGAlgorithm","description":"

A PRNGAlgorithm is a class that implements some technique for random number\ngeneration. It should have a seed and max value, as well as a next function.

"},{"title":"Path","link":"Path"},{"title":"Plot","link":"Plot"},{"title":"Plot#add","link":"add"},{"title":"Plot#addCirclesToSVG","link":"addCirclesToSVG","description":"

Adds the [Circles]{@link Circle} in this Plot's circles array to it's SVG element.

"},{"title":"Plot#addLinesToSVG","link":"addLinesToSVG","description":"

Adds the [Lines]{@link Line} in this Plot's lines array to it's SVG element.

"},{"title":"Plot#addPathsToSVG","link":"addPathsToSVG","description":"

Adds the [Paths]{@link Path} in this Plot's paths array to it's SVG element.

"},{"title":"Plot#addSingleShape","link":"addSingleShape","description":"

Adds a single shape to the appropriate array. Used by {@link Plot#add}.

"},{"title":"Plot#appendSVG","link":"appendSVG","description":"

Appends this plot's SVG element to the document body.

"},{"title":"Plot#clear","link":"clear","description":"

Empty out any existing HTML UI and SVG document elements on the page, in order to regenerate a Plot.

"},{"title":"Plot#createUI","link":"createUI","description":"

Creates HTML UI and adds it to the document body.

"},{"title":"Plot#deduplicateLines","link":"deduplicateLines","description":"

Removes duplicated [Lines]{@link Line} from this Plot's lines array.

"},{"title":"Plot#downloadSVG","link":"downloadSVG","description":"

Download the {@link Plot} as an SVG file.

"},{"title":"Plot#draw","link":"draw","description":"

Generates the SVG and UI and appends them to the document body.\nMust be called after defining a Plot.generate() function.

"},{"title":"Plot#filename","link":"filename"},{"title":"Plot#removeOverlappingLines","link":"removeOverlappingLines","description":"

Removes overlapping [Lines]{@link Line} from this Plot's lines array.

"},{"title":"Plot#removeShortLines","link":"removeShortLines","description":"

Removes [Lines]{@link Line} in this Plot's lines array that are shorter than a specified minimum length.

"},{"title":"Quadtree","link":"Quadtree","description":"

Create a quadtree.

"},{"title":"Quadtree#insert","link":"insert","description":"

Add a point into this quadtree.

"},{"title":"Quadtree#query","link":"query","description":"

Check for points in a given range and return them in an array.

"},{"title":"Quadtree#show","link":"show","description":"

For each boundary of this quadtree and all it's children,\ncreate [Lines]{@link Line} from those rectangles and add them to a {@link Plot}.

"},{"title":"Triangle","link":"Triangle","description":"

Create a triangle.

"},{"title":"Triangle#lines","link":"lines","description":"

Create an array of [Lines]{@link Line}\ncontaining a line for each side of the Triangle.

"},{"title":"Vector","link":"Vector","description":"

Create a vector from coordinates.

"},{"title":"Vector#add","link":"add","description":"

Add a vector to this vector.

"},{"title":"Vector#clone","link":"clone","description":"

Make a copy of this vector.

"},{"title":"Vector#distance","link":"distance","description":"

Calculate the distance to another vector from this vector

"},{"title":"Vector#equals","link":"equals","description":"

Check if this vector is equivalent to another vector.

"},{"title":"Vector#getAngle","link":"getAngle","description":"

Get the angle of this vector with respect to the positive x-axis.

"},{"title":"Vector#getMagnitude","link":"getMagnitude","description":"

Get the magnitude of this vector.

"},{"title":"Vector#isOnLine","link":"isOnLine","description":"

Check if this vector is a point on a {@link Line}.

"},{"title":"Vector#multiply","link":"multiply","description":"

Multiply this vector by a scalar.

"},{"title":"Vector#nearestNeighbour","link":"nearestNeighbour","description":"

Finds the n nearest neighbours to this vector, from a given array of vectors.

"},{"title":"Vector#normalize","link":"normalize","description":"

Normalize this vector by setting it's magnitude to 1.

"},{"title":"Vector#rotate","link":"rotate","description":"

Rotate this vector by a specified angle.

"},{"title":"Vector#setMagnitude","link":"setMagnitude","description":"

Set the magnitude of this vector.

"},{"title":"Vector#subtract","link":"subtract","description":"

Subtract a vector from this vector.

"},{"title":"Vector#toArray","link":"toArray","description":"

Create an array from the vector's components.

"},{"title":"Vector.add","link":"add","description":"

Add two vectors.

"},{"title":"Vector.cross","link":"cross","description":"

Calculate the cross product of two 2D vectors.

"},{"title":"Vector.distance","link":"distance","description":"

Calculate the distance between two vectors.

"},{"title":"Vector.dot","link":"dot","description":"

Calculate the dot product of two vectors.

"},{"title":"Vector.fromAngle","link":"fromAngle","description":"

Create a vector from an angle.

"},{"title":"Vector.fromArray","link":"fromArray","description":"

Create a vector from an array.

"},{"title":"Vector.lerp","link":"lerp","description":"

Linear interpolation between vectors.

"},{"title":"Vector.subtract","link":"subtract","description":"

Subtract two vectors.

"},{"title":"XORShift32","link":"XORShift32","description":"

This class provides the XORShift32 method of generating psuedorandom\nnumbers to the {@link PRNG} class. It uses bitwise operations\nto generate a sequence of pseudorandom 32-bit unsigned integers.

\n

The XORShift algorithm was written by George Marsaglia in 2003 and is\nreleased to the public domain, meaning it can be freely used, modified,\nand distributed without restrictions.

"},{"title":"XORShift32#next","link":"next","description":"

Generates the next psuedo-random number.

"},{"title":"decToHex","link":"decToHex","description":"

Convert a decimal number into a hexadecimal string.

"},{"title":"fract","link":"fract"},{"title":"hexToDec","link":"hexToDec","description":"

Convert a hexadecimal string to a decimal number.

"},{"title":"lerp","link":"lerp","description":"

Linear interpolation between two values

"},{"title":"map","link":"map","description":"

Re-maps a number from one range to another.

"},{"title":"sinFract","link":"sinFract","description":"

Generates pseudo-random numbers from x and y co-ordinates. This\ntechnique is adapted from The Art of Code's YouTube video on value noise.

"},{"title":"unseededRandomHex","link":"unseededRandomHex","description":"

Uses Math.random() to make a hexadecimal string for\nsetting the seed of a {@link Plot} to be used in a seedable {@link PRNG} such as {@link LCG}

"},{"title":"wrap","link":"wrap","description":"

Constrain an input number to within a specified range, and wrapping it around to min when it exceeds max (and vice versa)

"}]} \ No newline at end of file diff --git a/docs/global.html b/docs/global.html index 50d486e..ad9dbe2 100644 --- a/docs/global.html +++ b/docs/global.html @@ -1,5 +1,5 @@ Global
On this page

Methods

decToHex(dec, lengthopt) → {string}

Convert a decimal number into a hexadecimal string.

Parameters:
NameTypeAttributesDefaultDescription
decnumber

A decimal number.

lengthnumber<optional>
8

The number of digits the string should be padded to.

Returns:
  • The hexadecimal string equivalent of the decimal number.
Type: 
string

fract(x) → {number}

Parameters:
NameTypeDescription
xnumber
Returns:

The fractional part of x

Type: 
number
Examples
// returns 0.42
+    
On this page

Methods

decToHex(dec, lengthopt) → {string}

Convert a decimal number into a hexadecimal string.

Parameters:
NameTypeAttributesDefaultDescription
decnumber

A decimal number.

lengthnumber<optional>
8

The number of digits the string should be padded to.

Returns:
  • The hexadecimal string equivalent of the decimal number.
Type: 
string

fract(x) → {number}

Parameters:
NameTypeDescription
xnumber
Returns:

The fractional part of x

Type: 
number
Examples
// returns 0.42
 fract(1.42)
// returns 0.77
-fract(-42.23)

hexToDec(hex) → {number}

Convert a hexadecimal string to a decimal number.

Parameters:
NameTypeDescription
hexstring

A hexacimal string.

Returns:
  • The decimal equivalent of the hex string.
Type: 
number

lerp(a, b, amount)

Linear interpolation between two values

Parameters:
NameTypeDescription
anumber
bnumber
amountnumber

map(value, min1, max1, min2, max2, withinBoundsopt) → {number}

Re-maps a number from one range to another.

Parameters:
NameTypeAttributesDefaultDescription
valuenumber

The number to be re-mapped.

min1number

The minimum value of the original range.

max1number

The maximum value of the original range.

min2number

The minimum value of the target range.

max2number

The maximum value of the target range.

withinBoundsboolean<optional>
false

Whether the remapped value should be constrained within the target range.

Returns:

The re-mapped value.

Type: 
number

sinFract() → {number}

Generates pseudo-random numbers from x and y co-ordinates. This technique is adapted from The Art of Code's YouTube video on value noise.

Returns:
  • A floating point number between 0 and 1
Type: 
number

unseededRandomHex(n) → {string}

Create a random hexadecimal string of a specified length.

Uses Math.random() to make a hexadecimal string for setting the seed of a Plot to be used in a seedable PRNG such as LCG

Parameters:
NameTypeDescription
nnumber

Number of digits

Returns:
  • Hexadecimal string of length n
Type: 
string

wrap()

Constrain an input number to within a specified range, and wrapping it around to min when it exceeds max (and vice versa)

Type Definitions

PRNGAlgorithm

A PRNGAlgorithm is a class that implements some technique for random number generation. It should have a seed and max value, as well as a next function.

Properties
NameTypeDescription
seednumber

The initial state of the PRNG.

maxnumber

The maximum possible value of the PRNG.

nextfunction

The next psuedo-random number between 0 and 1.

\ No newline at end of file +fract(-42.23)

hexToDec(hex) → {number}

Convert a hexadecimal string to a decimal number.

Parameters:
NameTypeDescription
hexstring

A hexacimal string.

Returns:
  • The decimal equivalent of the hex string.
Type: 
number

lerp(a, b, amount)

Linear interpolation between two values

Parameters:
NameTypeDescription
anumber
bnumber
amountnumber

map(value, min1, max1, min2, max2, withinBoundsopt) → {number}

Re-maps a number from one range to another.

Parameters:
NameTypeAttributesDefaultDescription
valuenumber

The number to be re-mapped.

min1number

The minimum value of the original range.

max1number

The maximum value of the original range.

min2number

The minimum value of the target range.

max2number

The maximum value of the target range.

withinBoundsboolean<optional>
false

Whether the remapped value should be constrained within the target range.

Returns:

The re-mapped value.

Type: 
number

sinFract() → {number}

Generates pseudo-random numbers from x and y co-ordinates. This technique is adapted from The Art of Code's YouTube video on value noise.

Returns:
  • A floating point number between 0 and 1
Type: 
number

unseededRandomHex(n) → {string}

Create a random hexadecimal string of a specified length.

Uses Math.random() to make a hexadecimal string for setting the seed of a Plot to be used in a seedable PRNG such as LCG

Parameters:
NameTypeDescription
nnumber

Number of digits

Returns:
  • Hexadecimal string of length n
Type: 
string

wrap()

Constrain an input number to within a specified range, and wrapping it around to min when it exceeds max (and vice versa)

Type Definitions

PRNGAlgorithm

A PRNGAlgorithm is a class that implements some technique for random number generation. It should have a seed and max value, as well as a next function.

Properties
NameTypeDescription
seednumber

The initial state of the PRNG.

maxnumber

The maximum possible value of the PRNG.

nextfunction

The next psuedo-random number between 0 and 1.

\ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 31fc9bc..5318181 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,6 +1,6 @@ Penplotting.js
On this page

Penplotting.js

GitHub Actions Workflow Status

Penplotting.js is a JavaScript framework for making generative art in SVG format for penplotters. This project is a personal project, and as such, it is a work-in-progress. New features and breaking changes are to be expected in future updates. Use at your own discretion, feel free to contribute and raise issues.

Features

  • Shapes and geometry classes: 2D Vector, Line, Path, Circle, AABB
  • Seedable PRNG implementations with useful methods
  • Quadtree for optimised nearest-neighbour search
  • Paper sizes

Installation

npm i @jakebeamish/penplotting
+    
On this page

Penplotting.js

GitHub Actions Workflow Status

Penplotting.js is a JavaScript framework for making generative art in SVG format for penplotters. This project is a personal project, and as such, it is a work-in-progress. New features and breaking changes are to be expected in future updates. Use at your own discretion, feel free to contribute and raise issues.

Features

  • Shapes and geometry classes: 2D Vector, Line, Path, Circle, AABB
  • Seedable PRNG implementations with useful methods
  • Quadtree for optimised nearest-neighbour search
  • Paper sizes

Installation

npm i @jakebeamish/penplotting
 

Usage

To start a new plot, run

npx new-plot
 

This is a shell script that will create new default index.html, style.css and plot.js files in the current working directory. Inside plot.js, adjust the options for initializing the plot:

const plot = new Plot({
     units: "mm",
@@ -20,4 +20,4 @@
 }
 
 plot.draw();
-

Calling plot.draw() at the end of the file will generate an SVG element and UI inside index.html, which can be opened in a browser.

Keyboard shortcuts

ActionKey
Download an SVG filed
Regenerate with random seedr

Plotting the SVG files

The SVG file can be downloaded and optionally processed further. Personally, I use vpype to optimise the file, and then the axidraw Inkscape plugin to control the plotter.

Contributing

Contributions are welcome. Issues, comments and Pull Requests can be made at https://github.com/jakebeamish/penplot-svg-tool/issues.

The project is tested using jest. Documentation is generated using JSDoc.

License

This project is licensed under the MIT License. See the LICENSE.md file for details.

Acknowledgements

This project incorporates code from:

\ No newline at end of file +

Calling plot.draw() at the end of the file will generate an SVG element and UI inside index.html, which can be opened in a browser.

Keyboard shortcuts

ActionKey
Download an SVG filed
Regenerate with random seedr

Plotting the SVG files

The SVG file can be downloaded and optionally processed further. Personally, I use vpype to optimise the file, and then the axidraw Inkscape plugin to control the plotter.

Contributing

Contributions are welcome. Issues, comments and Pull Requests can be made at https://github.com/jakebeamish/penplot-svg-tool/issues.

The project is tested using jest. Documentation is generated using JSDoc.

License

This project is licensed under the MIT License. See the LICENSE.md file for details.

Acknowledgements

This project incorporates code from:

\ No newline at end of file diff --git a/docs/utils.js.html b/docs/utils.js.html index d74d5de..607b298 100644 --- a/docs/utils.js.html +++ b/docs/utils.js.html @@ -1,6 +1,6 @@ Source: utils.js
On this page

utils.js

/**
+    
On this page

utils.js

/**
  * Generates pseudo-random numbers from `x` and `y` co-ordinates. This
  * technique is adapted from The Art of Code's YouTube video on value noise.
  *
@@ -86,4 +86,4 @@
 export function decToHex(dec, length = 8) {
   return dec.toString(16).padStart(length, "0");
 }
-
\ No newline at end of file +
\ No newline at end of file diff --git a/source/Triangle.js b/source/Triangle.js index d63d4d9..c375fc9 100644 --- a/source/Triangle.js +++ b/source/Triangle.js @@ -1,6 +1,10 @@ import { Vector } from "./Vector.js"; import { Line } from "./Line.js"; + +/** + * Class representing a triangle. + */ export class Triangle { /** * Create a triangle.