light-h5-core-lib 2.5.5 → 2.6.5

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/LightCore.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UniqueIDUtil = exports.StringUtil = exports.RandomNumUtil = exports.FloatDigitUtil = exports.DateUtil = exports.BitUtil = exports.BaseSingleton = exports.PoolObj = void 0;
3
+ exports.BeizerUtil = exports.UniqueIDUtil = exports.StringUtil = exports.RandomNumUtil = exports.FloatDigitUtil = exports.DateUtil = exports.BitUtil = exports.BaseSingleton = exports.PoolObj = void 0;
4
4
  var PoolObj_1 = require("./pool/PoolObj");
5
5
  Object.defineProperty(exports, "PoolObj", { enumerable: true, get: function () { return PoolObj_1.PoolObj; } });
6
6
  var BaseSingleton_1 = require("./common/base/BaseSingleton");
@@ -17,14 +17,8 @@ var StringUtil_1 = require("./common/util/StringUtil");
17
17
  Object.defineProperty(exports, "StringUtil", { enumerable: true, get: function () { return StringUtil_1.StringUtil; } });
18
18
  var UniqueIDUtil_1 = require("./common/util/UniqueIDUtil");
19
19
  Object.defineProperty(exports, "UniqueIDUtil", { enumerable: true, get: function () { return UniqueIDUtil_1.UniqueIDUtil; } });
20
- // module.exports.PoolObj = PoolObj;
21
- // module.exports.BaseSingleton = BaseSingleton;
22
- // module.exports.BitUtil = BitUtil;
23
- // module.exports.DateUtil = DateUtil;
24
- // module.exports.FloatDigitUtil = FloatDigitUtil;
25
- // module.exports.RandomNumUtil = RandomNumUtil;
26
- // module.exports.StringUtil = StringUtil;
27
- // module.exports.UniqueIDUtil = UniqueIDUtil;
20
+ var BeizerUtil_1 = require("./common/util/BeizerUtil");
21
+ Object.defineProperty(exports, "BeizerUtil", { enumerable: true, get: function () { return BeizerUtil_1.BeizerUtil; } });
28
22
  module.exports = {
29
23
  PoolObj: PoolObj_1.PoolObj,
30
24
  BaseSingleton: BaseSingleton_1.BaseSingleton,
@@ -34,4 +28,5 @@ module.exports = {
34
28
  RandomNumUtil: RandomNumUtil_1.RandomNumUtil,
35
29
  StringUtil: StringUtil_1.StringUtil,
36
30
  UniqueIDUtil: UniqueIDUtil_1.UniqueIDUtil,
31
+ BeizerUtil: BeizerUtil_1.BeizerUtil,
37
32
  };
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BeizerUtil = void 0;
4
+ /**
5
+ * 贝塞尔曲线运动
6
+ * @author Aonaufly
7
+ */
8
+ var BeizerUtil = /** @class */ (function () {
9
+ function BeizerUtil() {
10
+ }
11
+ //#region 获得当前坐标
12
+ /**
13
+ * 获得当前坐标
14
+ * @param timer 时间[0,1]
15
+ * @returns
16
+ */
17
+ BeizerUtil.getPosition = function (points, timer) {
18
+ var x = 0, y = 0;
19
+ var bezier;
20
+ for (var i = 0, n = points.length; i < n; i++) {
21
+ bezier =
22
+ Math.min(Math.pow(1 - timer, n - i - 1) * Math.pow(timer, i)) *
23
+ BeizerUtil.calculationC(i, n);
24
+ x += points[i].x * bezier;
25
+ y += points[i].y * bezier;
26
+ }
27
+ return { x: x, y: y };
28
+ };
29
+ //#endregion
30
+ //region 获得路线的长度
31
+ BeizerUtil.distance = function (p1, p2) {
32
+ var dx = p2.x - p1.x;
33
+ var dy = p2.y - p1.y;
34
+ return Math.sqrt(dx * dx + dy * dy);
35
+ };
36
+ /**
37
+ * 获得整个路线的长度
38
+ * @param precision 精确度(微积分方案)
39
+ */
40
+ BeizerUtil.getLength = function (points, precision) {
41
+ if (precision === void 0) { precision = 100; }
42
+ var length = 0;
43
+ var point1;
44
+ var point2;
45
+ for (var t = 0; t < 1; t += 1 / precision) {
46
+ point1 = BeizerUtil.getBezierPoint(points, t);
47
+ point2 = BeizerUtil.getBezierPoint(points, t + 1 / precision);
48
+ length += BeizerUtil.distance(point1, point2);
49
+ }
50
+ return length;
51
+ };
52
+ BeizerUtil.calculationC = function (i, n) {
53
+ return (BeizerUtil.factorial(n - 1) /
54
+ (BeizerUtil.factorial(i) * BeizerUtil.factorial(n - 1 - i)));
55
+ };
56
+ BeizerUtil.factorial = function (num) {
57
+ if (num < 0) {
58
+ return 1;
59
+ }
60
+ else if (num === 0 || num === 1) {
61
+ return 1;
62
+ }
63
+ else {
64
+ return num * BeizerUtil.factorial(num - 1);
65
+ }
66
+ };
67
+ BeizerUtil.getBezierPoint = function (points, t) {
68
+ if (points.length === 1) {
69
+ return points[0];
70
+ }
71
+ var nextPoints = [];
72
+ var x;
73
+ var y;
74
+ for (var i = 0; i < points.length - 1; i++) {
75
+ x = (1 - t) * points[i].x + t * points[i + 1].x;
76
+ y = (1 - t) * points[i].y + t * points[i + 1].y;
77
+ nextPoints.push({ x: x, y: y });
78
+ }
79
+ return BeizerUtil.getBezierPoint(nextPoints, t);
80
+ };
81
+ return BeizerUtil;
82
+ }());
83
+ exports.BeizerUtil = BeizerUtil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "light-h5-core-lib",
3
- "version": "2.5.5",
3
+ "version": "2.6.5",
4
4
  "description": "light core lib",
5
5
  "main": "./LightCore.js",
6
6
  "types": "./type/index.d.ts",
package/type/index.d.ts CHANGED
@@ -159,5 +159,35 @@ export declare class UniqueIDUtil {
159
159
  /**生成复合的Key值*/
160
160
  static getCompositeKey(key: string | number, uniqueId: string): string;
161
161
  }
162
+ /**
163
+ * 贝塞尔曲线运动
164
+ * @author Aonaufly
165
+ */
166
+ export declare class BeizerUtil {
167
+ /**
168
+ * 获得当前坐标
169
+ * @param timer 时间[0,1]
170
+ * @returns
171
+ */
172
+ static getPosition(points: {
173
+ x: number;
174
+ y: number;
175
+ }[], timer: number): {
176
+ x: number;
177
+ y: number;
178
+ };
179
+ private static calculationC;
180
+ private static factorial;
181
+ private static distance;
182
+ /**
183
+ * 获得整个路线的长度
184
+ * @param precision 精确度(微积分方案)
185
+ */
186
+ static getLength(points: {
187
+ x: number;
188
+ y: number;
189
+ }[], precision?: number): number;
190
+ private static getBezierPoint;
191
+ }
162
192
 
163
193
  export {};