Skip to content

Commit

Permalink
docs: Imrprove generated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Undistraction committed Aug 1, 2024
1 parent b3cdf75 commit 8dab059
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"lint-eslint": "eslint './**/*.{ts, js, jcjs}'",
"build": "vite build && pnpm run docs",
"build-watch": "vite build --watch",
"docs": "npx typedoc src/index.ts",
"docs": "typedoc",
"docs-open": "open ./docs/index.html",
"release-preview": "semantic-release --no-ci --dry-run --debug",
"link": "pnpm link --global",
Expand Down
92 changes: 53 additions & 39 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import {
validateGetSurfacePointArguments,
} from './utils/validation'

/**
* @groupDescription API
* The API of the package
*/

// -----------------------------------------------------------------------------
// Const
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -59,17 +64,17 @@ export { interpolatePointOnCurveLinear } from './interpolate/pointOnCurve/linear
* Computes a point on a surface defined by bounding curves at parameters u and
* v.
*
* @param {Object} boundingCurves - An object containing curves that define the
* surface boundaries.
* @param {number} u - The parameter along the first dimension (typically
* between 0 and 1).
* @param {number} v - The parameter along the second dimension (typically
* between 0 and 1).
* @param {BoundingCurves} boundingCurves - An object containing curves that
* define the surface boundaries.
* @param {number} u - The parameter along the first dimension (0–1).
* @param {number} v - The parameter along the second dimension (0–1).
* @param {Object} [config] - Configuration object.
* @param {Function}
* [interpolatePointOnCurve=interpolatePointOnCurveEvenlySpaced] - A function to
* interpolate points on the curves.
* @returns {Object} The interpolated point on the surface.
* [config.interpolatePointOnCurve=interpolatePointOnCurveDefault] - A function
* to interpolate points on the curves.
* @returns {Point} The interpolated point on the surface.
* @throws {Error} If the arguments are invalid.
* @group API
*/
export const getSurfacePoint = (
boundingCurves: BoundingCurves,
Expand Down Expand Up @@ -97,19 +102,22 @@ export const getSurfacePoint = (
* Generates intersection points on the surface based on the provided bounding
* curves, columns, and rows.
*
* @param {Object} boundingCurves - An object containing curves that define the
* surface boundaries.
* @param {BoundingCurves} boundingCurves - An object containing curves that
* define the surface boundaries.
* @param {number | Array<number> | Array<Object>} columns - Either a number, an
* array of numbers, or an array of column definitions, each containing a value
* and an optional isGutter flag.
* @param {number | Array<number> | Array<Object>} rows - Either a number, an
* array of numbers, or an array of row definitions.
* array of numbers, or an array of row definitions, each containing a value and
* an optional isGutter flag.
* @param {Object} [config] - Configuration object.
* @param {Function}
* [interpolatePointOnCurve=interpolatePointOnCurveEvenlySpaced] - A function to
* interpolate points on the curves.
* @returns {Array<Object>} An array of points representing the intersections on
* the surface.
* [config.interpolatePointOnCurve=interpolatePointOnCurveDefault] - A function
* to interpolate points on the curves.
* @returns {Points} An array of points representing the intersections on the
* surface.
* @throws {Error} If the arguments are invalid.
* @group API
*/
export const getSurfaceIntersectionPoints = (
boundingCurves: BoundingCurves,
Expand Down Expand Up @@ -168,22 +176,24 @@ export const getSurfaceIntersectionPoints = (
* Generates surface curves along the U-axis based on the provided bounding
* curves, columns, and rows.
*
* @param {Object} boundingCurves - An object containing curves that define the
* surface boundaries.
* @param {BoundingCurves} boundingCurves - An object containing curves that
* define the surface boundaries.
* @param {number | Array<number> | Array<Object>} columns - Either a number, an
* array of numbers, or an array of column definitions, each containing a value
* and an optional isGutter flag.
* @param {number | Array<number> | Array<Object>} rows - Either a number, an
* array of numbers, or an array of row definitions, each containing a value
* and an optional isGutter flag.
* array of numbers, or an array of row definitions, each containing a value and
* an optional isGutter flag.
* @param {Object} [config] - Configuration object.
* @param {Function}
* [interpolatePointOnCurve=interpolatePointOnCurveEvenlySpaced] - A function to
* interpolate points on the curves.
* @param {Function} [interpolateLineU=interpolateStraightLineU] - A
* [config.interpolatePointOnCurve=interpolatePointOnCurveDefault] - A function
* to interpolate points on the curves.
* @param {Function} [config.interpolateLineU=interpolateStraightLineU] - A
* function to interpolate lines along the U-axis.
* @returns {Array<Array<Object>>} A 2D array of curves representing the surface
* along the U-axis.
* @returns {StepCurves[]} A 2D array of curves representing the surface along
* the U-axis.
* @throws {Error} If the arguments are invalid.
* @group API
*/
export const getSurfaceCurvesU = (
boundingCurves: BoundingCurves,
Expand Down Expand Up @@ -259,22 +269,24 @@ export const getSurfaceCurvesU = (
* Generates surface curves along the V-axis based on the provided bounding
* curves, columns, and rows.
*
* @param {Object} boundingCurves - An object containing curves that define the
* surface boundaries.
* @param {BoundingCurves} boundingCurves - An object containing curves that
* define the surface boundaries.
* @param {number | Array<number> | Array<Object>} columns - Either a number, an
* array of numbers, or an array of column definitions, each containing a value
* and an optional isGutter flag.
* @param {number | Array<number> | Array<Object>} rows - Either a number, an
* array of numbers, or an array of row definitions, each containing a value
* and an optional isGutter flag.
* array of numbers, or an array of row definitions, each containing a value and
* an optional isGutter flag.
* @param {Object} [config] - Configuration object.
* @param {Function}
* [interpolatePointOnCurve=interpolatePointOnCurveEvenlySpaced] - A function to
* interpolate points on the curves.
* @param {Function} [interpolateLineV=interpolateStraightLineV] - A
* [config.interpolatePointOnCurve=interpolatePointOnCurveDefault] - A function
* to interpolate points on the curves.
* @param {Function} [config.interpolateLineV=interpolateStraightLineV] - A
* function to interpolate lines along the V-axis.
* @returns {Array<Array<Object>>} A 2D array of curves representing the surface
* along the V-axis.
* @throws {Error} If the arguments are invalid.
* @group API
*/
export const getSurfaceCurvesV = (
boundingCurves: BoundingCurves,
Expand Down Expand Up @@ -351,23 +363,25 @@ export const getSurfaceCurvesV = (
* Generates surface curves along both the U-axis and V-axis based on the
* provided bounding curves, columns, and rows.
*
* @param {Object} boundingCurves - An object containing curves that define the
* @param {BoundingCurves} boundingCurves - An object containing curves that define the
* surface boundaries.
* @param {number | Array<number> | Array<Object>} columns - Either a number, an
* array of numbers, or an array of column definitions, each containing a value
* and an optional isGutter flag.
* @param {number | Array<number> | Array<Object>} rows - Either a number, an
* array of numbers, or an array of row definitions.
* @param {Function}
* [interpolatePointOnCurve=interpolatePointOnCurveEvenlySpaced] - A function to
* array of numbers, or an array of row definitions, each containing a value
* and an optional isGutter flag.
* @param {Object} [config] - Configuration object.
* @param {Function} [config.interpolatePointOnCurve=interpolatePointOnCurveDefault] - A function to
* interpolate points on the curves.
* @param {Function} [interpolateLineU=interpolateStraightLineU] - A
* @param {Function} [config.interpolateLineU=interpolateStraightLineU] - A
* function to interpolate lines along the U-axis.
* @param {Function} [interpolateLineV=interpolateStraightLineV] - A
* @param {Function} [config.interpolateLineV=interpolateStraightLineV] - A
* function to interpolate lines along the V-axis.
* @returns {Object} An object containing 2D arrays of curves representing the
* @returns {UVCurves} An object containing 2D arrays of curves representing the
* surface along both the U-axis and V-axis.
* @throws {Error} If the arguments are invalid.
* @group API
*/
export const getSurfaceCurves = (
boundingCurves: BoundingCurves,
Expand Down
32 changes: 32 additions & 0 deletions src/interpolate/curves/curved.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ import { interpolateStraightLineU, interpolateStraightLineV } from './straight'
const T_MIDPOINT_1 = 0.25
const T_MIDPOINT_2 = 0.75

// -----------------------------------------------------------------------------
// Exports
// -----------------------------------------------------------------------------

/**
* Interpolates a cubic Bezier curve along the U direction of a surface defined
* by bounding curves.
*
* @param {BoundingCurves} boundingCurves - An object containing curves that
* define the surface boundaries.
* @param {number} vStart - The starting parameter along the V direction.
* @param {number} vSize - The size of the step along the V direction.
* @param {number} vEnd - The ending parameter along the V direction.
* @param {number} uStart - The starting parameter along the U direction.
* @param {InterpolatePointOnCurve} interpolatePointOnCurve - A function to
* interpolate points on the curves.
* @returns {Curve} The interpolated cubic Bezier curve.
*/
export const interpolateCurveU = (
boundingCurves: BoundingCurves,
vStart: number,
Expand Down Expand Up @@ -49,6 +67,20 @@ export const interpolateCurveU = (
return curve
}

/**
* Interpolates a cubic Bezier curve along the V direction of a surface defined
* by bounding curves.
*
* @param {BoundingCurves} boundingCurves - An object containing curves that
* define the surface boundaries.
* @param {number} uStart - The starting parameter along the U direction.
* @param {number} uSize - The size of the step along the U direction.
* @param {number} uEnd - The ending parameter along the U direction.
* @param {number} vStart - The starting parameter along the V direction.
* @param {InterpolatePointOnCurve} interpolatePointOnCurve - A function to
* interpolate points on the curves.
* @returns {Curve} The interpolated cubic Bezier curve.
*/
export const interpolateCurveV = (
boundingCurves: BoundingCurves,
uStart: number,
Expand Down
27 changes: 27 additions & 0 deletions src/interpolate/curves/straight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ import { interpolatePointOnSurface } from '../pointOnSurface/bilinear'
// Exports
// -----------------------------------------------------------------------------

/**
* Interpolates a straight line along the U direction of a surface defined
* by bounding curves.
*
* @param {BoundingCurves} boundingCurves - An object containing curves that define the
* surface boundaries.
* @param {number} uStart - The starting parameter along the U direction.
* @param {number} uSize - The size of the step along the U direction.
* @param {number} uEnd - The ending parameter along the U direction.
* @param {number} vStart - The starting parameter along the V direction.
* @param {InterpolatePointOnCurve} interpolatePointOnCurve - A function to interpolate points on the curves.
* @returns {Curve} The interpolated straight line as a cubic Bezier curve.
*/
export const interpolateStraightLineU = (
boundingCurves: BoundingCurves,
uStart: number,
Expand Down Expand Up @@ -36,6 +49,20 @@ export const interpolateStraightLineU = (
}
}

/**
* Interpolates a straight line along the V direction of a surface defined by
* bounding curves.
*
* @param {BoundingCurves} boundingCurves - An object containing curves that
* define the surface boundaries.
* @param {number} uStart - The starting parameter along the U direction.
* @param {number} uSize - The size of the step along the U direction.
* @param {number} uEnd - The ending parameter along the U direction.
* @param {number} vStart - The starting parameter along the V direction.
* @param {InterpolatePointOnCurve} interpolatePointOnCurve - A function to
* interpolate points on the curves.
* @returns {Curve} The interpolated straight line as a cubic Bezier curve.
*/
export const interpolateStraightLineV = (
boundingCurves: BoundingCurves,
uStart: number,
Expand Down
10 changes: 10 additions & 0 deletions src/interpolate/pointOnCurve/even.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ const getLutForCurve = memoize((curve, precision) => {
// Exports
// -----------------------------------------------------------------------------

/**
* Interpolates a point on a curve such that the points are evenly spaced.
*
* @param {Object} options - Configuration options.
* @param {number} options.precision - The number of points used to approximate
* the curve. Increasing this number improves accuracy at the cost of
* performance.
* @returns {Function} A function that takes a parameter `t` and a `curve`, and
* returns an interpolated point on the curve.
*/
export const interpolatePointOnCurveEvenlySpaced =
(
// Get an approximation using an arbitrary number of points. Increase for
Expand Down
8 changes: 8 additions & 0 deletions src/interpolate/pointOnCurve/linear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ const interpolate = (
// Exports
// -----------------------------------------------------------------------------

/**
* Interpolates a point on a curve using linear interpolation. Note that this
* will not result in the points being evenly spaced.
*
* @param {number} t - The parameter along the curve, typically between 0 and 1.
* @param {Curve} curve - The curve on which to interpolate the point.
* @returns {Point} The interpolated point on the curve.
*/
export const interpolatePointOnCurveLinear = (
t: number,
curve: Curve
Expand Down
1 change: 1 addition & 0 deletions tests/snapshotData.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getSurfaceIntersectionPoints,
getSurfacePoint,
} from '../src/index.js'

import fixtures from './fixtures.js'
import { __dirname, writeFileAsync } from './helpers.js'

Expand Down
8 changes: 8 additions & 0 deletions typedoc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('typedoc').TypeDocOptions} */
module.exports = {
entryPoints: ['./src/index.ts'],
out: 'docs',
categorizeByGroup: true,
groupOrder: ['API', '*'],
sort: 'source-order',
}

0 comments on commit 8dab059

Please sign in to comment.