atr-components 0.2.308 → 0.2.309

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -330,46 +330,63 @@ class ToolsUtil {
330
330
  }
331
331
  return false;
332
332
  }
333
+ /**
334
+ *
335
+ * @param num1
336
+ * @param num2
337
+ * @param error 误差
338
+ */
339
+ static equalNum(num1, num2, error = 5) {
340
+ let num = num1 - num2;
341
+ return num < error && num > -error;
342
+ }
343
+ /**
344
+ * 坐标对比
345
+ * @param point1
346
+ * @param point2
347
+ * @param error
348
+ */
349
+ static equalPoint(point1, point2, error = 5) {
350
+ return ToolsUtil.equalNum(point1.x, point2.x, error) && ToolsUtil.equalNum(point1.y, point2.y, error);
351
+ }
333
352
  //判断点是否在线段上
334
- static checkInLine(startP, endP, a) {
353
+ /**
354
+ *
355
+ * @param startP
356
+ * @param endP
357
+ * @param a
358
+ * @param error 误差
359
+ */
360
+ static checkInLine(startP, endP, a, error = 5) {
335
361
  //点和端点重合
336
- if ((startP.x == endP.x && startP.y == endP.y)
337
- || (startP.x == a.x && startP.y == a.y)
338
- || (endP.x == a.x && endP.y == a.y)) {
362
+ if (ToolsUtil.equalPoint(startP, endP, error)
363
+ || ToolsUtil.equalPoint(startP, a)
364
+ || ToolsUtil.equalPoint(endP, a)) {
339
365
  return true;
340
366
  }
341
- if (startP.x == endP.x && endP.x != a.x) {
367
+ if (ToolsUtil.equalNum(startP.x, endP.x, error)
368
+ && !ToolsUtil.equalNum(startP.x, a.x, error)) {
342
369
  return false;
343
370
  }
344
- else if (startP.x == endP.x && endP.x == a.x) {
371
+ else if (ToolsUtil.equalNum(startP.x, endP.x, error)
372
+ && ToolsUtil.equalNum(startP.x, a.x, error)) {
345
373
  if (startP.y > endP.y) {
346
374
  return startP.y > a.y && endP.y < a.y;
347
375
  }
348
- return startP.y < a.y && endP.y < a.y;
376
+ return startP.y < a.y && endP.y > a.y;
349
377
  }
350
378
  //判断点在线段上
351
379
  //斜率是否一致
352
380
  let k1 = (endP.y - startP.y) / (endP.x - startP.x);
353
381
  let b = startP.y - k1 * startP.x;
354
- //y = kx + y1 - kx1
355
- //b = y1 - kx1
356
- let y = k1 * a.x + b, num = y - a.y;
357
- if (num > -5 && num < 5) {
382
+ let y = k1 * a.x + b;
383
+ if (ToolsUtil.equalNum(y, a.y, error)) {
358
384
  //5像素的误差
359
385
  let startLen = ToolsUtil.getLength(startP, a);
360
386
  let endLen = ToolsUtil.getLength(a, endP);
361
387
  let len = ToolsUtil.getLength(startP, endP);
362
388
  return len >= startLen && len >= endLen;
363
389
  }
364
- // let k2 = (a.y - startP.y) / (a.x - startP.x);
365
- // //Number.EPSILON是精度误差
366
- // if (Math.abs(k1 - k2) <= Number.EPSILON) {
367
- // //斜率一致,并且a在线段上
368
- // let startLen = ToolsUtil.getLength(startP, a)
369
- // let endLen = ToolsUtil.getLength(a, endP)
370
- // let leng = ToolsUtil.getLength(startP, endP)
371
- // return leng >= startLen && leng >= endLen
372
- // }
373
390
  return false;
374
391
  }
375
392
  /**
@@ -742,21 +759,21 @@ class ToolsUtil {
742
759
  return { 'maxHeight': ToolsUtil.windowHeight() - 200 + 'px', 'overflow-y': 'auto' };
743
760
  }
744
761
  static getLength(pointA, pointB) {
745
- pointA.x1 = pointA.x || pointA.x1;
746
- pointA.y1 = pointA.y || pointA.y1;
747
- pointB.y1 = pointB.y || pointB.y1;
748
- pointB.x1 = pointB.x || pointB.x1;
762
+ pointA.x1 = pointA.x || pointA.x1 || 0;
763
+ pointA.y1 = pointA.y || pointA.y1 || 0;
764
+ pointB.y1 = pointB.y || pointB.y1 || 0;
765
+ pointB.x1 = pointB.x || pointB.x1 || 0;
749
766
  var lengthAB = Math.sqrt(Math.pow(pointA.x1 - pointB.x1, 2) +
750
767
  Math.pow(pointA.y1 - pointB.y1, 2));
751
768
  return lengthAB;
752
769
  }
753
770
  static getRotateNum(pointB, pointC, pointA) {
754
- pointA.x1 = pointA.x || pointA.x1;
755
- pointA.y1 = pointA.y || pointA.y1;
756
- pointB.x1 = pointB.y || pointB.x1;
757
- pointB.y1 = pointB.x || pointB.x1;
758
- pointC.x1 = pointC.y || pointC.x1;
759
- pointC.y1 = pointC.x || pointC.x1;
771
+ pointA.x1 = pointA.x || pointA.x1 || 0;
772
+ pointA.y1 = pointA.y || pointA.y1 || 0;
773
+ pointB.x1 = pointB.y || pointB.x1 || 0;
774
+ pointB.y1 = pointB.x || pointB.x1 || 0;
775
+ pointC.x1 = pointC.y || pointC.x1 || 0;
776
+ pointC.y1 = pointC.x || pointC.x1 || 0;
760
777
  //ABC中心点,起始点,终点
761
778
  let AB = {};
762
779
  let AC = {};