1.7.2, add Vec.distanceTo / Vec.nearestPointOnBounds

This commit is contained in:
Steve Ruiz 2022-06-21 08:49:45 +01:00
parent 7c0e098b12
commit a17bd18ae2
7 changed files with 58 additions and 3 deletions

View file

@ -1,5 +1,11 @@
## 1.2.4
## 1.16.1
### Patch Changes
- Fix clipboard bug in Firefox, add overwite option to `insertContent`.
## 1.16.0
### Minor Changes

View file

@ -2,7 +2,7 @@
"name": "tldraw-vscode",
"displayName": "tldraw",
"description": "The tldraw Extension for VS Code.",
"version": "1.16.0",
"version": "1.16.1",
"license": "MIT",
"publisher": "tldraw-org",
"repository": {

View file

@ -1,5 +1,12 @@
# @tldraw/www
## 1.7.2
### Patch Changes
- Updated dependencies
- @tldraw/tldraw@1.17.1
## 1.7.1
### Patch Changes

View file

@ -1,6 +1,6 @@
{
"name": "@tldraw/www",
"version": "1.7.1",
"version": "1.7.2",
"private": true,
"description": "A tiny little drawing app (site).",
"repository": {

View file

@ -1,5 +1,11 @@
# Changelog
## 1.17.1
### Patch Changes
- Fix clipboard bug in Firefox, add overwite option to `insertContent`.
## 1.17.0
### Minor Changes

View file

@ -1,6 +1,6 @@
{
"name": "@tldraw/tldraw",
"version": "1.17.0",
"version": "1.17.1",
"description": "A tiny little drawing app (editor)",
"author": "@steveruizok",
"repository": {

View file

@ -449,6 +449,42 @@ export class Vec {
return Vec.dist(P, Vec.nearestPointOnLineSegment(A, B, P, clamp))
}
/**
* Get the nearest point on a bounding box to a point P.
* @param bounds The bounding box
* @param P The point point
* @returns
*/
static nearestPointOnBounds = (
bounds: {
minX: number
minY: number
maxX: number
maxY: number
},
P: number[]
): number[] => {
return [Vec.clamp(P[0], bounds.minX, bounds.maxX), Vec.clamp(P[1], bounds.minY, bounds.maxY)]
}
/**
* Distance between a point and the nearest point on a bounding box.
* @param bounds The bounding box.
* @param P The point
* @returns
*/
static distanceToBounds = (
bounds: {
minX: number
minY: number
maxX: number
maxY: number
},
P: number[]
): number => {
return Vec.dist(P, Vec.nearestPointOnBounds(bounds, P))
}
/**
* Push a point A towards point B by a given distance.
* @param A