|
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 | +} |
2 | 89 |
|
3 | 90 | const PRECISION = 1e-5 |
4 | 91 |
|
@@ -38,16 +125,6 @@ export const computeRectWithCrossPoints = (pa, pb, angle) => { |
38 | 125 | } |
39 | 126 | } |
40 | 127 |
|
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 | | - |
51 | 128 | /** |
52 | 129 | * 根据一条线段(由 pinnedPoints 两点确定),拖拽点坐标(dragPoint),以及倾斜角度(angle)返回一个确定的矩形 |
53 | 130 | * @param {Object[]} pinnedPoints |
@@ -410,7 +487,7 @@ const resizeRect = (mouseStart, mouseEnd, adjustType, rectStart, fixedRatio) => |
410 | 487 | * @param {Position} mouseStart |
411 | 488 | * @param {Position} mouseEnd |
412 | 489 | * @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 } |
414 | 491 | * @param {Boolean} fixedRatio |
415 | 492 | */ |
416 | 493 | export default ( |
|
0 commit comments