mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Merge remote-tracking branch 'upstream/master' into snap-to-shape
This commit is contained in:
commit
ae65fbd570
490 changed files with 7224 additions and 5197 deletions
|
@ -17,5 +17,3 @@ With PNPM, similarly install the package with this command:
|
|||
```bash
|
||||
pnpm add @excalidraw/math
|
||||
```
|
||||
|
||||
## API
|
||||
|
|
|
@ -2,17 +2,18 @@
|
|||
"name": "@excalidraw/math",
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"types": "./dist/types/math/index.d.ts",
|
||||
"types": "./dist/types/math/src/index.d.ts",
|
||||
"main": "./dist/prod/index.js",
|
||||
"module": "./dist/prod/index.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/types/math/src/index.d.ts",
|
||||
"development": "./dist/dev/index.js",
|
||||
"production": "./dist/prod/index.js",
|
||||
"default": "./dist/prod/index.js"
|
||||
},
|
||||
"./*": {
|
||||
"types": "./../math/dist/types/math/*"
|
||||
"types": "./../math/dist/types/math/src/*.d.ts"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
|
@ -54,6 +55,6 @@
|
|||
"repository": "https://github.com/excalidraw/excalidraw",
|
||||
"scripts": {
|
||||
"gen:types": "rm -rf types && tsc",
|
||||
"build:esm": "rm -rf dist && node ../../scripts/buildMath.js && yarn gen:types"
|
||||
"build:esm": "rm -rf dist && node ../../scripts/buildBase.js && yarn gen:types"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { PRECISION } from "./utils";
|
||||
|
||||
import type {
|
||||
Degrees,
|
||||
GlobalPoint,
|
||||
|
@ -5,7 +7,6 @@ import type {
|
|||
PolarCoords,
|
||||
Radians,
|
||||
} from "./types";
|
||||
import { PRECISION } from "./utils";
|
||||
|
||||
// TODO: Simplify with modulo and fix for angles beyond 4*Math.PI and - 4*Math.PI
|
||||
export const normalizeRadians = (angle: Radians): Radians => {
|
|
@ -1,6 +1,8 @@
|
|||
import type { Bounds } from "../excalidraw/element/bounds";
|
||||
import type { Bounds } from "@excalidraw/element/bounds";
|
||||
|
||||
import { isPoint, pointDistance, pointFrom } from "./point";
|
||||
import { rectangle, rectangleIntersectLineSegment } from "./rectangle";
|
||||
|
||||
import type { Curve, GlobalPoint, LineSegment, LocalPoint } from "./types";
|
||||
|
||||
/**
|
|
@ -4,13 +4,6 @@ import {
|
|||
pointFromVector,
|
||||
pointsEqual,
|
||||
} from "./point";
|
||||
import type {
|
||||
Ellipse,
|
||||
GlobalPoint,
|
||||
Line,
|
||||
LineSegment,
|
||||
LocalPoint,
|
||||
} from "./types";
|
||||
import { PRECISION } from "./utils";
|
||||
import {
|
||||
vector,
|
||||
|
@ -20,6 +13,14 @@ import {
|
|||
vectorScale,
|
||||
} from "./vector";
|
||||
|
||||
import type {
|
||||
Ellipse,
|
||||
GlobalPoint,
|
||||
Line,
|
||||
LineSegment,
|
||||
LocalPoint,
|
||||
} from "./types";
|
||||
|
||||
/**
|
||||
* Construct an Ellipse object from the parameters
|
||||
*
|
|
@ -1,4 +1,5 @@
|
|||
import { pointFrom } from "./point";
|
||||
|
||||
import type { GlobalPoint, Line, LocalPoint } from "./types";
|
||||
|
||||
/**
|
|
@ -1,4 +1,7 @@
|
|||
import { degreesToRadians, radiansToDegrees } from "./angle";
|
||||
import { PRECISION } from "./utils";
|
||||
import { vectorDot, vectorFromPoint, vectorScale } from "./vector";
|
||||
|
||||
import type {
|
||||
LocalPoint,
|
||||
GlobalPoint,
|
||||
|
@ -6,8 +9,6 @@ import type {
|
|||
Degrees,
|
||||
Vector,
|
||||
} from "./types";
|
||||
import { PRECISION } from "./utils";
|
||||
import { vectorDot, vectorFromPoint, vectorScale } from "./vector";
|
||||
|
||||
/**
|
||||
* Create a properly typed Point instance from the X and Y coordinates.
|
||||
|
@ -96,7 +97,7 @@ export function pointsEqual<Point extends GlobalPoint | LocalPoint>(
|
|||
}
|
||||
|
||||
/**
|
||||
* Roate a point by [angle] radians.
|
||||
* Rotate a point by [angle] radians.
|
||||
*
|
||||
* @param point The point to rotate
|
||||
* @param center The point to rotate around, the center point
|
||||
|
@ -115,7 +116,7 @@ export function pointRotateRads<Point extends GlobalPoint | LocalPoint>(
|
|||
}
|
||||
|
||||
/**
|
||||
* Roate a point by [angle] degree.
|
||||
* Rotate a point by [angle] degree.
|
||||
*
|
||||
* @param point The point to rotate
|
||||
* @param center The point to rotate around, the center point
|
|
@ -1,8 +1,9 @@
|
|||
import { pointsEqual } from "./point";
|
||||
import { lineSegment, pointOnLineSegment } from "./segment";
|
||||
import type { GlobalPoint, LocalPoint, Polygon } from "./types";
|
||||
import { PRECISION } from "./utils";
|
||||
|
||||
import type { GlobalPoint, LocalPoint, Polygon } from "./types";
|
||||
|
||||
export function polygon<Point extends GlobalPoint | LocalPoint>(
|
||||
...points: Point[]
|
||||
) {
|
|
@ -1,4 +1,5 @@
|
|||
import { toBrandedType } from "@excalidraw/excalidraw/utils";
|
||||
import { toBrandedType } from "@excalidraw/common";
|
||||
|
||||
import type { InclusiveRange } from "./types";
|
||||
|
||||
/**
|
|
@ -1,5 +1,6 @@
|
|||
import { pointFrom } from "./point";
|
||||
import { lineSegment, lineSegmentIntersectionPoints } from "./segment";
|
||||
|
||||
import type { GlobalPoint, LineSegment, LocalPoint, Rectangle } from "./types";
|
||||
|
||||
export function rectangle<P extends GlobalPoint | LocalPoint>(
|
|
@ -5,7 +5,6 @@ import {
|
|||
pointFromVector,
|
||||
pointRotateRads,
|
||||
} from "./point";
|
||||
import type { GlobalPoint, LineSegment, LocalPoint, Radians } from "./types";
|
||||
import { PRECISION } from "./utils";
|
||||
import {
|
||||
vectorAdd,
|
||||
|
@ -15,6 +14,8 @@ import {
|
|||
vectorSubtract,
|
||||
} from "./vector";
|
||||
|
||||
import type { GlobalPoint, LineSegment, LocalPoint, Radians } from "./types";
|
||||
|
||||
/**
|
||||
* Create a line segment from two points.
|
||||
*
|
|
@ -1,12 +1,13 @@
|
|||
import "../utils/test-utils";
|
||||
import "@excalidraw/utils/test-utils";
|
||||
|
||||
import {
|
||||
curve,
|
||||
curveClosestPoint,
|
||||
curveIntersectLineSegment,
|
||||
curvePointDistance,
|
||||
} from "./curve";
|
||||
import { pointFrom } from "./point";
|
||||
import { lineSegment } from "./segment";
|
||||
} from "../src/curve";
|
||||
import { pointFrom } from "../src/point";
|
||||
import { lineSegment } from "../src/segment";
|
||||
|
||||
describe("Math curve", () => {
|
||||
describe("line segment intersection", () => {
|
|
@ -4,11 +4,12 @@ import {
|
|||
ellipseIncludesPoint,
|
||||
ellipseTouchesPoint,
|
||||
ellipseLineIntersectionPoints,
|
||||
} from "./ellipse";
|
||||
import { line } from "./line";
|
||||
import { pointFrom } from "./point";
|
||||
import { lineSegment } from "./segment";
|
||||
import type { Ellipse, GlobalPoint } from "./types";
|
||||
} from "../src/ellipse";
|
||||
import { line } from "../src/line";
|
||||
import { pointFrom } from "../src/point";
|
||||
import { lineSegment } from "../src/segment";
|
||||
|
||||
import type { Ellipse, GlobalPoint } from "../src/types";
|
||||
|
||||
describe("point and ellipse", () => {
|
||||
it("point on ellipse", () => {
|
|
@ -1,5 +1,5 @@
|
|||
import { line, linesIntersectAt } from "./line";
|
||||
import { pointFrom } from "./point";
|
||||
import { line, linesIntersectAt } from "../src/line";
|
||||
import { pointFrom } from "../src/point";
|
||||
|
||||
describe("line-line intersections", () => {
|
||||
it("should correctly detect intersection at origin", () => {
|
|
@ -1,5 +1,6 @@
|
|||
import { pointFrom, pointRotateRads } from "./point";
|
||||
import type { Radians } from "./types";
|
||||
import { pointFrom, pointRotateRads } from "../src/point";
|
||||
|
||||
import type { Radians } from "../src/types";
|
||||
|
||||
describe("rotate", () => {
|
||||
it("should rotate over (x2, y2) and return the rotated coordinates for (x1, y1)", () => {
|
|
@ -1,4 +1,4 @@
|
|||
import { rangeInclusive, rangeIntersection, rangesOverlap } from "./range";
|
||||
import { rangeInclusive, rangeIntersection, rangesOverlap } from "../src/range";
|
||||
|
||||
describe("range overlap", () => {
|
||||
const range1_4 = rangeInclusive(1, 4);
|
|
@ -1,5 +1,5 @@
|
|||
import { pointFrom } from "./point";
|
||||
import { lineSegment, lineSegmentIntersectionPoints } from "./segment";
|
||||
import { pointFrom } from "../src/point";
|
||||
import { lineSegment, lineSegmentIntersectionPoints } from "../src/segment";
|
||||
|
||||
describe("line-segment intersections", () => {
|
||||
it("should correctly detect intersection", () => {
|
|
@ -1,4 +1,4 @@
|
|||
import { isVector } from ".";
|
||||
import { isVector } from "../src/vector";
|
||||
|
||||
describe("Vector", () => {
|
||||
test("isVector", () => {
|
|
@ -1,24 +1,8 @@
|
|||
{
|
||||
"extends": "../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist/types",
|
||||
"target": "ESNext",
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"declaration": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"resolveJsonModule": true,
|
||||
"jsx": "react-jsx",
|
||||
"emitDeclarationOnly": true,
|
||||
"paths": {
|
||||
"@excalidraw/excalidraw": ["../excalidraw/index.tsx"],
|
||||
"@excalidraw/utils": ["../utils/index.ts"],
|
||||
"@excalidraw/math": ["../math/index.ts"],
|
||||
"@excalidraw/excalidraw/*": ["../excalidraw/*"],
|
||||
"@excalidraw/utils/*": ["../utils/*"],
|
||||
"@excalidraw/math/*": ["../math/*"]
|
||||
}
|
||||
"outDir": "./dist/types"
|
||||
},
|
||||
"include": ["src/**/*", "global.d.ts"],
|
||||
"exclude": ["**/*.test.*", "tests", "types", "examples", "dist"]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue