Skip to content

Commit

Permalink
fix(modeling): use modern typescript imports
Browse files Browse the repository at this point in the history
  • Loading branch information
platypii committed Aug 13, 2023
1 parent 48606fc commit 0a0d2e8
Show file tree
Hide file tree
Showing 697 changed files with 1,881 additions and 1,889 deletions.
15 changes: 15 additions & 0 deletions packages/modeling/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// global types
declare type Geom2 = import('./src/geometries/geom2/type.d.ts').Geom2
declare type Geom3 = import('./src/geometries/geom3/type.d.ts').Geom3
declare type Path2 = import('./src/geometries/path2/type.d.ts').Path2
declare type Poly2 = import('./src/geometries/poly2/type.d.ts').Poly2
declare type Poly3 = import('./src/geometries/poly3/type.d.ts').Poly3
declare type Slice = import('./src/geometries/slice/type.d.ts').Slice

declare type Line2 = import('./src/maths/line2/type.d.ts').Line2
declare type Line3 = import('./src/maths/line3/type.d.ts').Line3
declare type Mat4 = import('./src/maths/mat4/type.d.ts').Mat4
declare type Plane = import('./src/maths/plane/type.d.ts').Plane
declare type Vec2 = import('./src/maths/vec2/type.d.ts').Vec2
declare type Vec3 = import('./src/maths/vec3/type.d.ts').Vec3
declare type Vec4 = import('./src/maths/vec4/type.d.ts').Vec4
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/colorNameToRgb.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { RGB } from './types'
import type { RGB } from './types.d.ts'

export function colorNameToRgb(s: string): RGB
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/colorNameToRgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { cssColors } from './cssColors.js'
/**
* Converts a CSS color name to RGB color.
*
* @param {String} s - the CSS color name
* @param {string} s - the CSS color name
* @return {Array} the RGB color, or undefined if not found
* @alias module:modeling/colors.colorNameToRgb
* @example
Expand Down
6 changes: 3 additions & 3 deletions packages/modeling/src/colors/colorize.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Colored, Geometry } from '../geometries/types'
import RecursiveArray from '../utils/recursiveArray'
import type { Colored, Geometry } from '../geometries/types.d.ts'
import type { RecursiveArray } from '../utils/recursiveArray.d.ts'

import { RGB, RGBA } from './types'
import type { RGB, RGBA } from './types.d.ts'

// Single Geom3 returns Colored Geom3
export function colorize<T extends Geometry>(color: RGB | RGBA, object: T): T & Colored
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/colorize.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const colorPoly3 = (color, object) => {
/**
* Assign the given color to the given objects.
* @param {Array} color - RGBA color values, where each value is between 0 and 1.0
* @param {Object|Array} objects - the objects of which to apply the given color
* @param {object|Array} objects - the objects of which to apply the given color
* @return {Object|Array} new object, or list of new objects with an additional attribute 'color'
* @alias module:modeling/colors.colorize
*
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/cssColors.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RGB } from './types'
import type { RGB } from './types.d.ts'

export const black: RGB
export const silver: RGB
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/hexToRgb.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { RGB, RGBA } from './types'
import type { RGB, RGBA } from './types.d.ts'

export function hexToRgb(hex: string): RGB | RGBA
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/hexToRgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Converts CSS color notations (string of hex values) to RGB values.
*
* @see https://www.w3.org/TR/css-color-3/
* @param {String} notation - color notation
* @param {string} notation - color notation
* @return {Array} RGB color values
* @alias module:modeling/colors.hexToRgb
*
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/hslToRgb.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HSL, HSLA, RGB, RGBA } from './types'
import type { HSL, HSLA, RGB, RGBA } from './types.d.ts'

export function hslToRgb(hsl: HSL): RGB
export function hslToRgb(hsl: HSLA): RGBA
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/hsvToRgb.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HSV, HSVA, RGB, RGBA } from './types'
import type { HSV, HSVA, RGB, RGBA } from './types.d.ts'

export function hsvToRgb(hsv: HSV): RGB
export function hsvToRgb(hsv: HSVA): RGBA
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/hueToColorComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @param {Number} p
* @param {Number} q
* @param {Number} t
* @return {Number} color component
* @return {number} color component
* @alias module:modeling/colors.hueToColorComponent
*/
export const hueToColorComponent = (p, q, t) => {
Expand Down
23 changes: 11 additions & 12 deletions packages/modeling/src/colors/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
export { colorize } from './colorize'
export { colorNameToRgb } from './colorNameToRgb'
export * as cssColors from './cssColors'
export { hexToRgb } from './hexToRgb'
export { hslToRgb } from './hslToRgb'
export { hsvToRgb } from './hsvToRgb'
export { hueToColorComponent } from './hueToColorComponent'
export { rgbToHex } from './rgbToHex'
export { rgbToHsl } from './rgbToHsl'
export { rgbToHsv } from './rgbToHsv'
export { colorize } from './colorize.js'
export { colorNameToRgb } from './colorNameToRgb.js'
export * as cssColors from './cssColors.js'
export { hexToRgb } from './hexToRgb.js'
export { hslToRgb } from './hslToRgb.js'
export { hsvToRgb } from './hsvToRgb.js'
export { hueToColorComponent } from './hueToColorComponent.js'
export { rgbToHex } from './rgbToHex.js'
export { rgbToHsl } from './rgbToHsl.js'
export { rgbToHsv } from './rgbToHsv.js'

export * from './types'
export as namespace colors
export type * from './types.d.ts'
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/rgbToHex.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RGB, RGBA } from './types'
import type { RGB, RGBA } from './types.d.ts'

