Package Exports
- @tldraw/intersect
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@tldraw/intersect) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@tldraw/intersect
This package contains 2D intersection utility functions used by tldraw.
💕 Love this library? Consider becoming a sponsor.
Installation
Use your package manager of choice to install @tldraw/intersect.
yarn add @tldraw/intersect
# or
npm i @tldraw/intersectUsage
This library exports many intersection functions. You can use these methods to find intersection points between various 2D shapes. Points are formatted as [x, y].
import { intersectLineSegmentEllipse } from "@tldraw/intersect"
const A = [5, 5]
const B = [10, 10]
const ellipse = { center: [10, 10], rx: 5, ry: 4, rotation: Math.PI / 6 }
const intersections = intersectLineSegmentEllipse(
A,
B,
ellipse.center,
ellipse.rx,
ellipse.ry,
ellipse.rotation
)An intersection is formatted as:
export type TLIntersection = {
didIntersect: boolean
message: string
points: number[][]
}Some intersection functions, such as intersectLineSegmentLineSegment, will return a single intersection. Others, such as intersectRectangleRectangle, will return an array of several intersections.
Community
Support
Need help? Please open an issue for support.
Discussion
Want to connect with other devs? Visit the Discord channel.
License
This project is licensed under MIT. If you're using the library in a commercial product, please consider becoming a sponsor.