@xort/cga 0.0.78 → 0.0.81

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.
Files changed (51) hide show
  1. package/dist/IKanimation/Bone.js +1 -3
  2. package/dist/IKanimation/CCDSolver.js +2 -2
  3. package/dist/IKanimation/constaint/hinge.js +1 -3
  4. package/dist/IKanimation/constaint/slider.js +1 -3
  5. package/dist/alg/common.js +2 -2
  6. package/dist/alg/extrude.js +54 -56
  7. package/dist/alg/pointset.js +5 -5
  8. package/dist/alg/trianglution.js +10 -12
  9. package/dist/app.js +10 -14
  10. package/dist/diamondMaterialShader.js +2 -6
  11. package/dist/effect/breath-light.js +1 -3
  12. package/dist/extends/geometryaid.js +7 -7
  13. package/dist/index.js +2 -6
  14. package/dist/math/Color.d.ts +5 -2
  15. package/dist/math/Color.js +77 -17
  16. package/dist/math/Euler.js +10 -12
  17. package/dist/math/HVec3.js +1 -3
  18. package/dist/math/Mat3.js +1 -1
  19. package/dist/math/Mat4.js +6 -6
  20. package/dist/math/Quat.js +2 -4
  21. package/dist/math/Vec.js +1 -3
  22. package/dist/math/Vec2.js +1 -3
  23. package/dist/math/Vec3.js +5 -7
  24. package/dist/math/Vec4.js +1 -3
  25. package/dist/math/vector.js +7 -9
  26. package/dist/render/buffer-attribute.js +28 -12
  27. package/dist/render/eventhandler.d.ts +1 -1
  28. package/dist/render/eventhandler.js +7 -9
  29. package/dist/render/geometry.js +2 -2
  30. package/dist/render/mesh.js +9 -11
  31. package/dist/render/thing.js +8 -10
  32. package/dist/render/types.js +1 -2
  33. package/dist/struct/3d/Box.js +3 -3
  34. package/dist/struct/3d/Capsule.js +1 -3
  35. package/dist/struct/3d/Circle.js +2 -2
  36. package/dist/struct/3d/Disk.js +1 -1
  37. package/dist/struct/3d/Line.js +4 -4
  38. package/dist/struct/3d/Path.js +11 -13
  39. package/dist/struct/3d/Plane.js +10 -12
  40. package/dist/struct/3d/Point.js +1 -3
  41. package/dist/struct/3d/Polygon.js +1 -3
  42. package/dist/struct/3d/Polyline.js +1 -3
  43. package/dist/struct/3d/Rectangle.js +1 -3
  44. package/dist/struct/3d/Segment.js +7 -9
  45. package/dist/struct/3d/Shape.js +1 -3
  46. package/dist/struct/3d/Sphere.js +1 -1
  47. package/dist/struct/3d/Triangle.js +1 -3
  48. package/dist/struct/data/ArrayList.js +9 -11
  49. package/dist/struct/data/ArrayObject.js +1 -3
  50. package/package.json +1 -1
  51. package/src/math/Color.ts +89 -20
@@ -3,12 +3,10 @@ var __extends = (this && this.__extends) || (function () {
3
3
  var extendStatics = function (d, b) {
4
4
  extendStatics = Object.setPrototypeOf ||
5
5
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
10
  extendStatics(d, b);
13
11
  function __() { this.constructor = d; }
14
12
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -25,7 +23,7 @@ var Thing = /** @class */ (function (_super) {
25
23
  _this.cache = {};
26
24
  _this._useData = {};
27
25
  opts = opts || {};
28
- _this.uuid = (0, uuid_1.v4)();
26
+ _this.uuid = uuid_1.v4();
29
27
  _this.id = _this.uuid;
30
28
  _this.name = opts.name || "未命名";
31
29
  _this.alias = opts.alias;
@@ -153,11 +151,11 @@ var Thing = /** @class */ (function (_super) {
153
151
  return;
154
152
  Object.defineProperty(bindObject, name, {
155
153
  get: function () {
156
- return bindObject["_".concat(name)];
154
+ return bindObject["_" + name];
157
155
  },
158
156
  set: function (value) {
159
- var oldValue = bindObject["_".concat(name)];
160
- bindObject["_".concat(name)] = value;
157
+ var oldValue = bindObject["_" + name];
158
+ bindObject["_" + name] = value;
161
159
  bindObject.fire('set', name, oldValue, value);
162
160
  },
163
161
  configurable: true
@@ -177,11 +175,11 @@ function buildAccessor(name, bindObject) {
177
175
  return;
178
176
  Object.defineProperty(bindObject, name, {
179
177
  get: function () {
180
- return bindObject["_".concat(name)];
178
+ return bindObject["_" + name];
181
179
  },
182
180
  set: function (value) {
183
- var oldValue = bindObject["_".concat(name)];
184
- bindObject["_".concat(name)] = value;
181
+ var oldValue = bindObject["_" + name];
182
+ bindObject["_" + name] = value;
185
183
  bindObject.fire('set', name, oldValue, value);
186
184
  },
187
185
  configurable: true
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isBufferArray = void 0;
4
- var isBufferArray = function (obj) {
4
+ exports.isBufferArray = function (obj) {
5
5
  var types = ['Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array', 'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array', 'Float64Array'];
6
6
  return types.indexOf(obj.constructor.name) > -1;
7
7
  };
8
- exports.isBufferArray = isBufferArray;
@@ -5,9 +5,9 @@ var Vec3_1 = require("../../math/Vec3");
5
5
  var _vector = new Vec3_1.Vec3();
6
6
  var Box = /** @class */ (function () {
7
7
  function Box(min, max) {
8
- if (min === void 0) { min = (0, Vec3_1.v3)(Infinity, Infinity, Infinity); }
9
- if (max === void 0) { max = (0, Vec3_1.v3)(-Infinity, -Infinity, -Infinity); }
10
- this._center = (0, Vec3_1.v3)();
8
+ if (min === void 0) { min = Vec3_1.v3(Infinity, Infinity, Infinity); }
9
+ if (max === void 0) { max = Vec3_1.v3(-Infinity, -Infinity, -Infinity); }
10
+ this._center = Vec3_1.v3();
11
11
  this.min = min;
12
12
  this.max = max;
13
13
  // if (points) {
@@ -3,12 +3,10 @@ var __extends = (this && this.__extends) || (function () {
3
3
  var extendStatics = function (d, b) {
4
4
  extendStatics = Object.setPrototypeOf ||
5
5
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
10
  extendStatics(d, b);
13
11
  function __() { this.constructor = d; }
14
12
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -35,7 +35,7 @@ var Circle = /** @class */ (function () {
35
35
  Circle.prototype.arc1 = function (fixp0, fixp1, movep, normal) {
36
36
  this.setFrom3Points(fixp0, fixp1, movep);
37
37
  this.startAngle = 0;
38
- this.endAngle = (0, common_1.angle)(fixp0.clone().sub(this.center).normalize(), fixp1.clone().sub(this.center).normalize(), this.normal || normal);
38
+ this.endAngle = common_1.angle(fixp0.clone().sub(this.center).normalize(), fixp1.clone().sub(this.center).normalize(), this.normal || normal);
39
39
  };
40
40
  /**
41
41
  * 全两个点确定半径,后面点确定 弧度 ,只需要检测鼠标移动时鼠标是否跨过第一条半径即可确定顺逆时针
@@ -49,7 +49,7 @@ var Circle = /** @class */ (function () {
49
49
  this.center.copy(center);
50
50
  var v2 = movep.clone().sub(center);
51
51
  var v1 = fixp1.clone().sub(center);
52
- var jd = (0, common_1.angle)(v1, v2);
52
+ var jd = common_1.angle(v1, v2);
53
53
  };
54
54
  Circle.prototype.setFrom3Points = function (p0, p1, p2, normal) {
55
55
  // if (pointsCollinear(p0, p1, p2))
@@ -5,7 +5,7 @@ var Vec3_1 = require("../../math/Vec3");
5
5
  var Disk = /** @class */ (function () {
6
6
  function Disk(center, radius, normal) {
7
7
  if (normal === void 0) { normal = Vec3_1.Vec3.UnitY; }
8
- this.center = center || (0, Vec3_1.v3)();
8
+ this.center = center || Vec3_1.v3();
9
9
  this.normal = normal;
10
10
  this.radius = radius || 0;
11
11
  this.w = this.normal.dot(center);
@@ -8,8 +8,8 @@ var _v1 = new Vec3_1.Vec3;
8
8
  ;
9
9
  var Line = /** @class */ (function () {
10
10
  function Line(origin, end) {
11
- if (origin === void 0) { origin = (0, Vec3_1.v3)(); }
12
- if (end === void 0) { end = (0, Vec3_1.v3)(); }
11
+ if (origin === void 0) { origin = Vec3_1.v3(); }
12
+ if (end === void 0) { end = Vec3_1.v3(); }
13
13
  this.origin = origin;
14
14
  this.end = end;
15
15
  this.direction = this.end
@@ -192,10 +192,10 @@ var Line = /** @class */ (function () {
192
192
  if (robust === void 0) { robust = false; }
193
193
  if (numInputs === 1) {
194
194
  if (Math.abs(v[0][0]) > Math.abs(v[0][1])) {
195
- v[1] = (0, Vec3_1.v3)(-v[0].z, 0, +v[0].x);
195
+ v[1] = Vec3_1.v3(-v[0].z, 0, +v[0].x);
196
196
  }
197
197
  else {
198
- v[1] = (0, Vec3_1.v3)(0, +v[0].z, -v[0].y);
198
+ v[1] = Vec3_1.v3(0, +v[0].z, -v[0].y);
199
199
  }
200
200
  ;
201
201
  numInputs = 2;
@@ -10,12 +10,10 @@ var __extends = (this && this.__extends) || (function () {
10
10
  var extendStatics = function (d, b) {
11
11
  extendStatics = Object.setPrototypeOf ||
12
12
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
13
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
13
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
14
14
  return extendStatics(d, b);
15
15
  };
16
16
  return function (d, b) {
17
- if (typeof b !== "function" && b !== null)
18
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
19
17
  extendStatics(d, b);
20
18
  function __() { this.constructor = d; }
21
19
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -75,15 +73,15 @@ var Path = /** @class */ (function (_super) {
75
73
  var normal = new Vec3_1.Vec3();
76
74
  normal.crossVecs(d1, d2).normalize();
77
75
  this.get(i).normal = normal;
78
- var bdir = (0, Vec3_1.v3)().addVecs(d1, d2).normalize();
76
+ var bdir = Vec3_1.v3().addVecs(d1, d2).normalize();
79
77
  this.get(i).bdirection = bdir;
80
- this.get(i).bnormal = (0, Vec3_1.v3)().crossVecs(bdir, normal).normalize();
78
+ this.get(i).bnormal = Vec3_1.v3().crossVecs(bdir, normal).normalize();
81
79
  // }
82
80
  }
83
81
  if (!this._closed) { //不闭合路径 最后一个点没有
84
- this.get(-1).bdirection = (0, Vec3_1.v3)();
85
- this.get(-1).normal = (0, Vec3_1.v3)();
86
- this.get(-1).bnormal = (0, Vec3_1.v3)();
82
+ this.get(-1).bdirection = Vec3_1.v3();
83
+ this.get(-1).normal = Vec3_1.v3();
84
+ this.get(-1).bnormal = Vec3_1.v3();
87
85
  }
88
86
  if (!this._closed) {
89
87
  // 不闭合的情况下怎么样去计算端点的up和normal
@@ -118,10 +116,10 @@ var Path = /** @class */ (function (_super) {
118
116
  configurable: true
119
117
  });
120
118
  Path.prototype.applyMat4 = function (mat4) {
121
- (0, pointset_1.applyMat4)(this._array, mat4);
119
+ pointset_1.applyMat4(this._array, mat4);
122
120
  };
123
121
  Path.prototype.scale = function (x, y, z) {
124
- (0, common_1.scale)(this._array, (0, Vec3_1.v3)(x, y, z), true);
122
+ common_1.scale(this._array, Vec3_1.v3(x, y, z), true);
125
123
  };
126
124
  /**
127
125
  * 截取一段从from到to的path
@@ -159,7 +157,7 @@ var Path = /** @class */ (function (_super) {
159
157
  Path.prototype.getPointByDistance = function (arg_distance, left, right) {
160
158
  if (left === void 0) { left = 0; }
161
159
  if (right === void 0) { right = this.length - 1; }
162
- var distance = (0, Math_1.clamp)(arg_distance, 0, this.get(-1).tlen);
160
+ var distance = Math_1.clamp(arg_distance, 0, this.get(-1).tlen);
163
161
  if (distance !== arg_distance)
164
162
  return null;
165
163
  if (right - left === 1) {
@@ -188,7 +186,7 @@ var Path = /** @class */ (function (_super) {
188
186
  Path.prototype.getPointByDistancePure = function (arg_distance, left, right) {
189
187
  if (left === void 0) { left = 0; }
190
188
  if (right === void 0) { right = this.length - 1; }
191
- var distance = (0, Math_1.clamp)(arg_distance, 0, this.get(-1).tlen);
189
+ var distance = Math_1.clamp(arg_distance, 0, this.get(-1).tlen);
192
190
  if (distance !== arg_distance)
193
191
  return null;
194
192
  if (right - left === 1) {
@@ -296,7 +294,7 @@ var Path = /** @class */ (function (_super) {
296
294
  res.push(mileages);
297
295
  }
298
296
  if (normalize) {
299
- var tl = (0, types_1.isDefined)(totalMileage) ? totalMileage : this.totalMileages(ps);
297
+ var tl = types_1.isDefined(totalMileage) ? totalMileage : this.totalMileages(ps);
300
298
  for (var i = 0, len = ps.length; i < len; i++) {
301
299
  res[i] /= tl;
302
300
  }
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
- if (ar || !(i in from)) {
5
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
- ar[i] = from[i];
7
- }
8
- }
9
- return to.concat(ar || Array.prototype.slice.call(from));
2
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
3
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
4
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
5
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
6
+ r[k] = a[j];
7
+ return r;
10
8
  };
11
9
  Object.defineProperty(exports, "__esModule", { value: true });
12
10
  exports.Plane = void 0;
@@ -70,9 +68,9 @@ var Plane = /** @class */ (function () {
70
68
  */
71
69
  Plane.prototype.frontback = function (point) {
72
70
  var value = this.normal.dot(point);
73
- if ((0, Math_1.approximateEqual)(value, 0))
71
+ if (Math_1.approximateEqual(value, 0))
74
72
  return 0;
75
- return (0, Math_1.sign)(this.normal.dot(point));
73
+ return Math_1.sign(this.normal.dot(point));
76
74
  };
77
75
  //---Distance-------------------------------------------------------------------------------
78
76
  Plane.prototype.distancePoint = function (point) {
@@ -225,8 +223,8 @@ var Plane = /** @class */ (function () {
225
223
  * @param polyVS
226
224
  */
227
225
  Plane.prototype.splitPolyVS = function (polyVS) {
228
- polyVS = __spreadArray([], polyVS, true);
229
- (0, mesh_1.indexable)(polyVS);
226
+ polyVS = __spreadArrays(polyVS);
227
+ mesh_1.indexable(polyVS);
230
228
  var jd0 = -1; //找出第一个交点
231
229
  var jdp0; //找出第一个交点
232
230
  var lastOriention = this.orientationPoint(polyVS[0]);
@@ -3,12 +3,10 @@ var __extends = (this && this.__extends) || (function () {
3
3
  var extendStatics = function (d, b) {
4
4
  extendStatics = Object.setPrototypeOf ||
5
5
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
10
  extendStatics(d, b);
13
11
  function __() { this.constructor = d; }
14
12
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -3,12 +3,10 @@ var __extends = (this && this.__extends) || (function () {
3
3
  var extendStatics = function (d, b) {
4
4
  extendStatics = Object.setPrototypeOf ||
5
5
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
10
  extendStatics(d, b);
13
11
  function __() { this.constructor = d; }
14
12
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -3,12 +3,10 @@ var __extends = (this && this.__extends) || (function () {
3
3
  var extendStatics = function (d, b) {
4
4
  extendStatics = Object.setPrototypeOf ||
5
5
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
10
  extendStatics(d, b);
13
11
  function __() { this.constructor = d; }
14
12
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -3,12 +3,10 @@ var __extends = (this && this.__extends) || (function () {
3
3
  var extendStatics = function (d, b) {
4
4
  extendStatics = Object.setPrototypeOf ||
5
5
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
10
  extendStatics(d, b);
13
11
  function __() { this.constructor = d; }
14
12
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -3,12 +3,10 @@ var __extends = (this && this.__extends) || (function () {
3
3
  var extendStatics = function (d, b) {
4
4
  extendStatics = Object.setPrototypeOf ||
5
5
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
10
  extendStatics(d, b);
13
11
  function __() { this.constructor = d; }
14
12
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -25,16 +23,16 @@ var Segment = /** @class */ (function (_super) {
25
23
  * @param {Point|Vec3} p1
26
24
  */
27
25
  function Segment(_p0, _p1) {
28
- if (_p0 === void 0) { _p0 = (0, Vec3_1.v3)(); }
29
- if (_p1 === void 0) { _p1 = (0, Vec3_1.v3)(); }
26
+ if (_p0 === void 0) { _p0 = Vec3_1.v3(); }
27
+ if (_p1 === void 0) { _p1 = Vec3_1.v3(); }
30
28
  var _this = _super.call(this) || this;
31
29
  Object.setPrototypeOf(_this, Segment.prototype);
32
- _this.push((0, Vec3_1.v3)().copy(_p0), (0, Vec3_1.v3)().copy(_p1));
33
- _this.center = (0, Vec3_1.v3)().addVecs(_p0, _p1).multiplyScalar(0.5);
34
- _this.extentDirection = (0, Vec3_1.v3)().subVecs(_p1, _p0);
30
+ _this.push(Vec3_1.v3().copy(_p0), Vec3_1.v3().copy(_p1));
31
+ _this.center = Vec3_1.v3().addVecs(_p0, _p1).multiplyScalar(0.5);
32
+ _this.extentDirection = Vec3_1.v3().subVecs(_p1, _p0);
35
33
  _this.extentSqr = _this.extentDirection.lengthSq();
36
34
  _this.extent = Math.sqrt(_this.extentSqr);
37
- _this.direction = (0, Vec3_1.v3)().copy(_this.extentDirection).normalize();
35
+ _this.direction = Vec3_1.v3().copy(_this.extentDirection).normalize();
38
36
  return _this;
39
37
  }
40
38
  Segment.prototype.set = function (p0, p1) {
@@ -3,12 +3,10 @@ var __extends = (this && this.__extends) || (function () {
3
3
  var extendStatics = function (d, b) {
4
4
  extendStatics = Object.setPrototypeOf ||
5
5
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
10
  extendStatics(d, b);
13
11
  function __() { this.constructor = d; }
14
12
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -4,7 +4,7 @@ exports.Sphere = void 0;
4
4
  var Vec3_1 = require("../../math/Vec3");
5
5
  var Sphere = /** @class */ (function () {
6
6
  function Sphere(center, radius) {
7
- if (center === void 0) { center = (0, Vec3_1.v3)(); }
7
+ if (center === void 0) { center = Vec3_1.v3(); }
8
8
  if (radius === void 0) { radius = 0; }
9
9
  this.center = center;
10
10
  this.radius = radius;
@@ -3,12 +3,10 @@ var __extends = (this && this.__extends) || (function () {
3
3
  var extendStatics = function (d, b) {
4
4
  extendStatics = Object.setPrototypeOf ||
5
5
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
10
  extendStatics(d, b);
13
11
  function __() { this.constructor = d; }
14
12
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
- if (ar || !(i in from)) {
5
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
- ar[i] = from[i];
7
- }
8
- }
9
- return to.concat(ar || Array.prototype.slice.call(from));
2
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
3
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
4
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
5
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
6
+ r[k] = a[j];
7
+ return r;
10
8
  };
11
9
  Object.defineProperty(exports, "__esModule", { value: true });
12
10
  exports.ArrayList = void 0;
@@ -85,7 +83,7 @@ var ArrayList = /** @class */ (function () {
85
83
  for (var _i = 1; _i < arguments.length; _i++) {
86
84
  value[_i - 1] = arguments[_i];
87
85
  }
88
- (_a = this._array).splice.apply(_a, __spreadArray([i, 0], value, false));
86
+ (_a = this._array).splice.apply(_a, __spreadArrays([i, 0], value));
89
87
  };
90
88
  ArrayList.prototype.splice = function (start, deleteCount) {
91
89
  var _a;
@@ -93,7 +91,7 @@ var ArrayList = /** @class */ (function () {
93
91
  for (var _i = 2; _i < arguments.length; _i++) {
94
92
  items[_i - 2] = arguments[_i];
95
93
  }
96
- (_a = this._array).splice.apply(_a, __spreadArray([start, deleteCount], items, false));
94
+ (_a = this._array).splice.apply(_a, __spreadArrays([start, deleteCount], items));
97
95
  };
98
96
  ArrayList.prototype.get = function (index) {
99
97
  if (index < 0)
@@ -113,7 +111,7 @@ var ArrayList = /** @class */ (function () {
113
111
  * 克隆
114
112
  */
115
113
  ArrayList.prototype.clone = function () {
116
- return new this.constructor((0, common_1.clone)(this._array));
114
+ return new this.constructor(common_1.clone(this._array));
117
115
  };
118
116
  /**
119
117
  * 分类
@@ -3,12 +3,10 @@ var __extends = (this && this.__extends) || (function () {
3
3
  var extendStatics = function (d, b) {
4
4
  extendStatics = Object.setPrototypeOf ||
5
5
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
10
  extendStatics(d, b);
13
11
  function __() { this.constructor = d; }
14
12
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xort/cga",
3
- "version": "0.0.78",
3
+ "version": "0.0.81",
4
4
  "description": "Xtor Compute Geometry Algorithm Libary 计算几何算法库",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/math/Color.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { EventHandler } from "../render/eventhandler";
2
2
 
3
3
  export class Color extends EventHandler {
4
- _r: number =0.0;
5
- _g: number =0.0;
6
- _b: number =0.0;
7
- _a: number =1.0;
4
+ _r: number = 0.0;
5
+ _g: number = 0.0;
6
+ _b: number = 0.0;
7
+ _a: number = 1.0;
8
+
8
9
  constructor(r: number = 0, g: number = 0, b: number = 0, a: number = 1) {
9
10
  super();
10
11
  this._r = r;
@@ -69,26 +70,68 @@ export class Color extends EventHandler {
69
70
  } else if (typeof value === 'number') {
70
71
  this.setHex(value);
71
72
  }
73
+ if (typeof value === 'string') {
74
+ if (value.indexOf("#") === 0)
75
+ this.setHexCssString(value);
76
+ else
77
+ console.error("未匹配的颜色数据")
78
+ }
72
79
 
73
80
  return this;
74
81
  }
75
82
 
76
83
  setHex(hex: number) {
77
-
78
84
  hex = Math.floor(hex);
79
- if (hex > 0xffffff) {
80
- this._r = (hex >> 32 & 255) / 255;
81
- this._g = (hex >> 16 & 255) / 255;
82
- this._b = (hex >> 8 & 255) / 255;
83
- this._a = (hex & 255) / 255;
84
- } else {
85
- this._r = (hex >> 16 & 255) / 255;
86
- this._g = (hex >> 8 & 255) / 255;
87
- this._b = (hex & 255) / 255;
88
- }
85
+
86
+ this._r = (hex >> 16 & 255) / 255;
87
+ this._g = (hex >> 8 & 255) / 255;
88
+ this._b = (hex & 255) / 255;
89
89
 
90
90
  return this;
91
+ }
92
+
93
+ setHexCssString(style: string) {
94
+ let m: any = /^\#([A-Fa-f\d]+)$/.exec(style)
95
+ // hex color
96
+
97
+ const hex = m[1];
98
+ const size = hex.length;
99
+
100
+ if (size === 3) {
101
+
102
+ // #ff0
103
+ this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
104
+ this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
105
+ this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
106
+
107
+ return this;
91
108
 
109
+ } else if (size === 6) {
110
+
111
+ // #ff0000
112
+ this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
113
+ this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
114
+ this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
115
+ return this;
116
+ }
117
+ else if (size === 4) {
118
+
119
+ // #ff0000
120
+ this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255;
121
+ this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255;
122
+ this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255;
123
+ this.a = parseInt(hex.charAt(3) + hex.charAt(3), 16) / 255;
124
+ return this;
125
+ }
126
+ else if (size === 8) {
127
+
128
+ // #ff0000
129
+ this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255;
130
+ this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255;
131
+ this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255;
132
+ this.a = parseInt(hex.charAt(6) + hex.charAt(7), 16) / 255;
133
+ return this;
134
+ }
92
135
  }
93
136
 
94
137
  setRGB(r: number, g: number, b: number, a: number = 1.0) {
@@ -99,7 +142,6 @@ export class Color extends EventHandler {
99
142
  this._a = a;
100
143
 
101
144
  return this;
102
-
103
145
  }
104
146
 
105
147
  clone() {
@@ -110,12 +152,13 @@ export class Color extends EventHandler {
110
152
  this._r = color.r;
111
153
  this._g = color.g;
112
154
  this._b = color.b;
155
+ this._a = color.a;
113
156
 
114
157
  return this;
115
158
  }
116
159
 
117
160
  equals(c: this) {
118
- return (c.r === this.r) && (c.g === this.g) && (c.b === this.b);
161
+ return (c.r === this.r) && (c.g === this.g) && (c.b === this.b) && (c.a === this.a);
119
162
  }
120
163
 
121
164
  toArray(array: number[] = [], offset = 0) {
@@ -127,13 +170,39 @@ export class Color extends EventHandler {
127
170
 
128
171
  return array;
129
172
  }
173
+ private byteToFloat(val: number) {
174
+ return val / 255.0;
175
+ };
130
176
 
131
- getHex() {
132
- return (this.r * 255) << 32 ^ (this.g * 255) << 16 ^ (this.b * 255) << 8 ^ (this.a * 255) << 0;
177
+ private floatToByte(val: number) {
178
+ return val === 1.0 ? 255.0 : (val * 256.0) | 0;
179
+ };
180
+
181
+ getHexCssString() {
182
+ let r = this.floatToByte(this._r).toString(16);
183
+ if (r.length < 2) {
184
+ r = `0${r}`;
185
+ }
186
+ let g = this.floatToByte(this._g).toString(16);
187
+ if (g.length < 2) {
188
+ g = `0${g}`;
189
+ }
190
+ let b = this.floatToByte(this._b).toString(16);
191
+ if (b.length < 2) {
192
+ b = `0${b}`;
193
+ }
194
+ if (this._a < 1) {
195
+ let hexAlpha = this.floatToByte(this._a).toString(16);
196
+ if (hexAlpha.length < 2) {
197
+ hexAlpha = `0${hexAlpha}`;
198
+ }
199
+ return `#${r}${g}${b}${hexAlpha}`;
200
+ }
201
+ return `#${r}${g}${b}`;
133
202
  }
134
203
 
135
204
  toJSON() {
136
- return this.getHex();
205
+ return this.getHexCssString();
137
206
  }
138
207
 
139
208
  }