export function rgbToHex(rgb: RGB | RGBA): string
export function rgbToHex(...rgb: RGB | RGBA): string
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/rgbToHsl.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HSL, HSLA, RGB, RGBA } from './types'
import type { HSL, HSLA, RGB, RGBA } from './types.d.ts'

export function rgbToHsl(rgb: RGB): HSL
export function rgbToHsl(rgb: RGBA): HSLA
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/rgbToHsv.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HSV, HSVA, RGB, RGBA } from './types'
import type { HSV, HSVA, RGB, RGBA } from './types.d.ts'

export function rgbToHsv(rgb: RGB): HSV
export function rgbToHsv(rgb: RGBA): HSVA
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/connectors/extends.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fromPointAxisNormal } from './fromPointAxisNormal.js'

/*
* Creates a new connector, with the connection point moved in the direction of the axis
* @param {Number} distance the distance to extend the connector to
* @param {number} distance the distance to extend the connector to
* @param {connector} connector the connector to extend
* @returns {connector} a normalized connector
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/modeling/src/connectors/fromPointAxisNormal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { create } from './create.js'

/**
* Create a connector from the given point, axis and normal.
* @param {vec3} point - the point of the connector, relative to the parent geometry
* @param {vec3} axis - the axis (directional vector) of the connector
* @param {vec3} normal - the normal (directional vector) of the connector, perpendicular to the axis
* @param {Vec3} point - the point of the connector, relative to the parent geometry
* @param {Vec3} axis - the axis (directional vector) of the connector
* @param {Vec3} normal - the normal (directional vector) of the connector, perpendicular to the axis
* @returns {connector} a new connector
* @alias module:modeling/connectors.fromPointsAxisNormal
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/connectors/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fromPointAxisNormal } from './fromPointAxisNormal.js'

/**
* Transform the give connector using the given matrix.
* @param {mat4} matrix - a transform matrix
* @param {Mat4} matrix - a transform matrix
* @param {connector} connector - the connector to transform
* @returns {connector} a new connector
* @alias module:modeling/connectors.transform
Expand Down
12 changes: 6 additions & 6 deletions packages/modeling/src/connectors/transformationBetween.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { transform } from './transform.js'

/**
* Get the transformation matrix that connects the given connectors.
* @param {Object} options
* @param {Boolean} [options.mirror=false] - the 'axis' vectors should point in the same direction
* @param {object} options
* @param {boolean} [options.mirror=false] - the 'axis' vectors should point in the same direction
* true: the 'axis' vectors should point in opposite direction
* @param {Number} [options.normalRotation=0] - the angle (RADIANS) of rotation between the 'normal' vectors
* @param {connector} from - connector from which to connect
* @param {connector} to - connector to connect to
* @returns {mat4} - the matrix that transforms (connects) one connector to another
* @param {number} [options.normalRotation=0] - the angle (RADIANS) of rotation between the 'normal' vectors
* @param {Connector} from - connector from which to connect
* @param {Connector} to - connector to connect to
* @returns {Mat4} - the matrix that transforms (connects) one connector to another
* @alias module:modeling/connectors.transformationBetween
*/
export const transformationBetween = (options, from, to) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/curves/bezier/arcLengthToT.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Bezier from './type'
import type { Bezier } from './type.d.ts'

