kfb-view 3.1.1 → 3.1.3

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kfb-view",
3
3
  "description": "一个在线kfb的阅片软件",
4
- "version": "3.1.1",
4
+ "version": "3.1.3",
5
5
  "author": "qifeng.fan <qifeng.fan@hzztai.com>",
6
6
  "license": "MIT",
7
7
  "main": "lib/kfb-view.js",
@@ -22,11 +22,9 @@
22
22
  "lint": "eslint --ext .js src"
23
23
  },
24
24
  "dependencies": {
25
- "@babel/polyfill": "^7.0.0",
26
- "axios": "^0.19.2",
27
- "openseadragon": "^4.1.0"
28
25
  },
29
26
  "devDependencies": {
27
+ "axios": "^1.6.5",
30
28
  "@babel/core": "^7.0.0",
31
29
  "@babel/plugin-proposal-class-properties": "^7.0.0",
32
30
  "@babel/plugin-proposal-decorators": "^7.0.0",
@@ -1,8 +1,15 @@
1
1
  import {EventEmitter} from '../../util/event-emitter';
2
2
  import {Thumb} from '../../tool/Thumb';
3
3
  import {
4
- acreage, getAngle, perimeter, pointsToRegion,
5
- getRectPoint, isPointInEllipse, isPointInMatrix, isPointInPolygon,
4
+ acreage,
5
+ getAngle,
6
+ perimeter,
7
+ pointsToRegion,
8
+ getRectPoint,
9
+ isPointInEllipse,
10
+ isPointInMatrix,
11
+ isPointInPolygon,
12
+ calculatePolygonArea,
6
13
  } from '../../util/calculate';
7
14
  import {Point, Rect} from '../../plugin/openseadragon/openseadragon';
8
15
  import {
@@ -253,8 +260,8 @@ export class ViewerCommon extends EventEmitter {
253
260
  }
254
261
  break;
255
262
  case ELLIPSE: {
256
- const w = Math.abs(endPoint.x - startPoint.x);
257
- const h = Math.abs(endPoint.y - startPoint.y);
263
+ const w = Math.abs(endPoint.x - startPoint.x) / 2;
264
+ const h = Math.abs(endPoint.y - startPoint.y) / 2;
258
265
  const pt = perimeter(ELLIPSE, startPoint, endPoint,
259
266
  this.options.imageCapRes);
260
267
  const ac = acreage(ELLIPSE, startPoint, endPoint,
@@ -316,7 +323,9 @@ export class ViewerCommon extends EventEmitter {
316
323
  angle: 0,
317
324
  texts: [
318
325
  `周长:${(pt * this.options.imageCapRes).toFixed(
319
- 2)}${this.options.unit}`],
326
+ 2)}${this.options.unit}`,
327
+ `面积:${calculatePolygonArea(points,
328
+ this.options.imageCapRes).toFixed(2)}${this.options.unit}²`],
320
329
  };
321
330
  }
322
331
  break;
@@ -395,6 +395,32 @@ function acreage(type, startPoint, endPoint, imageCapRes = 1) {
395
395
  return ag;
396
396
  }
397
397
 
398
+ function calculatePolygonArea(points, ratio) {
399
+ const numVertices = points.length;
400
+
401
+ if (numVertices < 3) {
402
+ // 无法构成多边形,返回0
403
+ return 0;
404
+ }
405
+
406
+ let area = 0;
407
+
408
+ for (let i = 0; i < numVertices; i++) {
409
+ const currentVertex = points[i];
410
+ const nextVertex = points[(i + 1) % numVertices]; // 下一个顶点
411
+
412
+ const x1 = currentVertex.x * ratio;
413
+ const y1 = currentVertex.y * ratio;
414
+ const x2 = nextVertex.x * ratio;
415
+ const y2 = nextVertex.y * ratio;
416
+
417
+ area += (x1 * y2 - x2 * y1); // 通过叉乘计算每个三角形的面积
418
+ }
419
+
420
+ // 最终的面积可能为负数,取绝对值
421
+ return Math.abs(area / 2);
422
+ }
423
+
398
424
  /**
399
425
  * 几何图形的周长
400
426
  * @param {string} type
@@ -414,8 +440,8 @@ function perimeter(type, startPoint, endPoint, imageCapRes = 1) {
414
440
  pt = (distX + distY) * 2;
415
441
  }
416
442
  if (type === 'Ellipse') {
417
- const a = distX >= distY ? distX : distY;
418
- const b = distX >= distY ? distY : distX;
443
+ const a = (distX >= distY ? distX : distY) / 2;
444
+ const b = (distX >= distY ? distY : distX) / 2;
419
445
  pt = 4 * (a - b) + 2 * Math.PI * b;
420
446
  }
421
447
  /* if (type === 'polygon') {
@@ -440,4 +466,5 @@ export {
440
466
  getPoint,
441
467
  getAngle,
442
468
  getDistance,
469
+ calculatePolygonArea,
443
470
  };