Skip to content

Commit

Permalink
refactor: Various minor improvements to code
Browse files Browse the repository at this point in the history
  • Loading branch information
Undistraction committed Aug 1, 2024
1 parent c4653cc commit 4bfc30f
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 218 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ node_modules/
**/dist/

# Docs (we generate on build)

/docs

# Local files
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"version": "1.7.0",
"packageManager": "pnpm@9.6.0",
"description": "Create a Coons patch and access points and curves on its surface",
"main": "./dist/index.common.js",
"exports": {
".": {
"import": "./dist/index.mjs",
"import": "./dist/index.common.js",
"require": "./dist/index.common.js",
"types": "./dist/index.d.ts",
"source": "./src/index.ts"
Expand Down Expand Up @@ -43,8 +44,7 @@
"docs-open": "open ./docs/index.html",
"release-preview": "semantic-release --no-ci --dry-run --debug",
"link": "pnpm link --global",
"unlink": "pnpm unlink --global",
"tsc": "tsc ./src/index.ts"
"unlink": "pnpm unlink --global"
},
"keywords": [
"coons patch",
Expand Down Expand Up @@ -87,7 +87,7 @@
"typedoc": "^0.26.5",
"typescript": "5.4.2",
"vite": "^5.3.3",
"vite-plugin-dts": "4.0.0-beta.2"
"vite-plugin-dts": "3.9.1"
},
"dependencies": {
"fast-memoize": "^2.5.2",
Expand Down
329 changes: 126 additions & 203 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ export const getSurfaceCurves = (
}
}

// // -----------------------------------------------------------------------------
// // Re-export Types
// // -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Re-export Types
// -----------------------------------------------------------------------------

// export * from './types'
4 changes: 2 additions & 2 deletions src/interpolate/pointOnCurve/even.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import memoize from 'fast-memoize'
import { Curve, Point, Points } from '../../types'
import { Curve, InterpolatePointOnCurve, Point, Points } from '../../types'
import { times, timesReduce } from '../../utils/functional'
import { getDistanceBetweenPoints, roundTo10 } from '../../utils/math'
import { validateT } from '../../utils/validation'
Expand Down Expand Up @@ -78,7 +78,7 @@ export const interpolatePointOnCurveEvenlySpaced =
// Get an approximation using an arbitrary number of points. Increase for
// more accuracy at cost of performance
{ precision }: { precision: number }
) =>
): InterpolatePointOnCurve =>
(t: number, curve: Curve): Point => {
// Round the ratio to 10 decimal places to avoid rounding issues where the
// number is fractionally over 1 or below 0
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export type GetCoordinateOnSurfaceConfig = {
u: number
v: number
}
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
export type ObjectWithStringKeys = { [key: string]: any }

// -----------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions src/utils/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ const getTotalValues = (columns: Steps, rows: Steps) => ({
rowsTotalValue: addAll(rows),
})

const expandToSteps = (unprocessedSteps: UnprocessedSteps): ExpandedSteps => {
const ensureArray = (unprocessedSteps: UnprocessedSteps): ExpandedSteps => {
if (isInt(unprocessedSteps)) {
return times(() => unprocessedSteps, unprocessedSteps)
return times(() => 1, unprocessedSteps)
}
return unprocessedSteps
}

const convertToObjects = (steps: ExpandedSteps): Steps =>
const ensureObjects = (steps: ExpandedSteps): Steps =>
steps.map((step: UnprocessedStep) => {
if (isPlainObj(step)) {
return step as Step
Expand All @@ -59,8 +59,8 @@ export const getTSize = (
}

export const processSteps = (steps: UnprocessedSteps): Steps => {
const arrayOfSteps = expandToSteps(steps)
return convertToObjects(arrayOfSteps)
const arrayOfSteps = ensureArray(steps)
return ensureObjects(arrayOfSteps)
}

export const getStepData = (
Expand Down

0 comments on commit 4bfc30f

Please sign in to comment.