@daeinc/geom
Advanced tools
Comparing version 0.10.0 to 0.10.1
import * as _thi_ng_vectors from '@thi.ng/vectors'; | ||
type Pt = number[]; | ||
type Pts = number[][]; | ||
type Pts = Pt[]; | ||
type GenericObject = Record<string, any>; | ||
@@ -22,4 +22,5 @@ /** | ||
* the resulting function is transformed to draw from center [0, 0] | ||
* | ||
* @param pts must be a normalized array (0..1) of [x, y]s | ||
* @param anchor normalized center point [x, y] | ||
* @param anchor normalized center point [x, y]. default: [0.5, 0.5] | ||
* @returns function to draw shape with given params (x,y,w,h) | ||
@@ -29,3 +30,4 @@ */ | ||
/** | ||
* calculate distance between two point[]s | ||
* calculate distance between two points | ||
* | ||
* @param pt1 | ||
@@ -37,3 +39,4 @@ * @param pt2 | ||
/** | ||
* squared distance (x^2 + y^2) between two point[]s | ||
* squared distance (x^2 + y^2) between two points | ||
* | ||
* @param pt1 | ||
@@ -52,3 +55,3 @@ * @param pt2 | ||
* @param numPointsToExtrude how many points to use for extruding (mirroring). useful when extruding same path again. | ||
* @param offset [ x, y ] how much +/- in each dimension | ||
* @param offset [ x, y ] how much +/- in each dimension. if number, will be converted to number[] | ||
* @param mode start (reverse direction) | end | both (closed path) | ||
@@ -58,3 +61,3 @@ * @param shapeFunc optional. function on how to extrude if other than straight line | ||
*/ | ||
declare const extrudePath: (path: Pts, numPointsToExtrude: number, offset: Pt, mode?: "start" | "end" | "both") => number[][]; | ||
declare const extrudePath: (path: Pts, numPointsToExtrude: number, offset: Pt | number, mode?: "start" | "end" | "both") => Pt[]; | ||
/** | ||
@@ -174,14 +177,14 @@ * generate extra points for smooth hard corners of path | ||
* @param pt a point [x, y] | ||
* @param size [width, height] to scale to | ||
* @param size [width, height] to scale to. if number, it is converted to number[] | ||
* @returns scaled point [x, y]` | ||
*/ | ||
declare const scalePoint: (pt: Pt, size: Pt) => Pt; | ||
declare const scalePoint: (pt: Pt, size: Pt | number) => Pt; | ||
/** | ||
* take normalized path data and return [ x, y ] scaled to width and height | ||
* @param path array of [x, y] normalized point pairs | ||
* @param size [width, height] to scale to | ||
* @param size [width, height] to scale to. if number, it is scaled to number[] | ||
* @returns new array of [x, y] | ||
*/ | ||
declare const scalePath: (path: Pts, size: Pt) => Pts; | ||
declare const scalePath: (path: Pts, size: Pt | number) => Pts; | ||
export { GenericObject, Pt, Pts, blendPath, createShapeFunc, dist, distSq, extrudePath, generateSmoothPath, getAngleBetween, getPathLength, getPositiveAngleBetween, getSegmentLengths, interpolate, interpolateArray, interpolateObject, interpolatePath, projectPointOnLine, reflectPath, reflectPoint, rotatePoint, scalePath, scalePoint }; |
@@ -31,2 +31,5 @@ import { TWO_PI, mix, reflect, roundF } from '@daeinc/math'; | ||
} | ||
if (typeof offset === "number") { | ||
offset = [offset, offset]; | ||
} | ||
const clone = [...path]; | ||
@@ -100,3 +103,3 @@ if (mode === "end") { | ||
throw new Error("interpolatePath(): length must be same"); | ||
out = out || new Array(pathStart.length).fill([]).map(() => []); | ||
out = out || new Array(pathStart.length).fill([]).map(() => [0, 0]); | ||
for (let i = 0; i < pathStart.length; i++) { | ||
@@ -175,6 +178,7 @@ out[i][0] = mix(pathStart[i][0], pathTarget[i][0], t); | ||
const [x, y] = pt; | ||
const [w, h] = size; | ||
const [w, h] = typeof size === "number" ? [size, size] : size; | ||
return [x * w, y * h]; | ||
}; | ||
var scalePath = (path, size) => { | ||
size = typeof size === "number" ? [size, size] : size; | ||
return path.map((pt) => scalePoint(pt, size)); | ||
@@ -181,0 +185,0 @@ }; |
{ | ||
"name": "@daeinc/geom", | ||
"version": "0.10.0", | ||
"version": "0.10.1", | ||
"description": "Geometry utilities", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39141
367