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.2.4
## 1.16.1
### Patch Changes
- Fix clipboard bug in Firefox, add overwite option to `insertContent`.
## 1.16.0 ## 1.16.0
### Minor Changes ### Minor Changes

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -449,6 +449,42 @@ export class Vec {
return Vec.dist(P, Vec.nearestPointOnLineSegment(A, B, P, clamp)) 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. * Push a point A towards point B by a given distance.
* @param A * @param A