Skip to content

Commit ad556a7

Browse files
committed
lazy compute endpoints
1 parent abe78b6 commit ad556a7

File tree

11 files changed

+89
-317
lines changed

11 files changed

+89
-317
lines changed

rotateResize.js

Lines changed: 89 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,91 @@
1-
import EndPoints from './src/EndPoints'
1+
export const EndPoints = class EndPoints {
2+
constructor(rect) {
3+
this.rect = rect
4+
this._lt = null
5+
this._rt = null
6+
this._rb = null
7+
this._lb = null
8+
this._ct = null
9+
this._cb = null
10+
this._rm = null
11+
this._lm = null
12+
this._center = null
13+
}
14+
15+
get center() {
16+
if (!this._center) {
17+
this._center = rectCenter(this.rect)
18+
}
19+
return this._center
20+
}
21+
22+
get lt () {
23+
if (!this._lt) {
24+
const { x, y, r } = this.rect
25+
this._lt = rotatePositionRelatively({ x, y }, this.center, r)
26+
}
27+
return this._lt
28+
}
29+
30+
get rt() {
31+
if (!this._rt) {
32+
const { x, y, w, r } = this.rect
33+
this._rt = rotatePositionRelatively(
34+
{ x: x + w, y },
35+
this.center,
36+
r
37+
)
38+
}
39+
return this._rt
40+
}
41+
42+
get rb() {
43+
if (!this._rb) {
44+
this._rb = symmetryPoint(this.lt, this.center)
45+
}
46+
return this._rb
47+
}
48+
49+
get lb() {
50+
if (!this._lb) {
51+
this._lb = symmetryPoint(this.rt, this.center)
52+
}
53+
return this._lb
54+
}
55+
56+
get ct() {
57+
if (!this._ct) {
58+
this._ct = centerPoint(this.lt, this.rt)
59+
}
60+
return this._ct
61+
}
62+
63+
get cb() {
64+
if (!this._cb) {
65+
this._cb = centerPoint(this.rb, this.lb)
66+
}
67+
return this._cb
68+
}
69+
70+
get rm() {
71+
if (!this._rm) {
72+
this._rm = centerPoint(this.rt, this.rb)
73+
}
74+
return this._rm
75+
}
76+
77+
get lm() {
78+
if (!this._lm) {
79+
this._lm = centerPoint(this.lt, this.lb)
80+
}
81+
return this._lm
82+
}
83+
}
84+
85+
export const symmetryPoint = (start, center) => {
86+
const [x, y] = ['x', 'y'].map(k => start[k] + 2 * (center[k] - start[k]))
87+
return { x, y }
88+
}
289

390
const PRECISION = 1e-5
491

@@ -38,16 +125,6 @@ export const computeRectWithCrossPoints = (pa, pb, angle) => {
38125
}
39126
}
40127

41-
/**
42-
* 返回 start 点相对于 center 点的对称点
43-
* @param {*} start
44-
* @param {*} center
45-
*/
46-
export const computeSymmetryPoint = (start, center) => {
47-
const [x, y] = ['x', 'y'].map(k => start[k] + 2 * (center[k] - start[k]))
48-
return { x, y }
49-
}
50-
51128
/**
52129
* 根据一条线段(由 pinnedPoints 两点确定),拖拽点坐标(dragPoint),以及倾斜角度(angle)返回一个确定的矩形
53130
* @param {Object[]} pinnedPoints
@@ -410,7 +487,7 @@ const resizeRect = (mouseStart, mouseEnd, adjustType, rectStart, fixedRatio) =>
410487
* @param {Position} mouseStart
411488
* @param {Position} mouseEnd
412489
* @param {String} adjustType: 'rotate'|'move'|'lt'|'rt'|'ct'|'lb'|'rb'|'cb'|'lm'|'rm'
413-
* @param {Rect} rectStart
490+
* @param {Rect} rectStart: { x: Number, y: Number, w: Number, h: Number, r: Number }
414491
* @param {Boolean} fixedRatio
415492
*/
416493
export default (

src/EndPoints.js

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/angleDegrees.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/centerPoint.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/computeRotation.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/index.js

Lines changed: 0 additions & 131 deletions
This file was deleted.

src/moveRect.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/rectCenter.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)