export interface ArcLengthToTOptions {
distance?: Number
Expand Down
8 changes: 4 additions & 4 deletions packages/modeling/src/curves/bezier/arcLengthToT.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import { lengths } from './lengths.js'
* }
* return points;
*
* @param {Object} [options] options for construction
* @param {Number} [options.distance=0] the distance along the bezier curve for which we want to find the corresponding t value.
* @param {Number} [options.segments=100] the number of segments to use when approximating the curve length.
* @param {Object} bezier a bezier curve.
* @param {object} [options] options for construction
* @param {number} [options.distance=0] the distance along the bezier curve for which we want to find the corresponding t value.
* @param {number} [options.segments=100] the number of segments to use when approximating the curve length.
* @param {object} bezier a bezier curve.
* @returns a number in the [0, 1] interval or NaN if the arcLength is negative or greater than the total length of the curve.
* @alias module:modeling/curves/bezier.arcLengthToT
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/curves/bezier/create.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Bezier from './type'
import type { Bezier } from './type.d.ts'

export function create(points: Array<number> | Array<Array<number>>): Bezier
15 changes: 7 additions & 8 deletions packages/modeling/src/curves/bezier/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
export { create } from './create'
export { tangentAt } from './tangentAt'
export { valueAt } from './valueAt'
export { lengths } from './lengths'
export { length } from './length'
export { arcLengthToT } from './arcLengthToT'
export { create } from './create.js'
export { tangentAt } from './tangentAt.js'
export { valueAt } from './valueAt.js'
export { lengths } from './lengths.js'
export { length } from './length.js'
export { arcLengthToT } from './arcLengthToT.js'

export { Bezier } from './type'
export as namespace bezier
export type { Bezier } from './type.d.ts'
2 changes: 1 addition & 1 deletion packages/modeling/src/curves/bezier/length.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Bezier from './type'
import type { Bezier } from './type.d.ts'

export function length(segments: number, bezier: Bezier): number
4 changes: 2 additions & 2 deletions packages/modeling/src/curves/bezier/length.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { lengths } from './lengths.js'
* const b = bezier.create([[0, 0], [0, 10]]);
* console.log(length(100, b)) // output 10
*
* @param {Number} segments the number of segments to use when approximating the curve length.
* @param {Object} bezier a bezier curve.
* @param {number} segments the number of segments to use when approximating the curve length.
* @param {object} bezier a bezier curve.
* @returns an approximation of the curve's length.
* @alias module:modeling/curves/bezier.length
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/curves/bezier/lengths.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Bezier from './type'
import type { Bezier } from './type.d.ts'

