[fix] intersection bug (#452)

* Update TLShapeUtil.tsx

* Add tests

* Update tsconfig.json
This commit is contained in:
Steve Ruiz 2021-12-17 16:29:08 +00:00 committed by GitHub
parent 34492f2f01
commit 58b8968f12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 5 deletions

View file

@ -2,7 +2,7 @@
import * as React from 'react'
import Utils from '../utils'
import type { TLBounds, TLComponentProps, TLForwardedRef, TLShape, TLUser } from '../types'
import { intersectPolylineBounds } from '@tldraw/intersect'
import { intersectPolygonBounds, intersectPolylineBounds } from '@tldraw/intersect'
export abstract class TLShapeUtil<T extends TLShape, E extends Element = any, M = any> {
refMap = new Map<string, React.RefObject<E>>()
@ -42,7 +42,7 @@ export abstract class TLShapeUtil<T extends TLShape, E extends Element = any, M
const corners = Utils.getRotatedCorners(shapeBounds, shape.rotation)
return (
corners.every((point) => Utils.pointInBounds(point, bounds)) ||
intersectPolylineBounds(corners, bounds).length > 0
intersectPolygonBounds(corners, bounds).length > 0
)
}

View file

@ -664,7 +664,9 @@ describe('TldrawTestApp', () => {
const shapes = mockDocument.pages.page1.shapes
const bindings = mockDocument.pages.page1.bindings
const app = new TldrawTestApp('multiplayer', {
onChangePage: () => {},
onChangePage: () => {
//
},
}).createPage()
app.replacePageContent(shapes, bindings)
@ -676,7 +678,9 @@ describe('TldrawTestApp', () => {
const shapes = mockDocument.pages.page1.shapes
const bindings = mockDocument.pages.page1.bindings
const app = new TldrawTestApp('multiplayer', {
onChangePage: () => {},
onChangePage: () => {
//
},
}).createPage()
app.setSetting('isDebugMode', true)
app.replacePageContent(shapes, bindings)
@ -685,4 +689,14 @@ describe('TldrawTestApp', () => {
expect(app.bindings).toEqual(Object.values(bindings))
})
})
describe('When selecting a box', () => {
const app = new TldrawTestApp()
app
.createShapes({ id: 'box1', type: TDShapeType.Rectangle, point: [0, 0], size: [100, 100] })
.pointCanvas([-50, 20])
.movePointer([50, 50])
.movePointer([50, 51])
.expectSelectedIdsToBe(['box1'])
})
})

View file

@ -8,7 +8,7 @@ describe('Brush session', () => {
.selectNone()
.movePointer([-48, -48])
.startSession(SessionType.Brush)
.movePointer([48, 48])
.movePointer([10, 10])
.completeSession()
expect(app.status).toBe(TDStatus.Idle)
expect(app.selectedIds.length).toBe(1)

View file

@ -33,6 +33,8 @@ export class BrushSession extends BaseSession {
bounds: this.app.getShapeUtil(shape).getBounds(shape),
selectId: shape.id, //TLDR.getTopParentId(data, shape.id, currentPageId),
}))
this.update()
}
start = (): TldrawPatch | undefined => void null