@tldraw/primitives
Advanced tools
Comparing version 2.0.0-canary.2c8b431c1f31 to 2.0.0-canary.2d5b2bdc9472
@@ -225,2 +225,3 @@ import { Box2dModel } from '@tldraw/tlschema'; | ||
resize(handle: SelectionCorner | SelectionEdge | string, dx: number, dy: number): void; | ||
union(box: Box2dModel): this; | ||
static From(box: Box2dModel): Box2d; | ||
@@ -586,2 +587,8 @@ static FromPoints(points: VecLike[]): Box2d; | ||
/** | ||
* Check if a float is safe to use. ie: Not too big or small. | ||
* @public | ||
*/ | ||
export declare const isSafeFloat: (n: number) => boolean; | ||
/** @public */ | ||
@@ -982,2 +989,7 @@ export declare function isSelectionCorner(selection: string): selection is SelectionCorner; | ||
/** | ||
* @public | ||
*/ | ||
export declare function toFixed(v: number): number; | ||
/** | ||
* Get a number to a precision. | ||
@@ -984,0 +996,0 @@ * |
@@ -74,2 +74,3 @@ "use strict"; | ||
isAngleBetween: () => import_utils.isAngleBetween, | ||
isSafeFloat: () => import_utils.isSafeFloat, | ||
isSelectionCorner: () => import_Box2d.isSelectionCorner, | ||
@@ -99,2 +100,3 @@ lerpAngles: () => import_utils.lerpAngles, | ||
toDomPrecision: () => import_utils.toDomPrecision, | ||
toFixed: () => import_utils.toFixed, | ||
toPrecision: () => import_utils.toPrecision | ||
@@ -115,3 +117,2 @@ }); | ||
var import_setStrokePointRadii = require("./lib/freehand/setStrokePointRadii"); | ||
var import_types = require("./lib/freehand/types"); | ||
var import_intersect = require("./lib/intersect"); | ||
@@ -118,0 +119,0 @@ var import_polygon_helpers = require("./lib/polygon-helpers"); |
@@ -274,2 +274,13 @@ "use strict"; | ||
} | ||
union(box) { | ||
const minX = Math.min(this.minX, box.x); | ||
const minY = Math.min(this.minY, box.y); | ||
const maxX = Math.max(this.maxX, box.w + box.x); | ||
const maxY = Math.max(this.maxY, box.h + box.y); | ||
this.x = minX; | ||
this.y = minY; | ||
this.width = maxX - minX; | ||
this.height = maxY - minY; | ||
return this; | ||
} | ||
static From(box) { | ||
@@ -276,0 +287,0 @@ return new Box2d(box.x, box.y, box.w, box.h); |
@@ -44,2 +44,6 @@ "use strict"; | ||
const { a, b, c, d } = this.values; | ||
if (t <= 0) | ||
return import_Vec2d.Vec2d.From(a); | ||
if (t >= 1) | ||
return import_Vec2d.Vec2d.From(d); | ||
return new import_Vec2d.Vec2d( | ||
@@ -46,0 +50,0 @@ (1 - t) * (1 - t) * (1 - t) * a.x + 3 * ((1 - t) * (1 - t)) * t * b.x + 3 * (1 - t) * (t * t) * c.x + t * t * t * d.x, |
@@ -56,2 +56,6 @@ "use strict"; | ||
const { a, b } = this.values; | ||
if (t <= 0) | ||
return import_Vec2d.Vec2d.From(a); | ||
if (t >= 1) | ||
return import_Vec2d.Vec2d.From(b); | ||
return import_Vec2d.Vec2d.Lrp(a, b, t); | ||
@@ -58,0 +62,0 @@ } |
@@ -47,2 +47,3 @@ "use strict"; | ||
isAngleBetween: () => isAngleBetween, | ||
isSafeFloat: () => isSafeFloat, | ||
lerpAngles: () => lerpAngles, | ||
@@ -67,2 +68,3 @@ longAngleDist: () => longAngleDist, | ||
toDomPrecision: () => toDomPrecision, | ||
toFixed: () => toFixed, | ||
toPrecision: () => toPrecision | ||
@@ -395,2 +397,8 @@ }); | ||
} | ||
function toFixed(v) { | ||
return +v.toFixed(2); | ||
} | ||
const isSafeFloat = (n) => { | ||
return Math.abs(n) < Number.MAX_SAFE_INTEGER; | ||
}; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@tldraw/primitives", | ||
"description": "A tiny little drawing app (primitives).", | ||
"version": "2.0.0-canary.2c8b431c1f31", | ||
"version": "2.0.0-canary.2d5b2bdc9472", | ||
"packageManager": "yarn@3.5.0", | ||
@@ -45,3 +45,3 @@ "author": { | ||
"dependencies": { | ||
"@tldraw/tlschema": "2.0.0-canary.2c8b431c1f31" | ||
"@tldraw/tlschema": "2.0.0-canary.2d5b2bdc9472" | ||
}, | ||
@@ -58,4 +58,3 @@ "jest": { | ||
"devDependencies": { | ||
"benchmark": "^2.1.4", | ||
"lazyrepo": "0.0.0-alpha.26" | ||
"lazyrepo": "0.0.0-alpha.27" | ||
}, | ||
@@ -62,0 +61,0 @@ "module": "dist-esm/index.mjs", |
@@ -76,2 +76,3 @@ export { | ||
isAngleBetween, | ||
isSafeFloat, | ||
lerpAngles, | ||
@@ -96,3 +97,4 @@ longAngleDist, | ||
toDomPrecision, | ||
toFixed, | ||
toPrecision, | ||
} from './lib/utils' |
@@ -315,2 +315,16 @@ import { Box2dModel } from '@tldraw/tlschema' | ||
union(box: Box2dModel) { | ||
const minX = Math.min(this.minX, box.x) | ||
const minY = Math.min(this.minY, box.y) | ||
const maxX = Math.max(this.maxX, box.w + box.x) | ||
const maxY = Math.max(this.maxY, box.h + box.y) | ||
this.x = minX | ||
this.y = minY | ||
this.width = maxX - minX | ||
this.height = maxY - minY | ||
return this | ||
} | ||
static From(box: Box2dModel) { | ||
@@ -317,0 +331,0 @@ return new Box2d(box.x, box.y, box.w, box.h) |
@@ -34,5 +34,5 @@ import { CubicSegment2d } from './CubicSegment2d' | ||
it(`has the expected normals`, () => { | ||
expect(b.getNormal(0)).toMatchObject({ x: -1, y: -0 }) | ||
expect(b.getNormal(0)).toMatchObject({ x: -1, y: 0 }) | ||
expect(b.getNormal(0.5)).toMatchObject({ x: -0, y: 1 }) | ||
expect(b.getNormal(1)).toMatchObject({ x: 1, y: -0 }) | ||
expect(b.getNormal(1)).toMatchObject({ x: 1, y: 0 }) | ||
}) | ||
@@ -39,0 +39,0 @@ |
@@ -37,2 +37,5 @@ import { BaseSegment2d } from './BaseSegment2d' | ||
if (t <= 0) return Vec2d.From(a) | ||
if (t >= 1) return Vec2d.From(d) | ||
return new Vec2d( | ||
@@ -39,0 +42,0 @@ (1 - t) * (1 - t) * (1 - t) * a.x + |
@@ -107,4 +107,2 @@ import { Vec2d } from '../Vec2d' | ||
// console.log(nextDpr) | ||
if (nextDpr > -0.62 && totalLength - strokePoint.runningLength > strokePoint.radius) { | ||
@@ -111,0 +109,0 @@ // Draw a "soft" corner |
@@ -50,2 +50,5 @@ import { BaseSegment2d } from './BaseSegment2d' | ||
if (t <= 0) return Vec2d.From(a) | ||
if (t >= 1) return Vec2d.From(b) | ||
return Vec2d.Lrp(a, b, t) | ||
@@ -52,0 +55,0 @@ } |
@@ -670,1 +670,16 @@ import { Box2d } from './Box2d' | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export function toFixed(v: number) { | ||
return +v.toFixed(2) | ||
} | ||
/** | ||
* Check if a float is safe to use. ie: Not too big or small. | ||
* @public | ||
*/ | ||
export const isSafeFloat = (n: number) => { | ||
return Math.abs(n) < Number.MAX_SAFE_INTEGER | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
723839
1
11078
110
+ Added@tldraw/state@2.0.0-canary.2d5b2bdc9472(transitive)
+ Added@tldraw/store@2.0.0-canary.2d5b2bdc9472(transitive)
+ Added@tldraw/tlschema@2.0.0-canary.2d5b2bdc9472(transitive)
+ Added@tldraw/utils@2.0.0-canary.2d5b2bdc9472(transitive)
+ Added@tldraw/validate@2.0.0-canary.2d5b2bdc9472(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedreact@18.3.1(transitive)
- Removed@tldraw/tlschema@2.0.0-canary.2c8b431c1f31(transitive)
- Removed@tldraw/tlstore@2.0.0-canary.2c8b431c1f31(transitive)
- Removed@tldraw/tlvalidate@2.0.0-canary.2c8b431c1f31(transitive)
- Removed@tldraw/utils@2.0.0-canary.2c8b431c1f31(transitive)
- Removedsignia@0.1.5(transitive)