export function lengths(segments: number, bezier: Bezier): Array<number>
6 changes: 3 additions & 3 deletions packages/modeling/src/curves/bezier/lengths.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { valueAt } from './valueAt.js'
* const b = bezier.create([[0, 0], [0, 10]]);
* const totalLength = lengths(100, b).pop(); // the last element of the array is the curve's approximate length
*
* @param {Number} segments the number of segments to use when approximating the curve length.
* @param {Object} bezier a bezier curve.
* @param {number} segments the number of segments to use when approximating the curve length.
* @param {object} bezier a bezier curve.
* @returns an array containing the cumulative length of the segments.
*/
export const lengths = (segments, bezier) => {
Expand All @@ -34,7 +34,7 @@ export const lengths = (segments, bezier) => {
*
* @param {Array} a - first operand.
* @param {Array} b - second operand.
* @returns {Number} - distance.
* @returns {number} - distance.
*/
const distanceBetween = (a, b) => {
if (Number.isFinite(a) && Number.isFinite(b)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/curves/bezier/tangentAt.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Bezier from './type'
import type { Bezier } from './type.d.ts'

export function tangentAt(t: number, bezier: Bezier): Array<number> | number
2 changes: 1 addition & 1 deletion packages/modeling/src/curves/bezier/tangentAt.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* let tangent = bezier.tangentAt(t, b)
*
* @param {number} t : the position of which to calculate the bezier's tangent value; 0 < t < 1
* @param {Object} bezier : an array with at least 2 elements of either all numbers, or all arrays of numbers that are the same size.
* @param {object} bezier : an array with at least 2 elements of either all numbers, or all arrays of numbers that are the same size.
* @return {array | number} the tangent at the requested position.
* @alias module:modeling/curves/bezier.tangentAt
*/
Expand Down
2 changes: 0 additions & 2 deletions packages/modeling/src/curves/bezier/type.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export default Bezier

export interface Bezier {
points: Array<number> | Array<Array<number>>
pointType: string
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/curves/bezier/valueAt.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Bezier from './type'
import type { Bezier } from './type.d.ts'

export function valueAt(t: number, bezier: Bezier): Array<number> | number
2 changes: 1 addition & 1 deletion packages/modeling/src/curves/bezier/valueAt.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* let position = bezier.valueAt(t,b) // where 0 < t < 1
*
* @param {number} t : the position of which to calculate the value; 0 < t < 1
* @param {Object} bezier : a Bézier curve created with bezier.create().
* @param {object} bezier : a Bézier curve created with bezier.create().
* @returns {array | number} the value at the requested position.
* @alias module:modeling/curves/bezier.valueAt
*/
Expand Down
4 changes: 1 addition & 3 deletions packages/modeling/src/curves/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export * as bezier from './bezier'

export as namespace curves
export * as bezier from './bezier/index.js'
4 changes: 2 additions & 2 deletions packages/modeling/src/geometries/geom2/applyTransforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as vec2 from '../../maths/vec2/index.js'
/*
* Apply the transforms of the given geometry.
* NOTE: This function must be called BEFORE exposing any data. See toOutlines().
* @param {geom2} geometry - the geometry to transform
* @returns {geom2} the given geometry
* @param {Geom2} geometry - the geometry to transform
* @returns {Geom2} the given geometry
*
* @example
* geometry = applyTransforms(geometry)
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/geometries/geom2/clone.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Geom2 } from './type'
import type { Geom2 } from './type.d.ts'

export function clone(geometry: Geom2): Geom2
4 changes: 2 additions & 2 deletions packages/modeling/src/geometries/geom2/clone.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Performs a shallow clone of the given geometry.
* @param {geom2} geometry - the geometry to clone
* @returns {geom2} new geometry
* @param {Geom2} geometry - the geometry to clone
* @returns {Geom2} new geometry
* @alias module:modeling/geometries/geom2.clone
*/
export const clone = (geometry) => Object.assign({}, geometry)
4 changes: 2 additions & 2 deletions packages/modeling/src/geometries/geom2/create.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Geom2 } from './type'
import { Vec2 } from '../../maths/vec2/type'
import type { Geom2 } from './type.d.ts'
import type { Vec2 } from '../../maths/vec2/type.d.ts'

export function create(outlines?: Array<Array<Vec2>>): Geom2
5 changes: 2 additions & 3 deletions packages/modeling/src/geometries/geom2/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import * as mat4 from '../../maths/mat4/index.js'

/**
* Represents a 2D geometry consisting of outlines, where each outline is an ordered list of points.
* @typedef {Object} geom2
* @property {Array} outlines - list of polygon outlines
* @property {mat4} transforms - transforms to apply to the geometry, see transform()
* @property {Mat4} transforms - transforms to apply to the geometry, see transform()
* @example
* // data structure
* {
Expand All @@ -16,7 +15,7 @@ import * as mat4 from '../../maths/mat4/index.js'
/**
* Create a new 2D geometry composed of polygon outlines.
* @param {Array} [outlines] - list of outlines where each outline is an array of points
* @returns {geom2} a new geometry
* @returns {Geom2} a new geometry
* @alias module:modeling/geometries/geom2.create
* @example
* let myShape = create([ [[-1,-1], [1,-1], [1,1], [-1,1]] ])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Geom2 } from './type'
import type { Geom2 } from './type.d.ts'

export function fromCompactBinary(data: Array<number> | Float32Array | Float64Array): Geom2
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { create } from './create.js'
/**
* Create a new 2D geometry from the given compact binary data.
* @param {Array} data - compact binary data
* @returns {geom2} a new geometry
* @returns {Geom2} a new geometry
* @alias module:modeling/geometries/geom2.fromCompactBinary
*/
export const fromCompactBinary = (data) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/modeling/src/geometries/geom2/fromSides.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Geom2 } from './type'
import { Vec2 } from '../../maths/vec2/type'
import type { Geom2 } from './type.d.ts'
import type { Vec2 } from '../../maths/vec2/type.d.ts'

export function fromSides(sides: Array<[Vec2, Vec2]>): Geom2
2 changes: 1 addition & 1 deletion packages/modeling/src/geometries/geom2/fromSides.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const toPointMap = (sides) => {
/**
* Create a new 2D geometry from a list of sides.
* @param {Array} sides - list of sides to create outlines from
* @returns {geom2} a new geometry
* @returns {Geom2} a new geometry
*
* @example
* let geometry = fromSides([[[0, 0], [1, 0]], [[1, 0], [1, 1]], [[1, 1], [0, 0]]])
Expand Down

0 comments on commit 0a0d2e8

Please sign in to comment.