Skip to content

Commit

Permalink
modeling: flatten exports
Browse files Browse the repository at this point in the history
Everything is now exported as a top-level export from @jscad/modeling.

import { circle, union, colorize, translate } from '@jscad/modelin'

In the process there were some name conflict with utils. So I made some
choices about exactly which util functions to export: degToRad, radToDeg, sin, cos.
Also exports the constants EPS, NEPS, TAU.

I updated aliases and examples to reflect the new exports.
  • Loading branch information
platypii committed Sep 7, 2023
1 parent 5cfb4d2 commit db62dc5
Show file tree
Hide file tree
Showing 108 changed files with 141 additions and 180 deletions.
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/colorNameToRgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { cssColors } from './cssColors.js'
*
* @param {string} s - the CSS color name
* @return {Array} the RGB color, or undefined if not found
* @alias module:modeling/colors.colorNameToRgb
* @alias module:modeling/colorNameToRgb
* @example
* let mySphere = colorize(colorNameToRgb('lightblue'), sphere())
*/
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 @@ -34,7 +34,7 @@ const colorPoly3 = (color, object) => {
* @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
* @return {Object|Array} new object, or list of new objects with an additional attribute 'color'
* @alias module:modeling/colors.colorize
* @alias module:modeling/colorize
*
* @example
* let redSphere = colorize([1,0,0], sphere()) // red
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/cssColors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @alias module:modeling/colors.cssColors
* @alias module:modeling/cssColors
* @see CSS color table from http://www.w3.org/TR/css3-color/
* @enum {Array}
* @example
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/hexToRgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @see https://www.w3.org/TR/css-color-3/
* @param {string} notation - color notation
* @return {Array} RGB color values
* @alias module:modeling/colors.hexToRgb
* @alias module:modeling/hexToRgb
*
* @example
* let mySphere = colorize(hexToRgb('#000080'), sphere()) // navy blue
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/hslToRgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { hueToColorComponent } from './hueToColorComponent.js'
* @see http://en.wikipedia.org/wiki/HSL_color_space
* @param {...Number|Array} values - HSL or HSLA color values
* @return {Array} RGB or RGBA color values
* @alias module:modeling/colors.hslToRgb
* @alias module:modeling/hslToRgb
*
* @example
* let mySphere = colorize(hslToRgb([0.9166666666666666, 1, 0.5]), sphere())
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/hsvToRgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { flatten } from '../utils/flatten.js'
* @see http://en.wikipedia.org/wiki/HSV_color_space.
* @param {...Number|Array} values - HSV or HSVA color values
* @return {Array} RGB or RGBA color values
* @alias module:modeling/colors.hsvToRgb
* @alias module:modeling/hsvToRgb
*
* @example
* let mySphere = colorize(hsvToRgb([0.9166666666666666, 1, 1]), sphere())
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 @@ -4,7 +4,7 @@
* @param {Number} q
* @param {Number} t
* @return {number} color component
* @alias module:modeling/colors.hueToColorComponent
* @alias module:modeling/hueToColorComponent
*/
export const hueToColorComponent = (p, q, t) => {
if (t < 0) t += 1
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/rgbToHex.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { flatten } from '../utils/flatten.js'
* @see https://www.w3.org/TR/css-color-3/
* @param {...Number|Array} values - RGB or RGBA color values
* @return {String} CSS color notation
* @alias module:modeling/colors.rgbToHex
* @alias module:modeling/rgbToHex
*/
export const rgbToHex = (...values) => {
values = flatten(values)
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/rgbToHsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { flatten } from '../utils/flatten.js'
* @see http://axonflux.com/handy-rgb-to-hsl-and-rgb-to-hsv-color-model-c
* @param {...Number|Array} values - RGB or RGBA color values
* @return {Array} HSL or HSLA color values
* @alias module:modeling/colors.rgbToHsl
* @alias module:modeling/rgbToHsl
*/
export const rgbToHsl = (...values) => {
values = flatten(values)
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/colors/rgbToHsv.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { flatten } from '../utils/flatten.js'
* @see http://en.wikipedia.org/wiki/HSV_color_space.
* @param {...Number|Array} values - RGB or RGBA color values
* @return {Array} HSV or HSVA color values
* @alias module:modeling/colors.rgbToHsv
* @alias module:modeling/rgbToHsv
*/
export const rgbToHsv = (...values) => {
values = flatten(values)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { area } from '../../../maths/utils/index.js'
import { area } from '../../../maths/utils/area.js'
import { toOutlines } from '../../geom2/index.js'
import * as poly2 from '../../poly2/index.js'

Expand Down
28 changes: 14 additions & 14 deletions packages/modeling/src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export * as colors from './colors/index.js'
export * as curves from './curves/index.js'
export * as geometries from './geometries/index.js'
export * as maths from './maths/index.js'
export * as measurements from './measurements/index.js'
export * as primitives from './primitives/index.js'
export * as text from './text/index.js'
export * as utils from './utils/index.js'
export * from './colors/index.js'
export * from './curves/index.js'
export * from './geometries/index.js'
export * from './maths/index.js'
export * from './measurements/index.js'
export * from './primitives/index.js'
export * from './text/index.js'
export { degToRad, radToDeg } from './utils/index.js'

export * as booleans from './operations/booleans/index.js'
export * as extrusions from './operations/extrusions/index.js'
export * as hulls from './operations/hulls/index.js'
export * as modifiers from './operations/modifiers/index.js'
export * as offsets from './operations/offsets/index.js'
export * as transforms from './operations/transforms/index.js'
export * from './operations/booleans/index.js'
export * from './operations/extrusions/index.js'
export * from './operations/hulls/index.js'
export * from './operations/modifiers/index.js'
export * from './operations/offsets/index.js'
export * from './operations/transforms/index.js'
6 changes: 3 additions & 3 deletions packages/modeling/src/maths/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Epsilon used during determination of near zero distances.
* This should be 1 / spacialResolution.
* @default
* @alias module:modeling/maths.EPS
* @alias module:modeling/EPS
* @example
* const { EPS } = maths.constants
*/
Expand All @@ -11,7 +11,7 @@ export const EPS = 1e-5
/**
* Smaller epsilon used for measuring near zero distances.
* @default
* @alias module:modeling/maths.NEPS
* @alias module:modeling/NEPS
* @example
* const { NEPS } = maths.constants
*/
Expand All @@ -23,7 +23,7 @@ export const NEPS = 1e-13
/**
* The TAU property represents the ratio of the circumference of a circle to its radius.
* Approximately 6.28318530717958647692
* @alias module:modeling/maths.TAU
* @alias module:modeling/TAU
* @default
* @example
* const { TAU } = maths.constants
Expand Down
4 changes: 2 additions & 2 deletions packages/modeling/src/maths/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export * as constants from './constants.js'
export * from './constants.js'
export * as line2 from './line2/index.js'
export * as line3 from './line3/index.js'
export * as mat4 from './mat4/index.js'
export * as plane from './plane/index.js'
export * as utils from './utils/index.js'
export * as vec2 from './vec2/index.js'
export * as vec3 from './vec3/index.js'
export * as vec4 from './vec4/index.js'
export { sin, cos } from './utils/trigonometry.js'
7 changes: 3 additions & 4 deletions packages/modeling/src/maths/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
* @see Most computations are based upon the glMatrix library (glmatrix.net)
* @module modeling/maths
* @example
* import { maths } from '@jscad/modeling'
* const { constants, line2, line3, mat4, plane, utils, vec2, vec3, vec4 } = maths
* import { constants, line2, line3, mat4, plane, utils, vec2, vec3, vec4 } from '@jscad/modeling'
*/
export * as constants from './constants.js'
export * from './constants.js'
export * as line2 from './line2/index.js'
export * as line3 from './line3/index.js'
export * as mat4 from './mat4/index.js'
export * as plane from './plane/index.js'
export * as utils from './utils/index.js'
export * as vec2 from './vec2/index.js'
export * as vec3 from './vec3/index.js'
export * as vec4 from './vec4/index.js'
export { cos, sin } from './utils/trigonometry.js'
2 changes: 1 addition & 1 deletion packages/modeling/src/maths/line2/intersectPointOfLines.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vec2 from '../vec2/index.js'

import { solve2Linear } from '../utils/index.js'
import { solve2Linear } from '../utils/solve2Linear.js'

/**
* Return the point of intersection between the given lines.
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/maths/line3/fromPlanes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vec3 from '../vec3/index.js'
import { solve2Linear } from '../utils/index.js'
import { solve2Linear } from '../utils/solve2Linear.js'
import { EPS } from '../constants.js'

import { fromPointAndDirection } from './fromPointAndDirection.js'
Expand Down
4 changes: 2 additions & 2 deletions packages/modeling/src/maths/rotation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'ava'

import { compareVectors } from '../../test/helpers/index.js'

import { constants, mat4, vec2, vec3 } from './index.js'
import { TAU, mat4, vec2, vec3 } from './index.js'

// ALL POSITIVE ROTATIONS ARE CLOCKWISE
// see https://webglfundamentals.org/webgl/lessons/webgl-3d-orthographic.html
Expand All @@ -13,7 +13,7 @@ import { constants, mat4, vec2, vec3 } from './index.js'

// identity matrices for comparisons

const rad90 = constants.TAU / 4
const rad90 = TAU / 4

// +90 degree rotation about X
const cwX90Matrix = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import test from 'ava'
import * as vec3 from '../vec3/index.js'
import { plane } from '../index.js'

import { OrthonormalFormula } from './index.js'
import { OrthonormalFormula } from './OrthonormalFormula.js'

test('utils: OrthonormalFormula constructor', (t) => {
const p1 = plane.fromNormalAndPoint(plane.create(), [5, 0, 0], [0, 0, 0])
Expand Down
3 changes: 1 addition & 2 deletions packages/modeling/src/maths/utils/aboutEqualNormals.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { NEPS } from '../constants.js'
* Compare two normals (unit vectors) for near equality.
* @param {Vec3} a - normal a
* @param {Vec3} b - normal b
* @returns {Boolean} true if a and b are nearly equal
* @alias module:modeling/maths/utils.aboutEqualNormals
* @returns {boolean} true if a and b are nearly equal
*/
export const aboutEqualNormals = (a, b) => (Math.abs(a[0] - b[0]) <= NEPS && Math.abs(a[1] - b[1]) <= NEPS && Math.abs(a[2] - b[2]) <= NEPS)
3 changes: 1 addition & 2 deletions packages/modeling/src/maths/utils/area.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* Calculate the area under the given points.
* @param {Array} points - list of 2D points
* @param {Vec2[]} points - list of 2D points
* @return {number} area under the given points
* @alias module:modeling/maths/utils.area
*/
export const area = (points) => {
let area = 0
Expand Down
7 changes: 0 additions & 7 deletions packages/modeling/src/maths/utils/index.d.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/modeling/src/maths/utils/index.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @param {Vec2} point2
* @param {number} y
* @return {Array} X and Y of interpolated point
* @alias module:modeling/maths/utils.interpolateBetween2DPointsForY
*/
export const interpolateBetween2DPointsForY = (point1, point2, y) => {
let f1 = y - point1[1]
Expand Down
1 change: 0 additions & 1 deletion packages/modeling/src/maths/utils/intersect.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* @param {Vec2} p4 - second point of second line segment
* @param {boolean} endpointTouch - include intersections at segment endpoints
* @returns {Vec2} intersection point of the two line segments, or undefined
* @alias module:modeling/maths/utils.intersect
*/
export const intersect = (p1, p2, p3, p4, endpointTouch = true) => {
// Check if none of the lines are of length 0
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/maths/utils/intersect.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'ava'

import * as vec2 from '../vec2/index.js'
import { intersect } from './index.js'
import { intersect } from './intersect.js'

// A __F
// / \ __E
Expand Down
4 changes: 2 additions & 2 deletions packages/modeling/src/maths/utils/trigonometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const rezero = (n) => Math.abs(n) < NEPS ? 0 : n
*
* @param {number} radians - angle in radians
* @returns {number} sine of the given angle
* @alias module:modeling/utils.sin
* @alias module:modeling/sin
* @example
* sin(TAU / 2) == 0
* sin(TAU) == 0
Expand All @@ -24,7 +24,7 @@ export const sin = (radians) => rezero(Math.sin(radians))
*
* @param {number} radians - angle in radians
* @returns {number} cosine of the given angle
* @alias module:modeling/utils.cos
* @alias module:modeling/cos
* @example
* cos(TAU * 0.25) == 0
* cos(TAU * 0.75) == 0
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/maths/utils/trigonometry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'ava'

import { TAU } from '../constants.js'

import { cos, sin } from './index.js'
import { cos, sin } from './trigonometry.js'

test('utils: sin() should return rounded values', (t) => {
t.is(sin(0), 0)
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/measurements/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* All shapes (primitives or the results of operations) can be measured, e.g. calculate volume, etc.
* @module modeling/measurements
* @example
* import { measureArea, measureBoundingBox, measureVolume } from '@jscad/modeling/measurements')
* import { measureArea, measureBoundingBox, measureVolume } from '@jscad/modeling')
*/
export { measureAggregateArea } from './measureAggregateArea.js'
export { measureAggregateBoundingBox } from './measureAggregateBoundingBox.js'
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/measurements/measureAggregateArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { measureArea } from './measureArea.js'
* Note: This measurement will not account for overlapping geometry
* @param {...Object} geometries - the geometries to measure.
* @return {number} the total surface area for the group of geometry.
* @alias module:modeling/measurements.measureAggregateArea
* @alias module:modeling/measureAggregateArea
*
* @example
* let totalArea = measureAggregateArea(sphere(),cube())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { measureBoundingBox } from './measureBoundingBox.js'
* Measure the aggregated minimum and maximum bounds for the given geometries.
* @param {...Object} geometries - the geometries to measure
* @return {Array} the min and max bounds for the group of geometry, i.e. [[x,y,z],[X,Y,Z]]
* @alias module:modeling/measurements.measureAggregateBoundingBox
* @alias module:modeling/measureAggregateBoundingBox
*
* @example
* let bounds = measureAggregateBoundingBox(sphere(),cube())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { calculateEpsilonFromBounds } from './calculateEpsilonFromBounds.js'
* Measure the aggregated Epsilon for the given geometries.
* @param {...Object} geometries - the geometries to measure
* @return {number} the aggregated Epsilon for the whole group of geometries
* @alias module:modeling/measurements.measureAggregateEpsilon
* @alias module:modeling/measureAggregateEpsilon
*
* @example
* let groupEpsilon = measureAggregateEpsilon(sphere(),cube())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { measureVolume } from './measureVolume.js'
* Note: This measurement will not account for overlapping geometry
* @param {...Object} geometries - the geometries to measure.
* @return {number} the volume for the group of geometry.
* @alias module:modeling/measurements.measureAggregateVolume
* @alias module:modeling/measureAggregateVolume
*
* @example
* let totalVolume = measureAggregateVolume(sphere(),cube())
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/measurements/measureArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const measureAreaOfSlice = (geometry) => {
* Measure the area of the given geometries.
* @param {...Object} geometries - the geometries to measure
* @return {number|Array} the area, or a list of areas for each geometry
* @alias module:modeling/measurements.measureArea
* @alias module:modeling/measureArea
*
* @example
* let area = measureArea(sphere())
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/measurements/measureBoundingBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const measureBoundingBoxOfSlice = (geometry) => {
* Measure the min and max bounds of the given geometries.
* @param {...Object} geometries - the geometries to measure
* @return {Array} the min and max bounds, or a list of bounds for each geometry
* @alias module:modeling/measurements.measureBoundingBox
* @alias module:modeling/measureBoundingBox
*
* @example
* let bounds = measureBoundingBox(sphere())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const measureBoundingSphereOfSlice = (geometry) => {
* @see https://en.wikipedia.org/wiki/Bounding_sphere
* @param {...Object} geometries - the geometries to measure
* @return {Array} the bounding sphere for each geometry, i.e. [centroid, radius]
* @alias module:modeling/measurements.measureBoundingSphere
* @alias module:modeling/measureBoundingSphere
*
* @example
* let bounds = measureBoundingSphere(cube())
Expand Down
2 changes: 1 addition & 1 deletion packages/modeling/src/measurements/measureCenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { measureBoundingBox } from './measureBoundingBox.js'
* Measure the center of the given geometries.
* @param {...Object} geometries - the geometries to measure
* @return {Array} the center vertex for each geometry, i.e. [X, Y, Z]
* @alias module:modeling/measurements.measureCenter
* @alias module:modeling/measureCenter
*
* @example
* let center = measureCenter(sphere())
Expand Down
Loading

0 comments on commit db62dc5

Please sign in to comment.