Improve filled draw shaped in dynamic size mode (#3974)
Still some improvements to be made with how we determine when to close a draw shape, but filled draw shapes now close more reliably in dynamic size mode. ![2024-06-18 at 14 26 56 - Aquamarine Booby](https://github.com/tldraw/tldraw/assets/98838967/51402feb-6450-4f8c-8736-250454bcecdb) ### Change Type <!-- ❗ Please select a 'Scope' label ❗️ --> - [ ] `sdk` — Changes the tldraw SDK - [x] `dotcom` — Changes the tldraw.com web app - [ ] `docs` — Changes to the documentation, examples, or templates. - [ ] `vs code` — Changes to the vscode plugin - [ ] `internal` — Does not affect user-facing stuff <!-- ❗ Please select a 'Type' label ❗️ --> - [ ] `bugfix` — Bug fix - [ ] `feature` — New feature - [x] `improvement` — Improving existing features - [ ] `chore` — Updating dependencies, other boring stuff - [ ] `galaxy brain` — Architectural changes - [ ] `tests` — Changes to any test code - [ ] `tools` — Changes to infrastructure, CI, internal scripts, debugging tools, etc. - [ ] `dunno` — I don't know ### Test Plan 1. Select the draw tool 2. set dynamic resize mode 3. Zoom in to 800% 4. Try to draw a closed shape, it should close! ### Release Notes - Improve closing of draw shapes in dynamic size mode --------- Co-authored-by: Steve Ruiz <steveruizok@gmail.com>
This commit is contained in:
parent
873e01583c
commit
9d02ca9cbe
1 changed files with 14 additions and 9 deletions
|
@ -149,7 +149,7 @@ export class Drawing extends StateNode {
|
|||
return this.shapeType !== 'highlight'
|
||||
}
|
||||
|
||||
getIsClosed(segments: TLDrawShapeSegment[], size: TLDefaultSizeStyle) {
|
||||
getIsClosed(segments: TLDrawShapeSegment[], size: TLDefaultSizeStyle, scale: number) {
|
||||
if (!this.canClose()) return false
|
||||
|
||||
const strokeWidth = STROKE_SIZES[size]
|
||||
|
@ -159,8 +159,8 @@ export class Drawing extends StateNode {
|
|||
|
||||
return (
|
||||
firstPoint !== lastPoint &&
|
||||
this.currentLineLength > strokeWidth * 4 &&
|
||||
Vec.DistMin(firstPoint, lastPoint, strokeWidth * 2)
|
||||
this.currentLineLength > strokeWidth * 4 * scale &&
|
||||
Vec.DistMin(firstPoint, lastPoint, strokeWidth * 2 * scale)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -245,7 +245,8 @@ export class Drawing extends StateNode {
|
|||
if (this.canClose()) {
|
||||
;(shapePartial as TLShapePartial<TLDrawShape>).props!.isClosed = this.getIsClosed(
|
||||
segments,
|
||||
shape.props.size
|
||||
shape.props.size,
|
||||
shape.props.scale
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -296,7 +297,7 @@ export class Drawing extends StateNode {
|
|||
|
||||
const {
|
||||
id,
|
||||
props: { size },
|
||||
props: { size, scale },
|
||||
} = initialShape
|
||||
|
||||
const shape = this.editor.getShape<DrawableShape>(id)!
|
||||
|
@ -374,7 +375,8 @@ export class Drawing extends StateNode {
|
|||
if (this.canClose()) {
|
||||
;(shapePartial as TLShapePartial<TLDrawShape>).props!.isClosed = this.getIsClosed(
|
||||
segments,
|
||||
size
|
||||
size,
|
||||
scale
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -442,7 +444,8 @@ export class Drawing extends StateNode {
|
|||
if (this.canClose()) {
|
||||
;(shapePartial as TLShapePartial<TLDrawShape>).props!.isClosed = this.getIsClosed(
|
||||
finalSegments,
|
||||
size
|
||||
size,
|
||||
scale
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -583,7 +586,8 @@ export class Drawing extends StateNode {
|
|||
if (this.canClose()) {
|
||||
;(shapePartial as TLShapePartial<TLDrawShape>).props!.isClosed = this.getIsClosed(
|
||||
segments,
|
||||
size
|
||||
size,
|
||||
scale
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -630,7 +634,8 @@ export class Drawing extends StateNode {
|
|||
if (this.canClose()) {
|
||||
;(shapePartial as TLShapePartial<TLDrawShape>).props!.isClosed = this.getIsClosed(
|
||||
newSegments,
|
||||
size
|
||||
size,
|
||||
scale
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue