@xort/cga 0.0.72 → 0.0.75

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 (57) 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.d.ts +1 -0
  14. package/dist/index.js +3 -6
  15. package/dist/math/Color.d.ts +29 -0
  16. package/dist/math/Color.js +195 -0
  17. package/dist/math/Euler.js +10 -12
  18. package/dist/math/HVec3.js +1 -3
  19. package/dist/math/Mat3.js +1 -1
  20. package/dist/math/Mat4.js +6 -6
  21. package/dist/math/Quat.js +2 -4
  22. package/dist/math/Vec.js +1 -3
  23. package/dist/math/Vec2.js +1 -3
  24. package/dist/math/Vec3.js +5 -7
  25. package/dist/math/Vec4.js +1 -3
  26. package/dist/math/vector.js +7 -9
  27. package/dist/render/buffer-attribute.js +28 -12
  28. package/dist/render/eventhandler.d.ts +1 -1
  29. package/dist/render/eventhandler.js +7 -9
  30. package/dist/render/geometry.js +2 -2
  31. package/dist/render/mesh.js +9 -11
  32. package/dist/render/thing.js +8 -10
  33. package/dist/render/types.js +1 -2
  34. package/dist/struct/3d/Box.js +3 -3
  35. package/dist/struct/3d/Capsule.js +1 -3
  36. package/dist/struct/3d/Circle.js +2 -2
  37. package/dist/struct/3d/Disk.js +1 -1
  38. package/dist/struct/3d/Line.js +4 -4
  39. package/dist/struct/3d/Path.js +11 -13
  40. package/dist/struct/3d/Plane.js +10 -12
  41. package/dist/struct/3d/Point.js +1 -3
  42. package/dist/struct/3d/Polygon.js +1 -3
  43. package/dist/struct/3d/Polyline.js +1 -3
  44. package/dist/struct/3d/Rectangle.js +1 -3
  45. package/dist/struct/3d/Segment.js +7 -9
  46. package/dist/struct/3d/Shape.js +1 -3
  47. package/dist/struct/3d/Sphere.js +1 -1
  48. package/dist/struct/3d/Triangle.js +1 -3
  49. package/dist/struct/data/ArrayList.js +9 -11
  50. package/dist/struct/data/ArrayObject.js +1 -3
  51. package/docs/guide/distLineAll.md +5 -5
  52. package/docs/guide/distPointAll.md +6 -6
  53. package/docs/guide/distRayAll.md +4 -4
  54. package/docs/guide/distSegmentAll.md +1 -1
  55. package/package.json +2 -2
  56. package/src/index.ts +1 -0
  57. package/src/math/Color.ts +157 -0
@@ -12,7 +12,7 @@ sidebarDepth: 2
12
12
  </ClientOnly>
13
13
 
14
14
  ```javascript
15
- import * as cga from "@xtor/cga.js";
15
+ import * as cga from "@xtor/cga";
16
16
  var seg0 = new cga.Segment(randomV3(), randomV3());
17
17
  var seg1 = new cga.Segment(randomV3(), randomV3());
18
18
  var result = seg0.distanceSegment(seg);
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@xort/cga",
3
- "version": "0.0.72",
3
+ "version": "0.0.75",
4
4
  "description": "Xtor Compute Geometry Algorithm Libary 计算几何算法库",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
7
7
  "scripts": {
8
- "release": "tsc && git.sh && npm publish",
8
+ "release": "tsc && npm publish && git.sh",
9
9
  "dev": "webpack-dev-server",
10
10
  "build:dev": "webpack --mode development",
11
11
  "build:prod": "webpack --mode production",
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ export * from "./math/Mat4"
7
7
  export * from "./math/Quat"
8
8
  export * from "./math/Math"
9
9
  export * from "./math/Euler"
10
+ export * from "./math/Color"
10
11
  //common
11
12
  export * from "./math/vector"
12
13
 
@@ -0,0 +1,157 @@
1
+ import { EventHandler } from "src/render/eventhandler";
2
+ import * as THREE from "three"
3
+
4
+
5
+ export function hue2rgb(p: number, q: number, t: number) {
6
+
7
+ if (t < 0) t += 1;
8
+ if (t > 1) t -= 1;
9
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
10
+ if (t < 1 / 2) return q;
11
+ if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
12
+ return p;
13
+
14
+ }
15
+
16
+ export function SRGBToLinear(c: number) {
17
+
18
+ return (c < 0.04045) ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
19
+
20
+ }
21
+
22
+ export function LinearToSRGB(c: number) {
23
+
24
+ return (c < 0.0031308) ? c * 12.92 : 1.055 * (Math.pow(c, 0.41666)) - 0.055;
25
+
26
+ }
27
+
28
+ export class Color extends EventHandler {
29
+ get isColor() {
30
+ return true;
31
+ }
32
+
33
+ constructor(private _r: number = 0, private _g: number = 0, private _b: number = 0, private _a: number = 1) {
34
+ super();
35
+ }
36
+
37
+ get r() {
38
+ return this._r;
39
+ }
40
+
41
+ set r(value) {
42
+ if (this._r !== value) {
43
+ this._r = value;
44
+ this.fire('change', 'r', this._r, value)
45
+ }
46
+ }
47
+
48
+ get g() {
49
+ return this._g;
50
+ }
51
+
52
+ set g(value) {
53
+ if (this._g !== value) {
54
+ this._g = value;
55
+ this.fire('change', 'g', this._g, value)
56
+ }
57
+ }
58
+
59
+ get b() {
60
+ return this._g;
61
+ }
62
+
63
+ set b(value) {
64
+ if (this._b !== value) {
65
+ this._b = value;
66
+ this.fire('change', 'b', this._b, value)
67
+ }
68
+ THREE.Color
69
+ }
70
+
71
+ get a() {
72
+ return this._a;
73
+ }
74
+
75
+ set a(value) {
76
+ if (this._a !== value) {
77
+ this._a = value;
78
+ this.fire('change', 'a', this._a, value)
79
+ }
80
+ }
81
+
82
+
83
+ set(value: any) {
84
+
85
+ if (value && value.isColor) {
86
+ this.copy(value);
87
+ } else if (typeof value === 'number') {
88
+ this.setHex(value);
89
+ }
90
+
91
+ return this;
92
+ }
93
+
94
+ setHex(hex: number) {
95
+
96
+ hex = Math.floor(hex);
97
+ if (hex > 0xffffff) {
98
+ this._r = (hex >> 32 & 255) / 255;
99
+ this._g = (hex >> 16 & 255) / 255;
100
+ this._b = (hex >> 8 & 255) / 255;
101
+ this._a = (hex & 255) / 255;
102
+ } else {
103
+ this._r = (hex >> 16 & 255) / 255;
104
+ this._g = (hex >> 8 & 255) / 255;
105
+ this._b = (hex & 255) / 255;
106
+ }
107
+
108
+ return this;
109
+
110
+ }
111
+
112
+ setRGB(r: number, g: number, b: number, a: number = 1.0) {
113
+
114
+ this._r = r;
115
+ this._g = g;
116
+ this._b = b;
117
+ this._a = a;
118
+
119
+ return this;
120
+
121
+ }
122
+
123
+ clone() {
124
+ return new (this.constructor as any)(this.r, this.g, this.b, this.a);
125
+ }
126
+
127
+ copy(color: this) {
128
+ this._r = color.r;
129
+ this._g = color.g;
130
+ this._b = color.b;
131
+
132
+ return this;
133
+ }
134
+
135
+ equals(c: this) {
136
+ return (c.r === this.r) && (c.g === this.g) && (c.b === this.b);
137
+ }
138
+
139
+ toArray(array: number[] = [], offset = 0) {
140
+
141
+ array[offset] = this.r;
142
+ array[offset + 1] = this.g;
143
+ array[offset + 2] = this.b;
144
+ array[offset + 3] = this.a;
145
+
146
+ return array;
147
+ }
148
+
149
+ getHex() {
150
+ return (this.r * 255) << 32 ^ (this.g * 255) << 16 ^ (this.b * 255) << 8 ^ (this.a * 255) << 0;
151
+ }
152
+
153
+ toJSON() {
154
+ return this.getHex();
155
+ }
156
+
157
+ }