@xort/cga 0.0.84 → 0.0.86
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/build/@xort_cga.js +290 -754
- package/dist/math/Color.d.ts +1 -0
- package/dist/math/Color.js +10 -0
- package/dist/struct/3d/Circle.d.ts +12 -3
- package/dist/struct/3d/Circle.js +33 -5
- package/package.json +1 -1
- package/src/math/Color.ts +14 -1
- package/src/struct/3d/Circle.ts +37 -8
- package/src/shape/arc.ts +0 -14
package/dist/math/Color.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare class Color {
|
|
|
21
21
|
copy(color: this): this;
|
|
22
22
|
equals(c: this): boolean;
|
|
23
23
|
toArray(array?: number[], offset?: number): number[];
|
|
24
|
+
fromArray(array?: number[], offset?: number): number[];
|
|
24
25
|
private byteToFloat;
|
|
25
26
|
private floatToByte;
|
|
26
27
|
getHexCssString(): string;
|
package/dist/math/Color.js
CHANGED
|
@@ -163,6 +163,16 @@ var Color = /** @class */ (function () {
|
|
|
163
163
|
array[offset + 3] = this.a;
|
|
164
164
|
return array;
|
|
165
165
|
};
|
|
166
|
+
Color.prototype.fromArray = function (array, offset) {
|
|
167
|
+
if (array === void 0) { array = []; }
|
|
168
|
+
if (offset === void 0) { offset = 0; }
|
|
169
|
+
this.r = array[offset];
|
|
170
|
+
this.g = array[offset + 1];
|
|
171
|
+
this.b = array[offset + 2];
|
|
172
|
+
if (array.length >= 4 + offset)
|
|
173
|
+
this.a = array[offset + 3];
|
|
174
|
+
return array;
|
|
175
|
+
};
|
|
166
176
|
Color.prototype.byteToFloat = function (val) {
|
|
167
177
|
return val / 255.0;
|
|
168
178
|
};
|
|
@@ -4,7 +4,7 @@ export declare class Circle {
|
|
|
4
4
|
radius: number;
|
|
5
5
|
normal: Vec3;
|
|
6
6
|
startAngle: number;
|
|
7
|
-
|
|
7
|
+
lengthAngle: number;
|
|
8
8
|
radiusSqr: number;
|
|
9
9
|
/**
|
|
10
10
|
* 圆圈
|
|
@@ -12,7 +12,7 @@ export declare class Circle {
|
|
|
12
12
|
* @param {Vec3} normal 法线
|
|
13
13
|
* @param {Number} radius 半径
|
|
14
14
|
*/
|
|
15
|
-
constructor(center?: Vec3, radius?: number, normal?: Vec3);
|
|
15
|
+
constructor(center?: Vec3, radius?: number, startAngle?: number, lengthAngle?: number, normal?: Vec3);
|
|
16
16
|
area(): number;
|
|
17
17
|
/**
|
|
18
18
|
* 两个点
|
|
@@ -30,5 +30,14 @@ export declare class Circle {
|
|
|
30
30
|
*/
|
|
31
31
|
arc2(center: Vec3, fixp1: Vec3, movep: Vec3, ccw?: boolean, normal?: Vec3): void;
|
|
32
32
|
setFrom3Points(p0: Vec3, p1: Vec3, p2: Vec3, normal?: Vec3): this;
|
|
33
|
+
/**
|
|
34
|
+
* 将圆环或者圆弧转化为路径点,生成XY平面上得三维点
|
|
35
|
+
* @param center 中心点
|
|
36
|
+
* @param radius 半径
|
|
37
|
+
* @param startAngle 起始角 右手坐标系 以X正坐标轴为起点 单位弧度
|
|
38
|
+
* @param lengthAngle 弧度长度 单位弧度
|
|
39
|
+
* @param segment 分段
|
|
40
|
+
*/
|
|
41
|
+
static toVertices(center: Vec3, radius: number, startAngle?: number, lengthAngle?: number, segment?: number): Vec3[];
|
|
33
42
|
}
|
|
34
|
-
export declare function circle(center?: Vec3, radius?: number
|
|
43
|
+
export declare function circle(center?: Vec3, radius?: number): Circle;
|
package/dist/struct/3d/Circle.js
CHANGED
|
@@ -11,16 +11,20 @@ var Circle = /** @class */ (function () {
|
|
|
11
11
|
* @param {Vec3} normal 法线
|
|
12
12
|
* @param {Number} radius 半径
|
|
13
13
|
*/
|
|
14
|
-
function Circle(center, radius, normal) {
|
|
14
|
+
function Circle(center, radius, startAngle, lengthAngle, normal) {
|
|
15
15
|
if (center === void 0) { center = new Vec3_1.Vec3(); }
|
|
16
16
|
if (radius === void 0) { radius = 0; }
|
|
17
|
+
if (startAngle === void 0) { startAngle = 0; }
|
|
18
|
+
if (lengthAngle === void 0) { lengthAngle = Math.PI * 2; }
|
|
17
19
|
if (normal === void 0) { normal = Vec3_1.Vec3.UnitY; }
|
|
18
20
|
this.center = center;
|
|
19
21
|
this.radius = radius;
|
|
20
22
|
this.normal = normal;
|
|
21
23
|
this.startAngle = 0;
|
|
22
|
-
this.
|
|
24
|
+
this.lengthAngle = Math.PI * 2;
|
|
23
25
|
this.radiusSqr = 0;
|
|
26
|
+
this.startAngle = startAngle;
|
|
27
|
+
this.lengthAngle = lengthAngle;
|
|
24
28
|
}
|
|
25
29
|
Circle.prototype.area = function () {
|
|
26
30
|
return Math.PI * this.radius * this.radius;
|
|
@@ -35,7 +39,7 @@ var Circle = /** @class */ (function () {
|
|
|
35
39
|
Circle.prototype.arc1 = function (fixp0, fixp1, movep, normal) {
|
|
36
40
|
this.setFrom3Points(fixp0, fixp1, movep);
|
|
37
41
|
this.startAngle = 0;
|
|
38
|
-
this.
|
|
42
|
+
this.lengthAngle = common_1.angle(fixp0.clone().sub(this.center).normalize(), fixp1.clone().sub(this.center).normalize(), this.normal || normal);
|
|
39
43
|
};
|
|
40
44
|
/**
|
|
41
45
|
* 全两个点确定半径,后面点确定 弧度 ,只需要检测鼠标移动时鼠标是否跨过第一条半径即可确定顺逆时针
|
|
@@ -71,10 +75,34 @@ var Circle = /** @class */ (function () {
|
|
|
71
75
|
this.normal = normal;
|
|
72
76
|
return this;
|
|
73
77
|
};
|
|
78
|
+
/**
|
|
79
|
+
* 将圆环或者圆弧转化为路径点,生成XY平面上得三维点
|
|
80
|
+
* @param center 中心点
|
|
81
|
+
* @param radius 半径
|
|
82
|
+
* @param startAngle 起始角 右手坐标系 以X正坐标轴为起点 单位弧度
|
|
83
|
+
* @param lengthAngle 弧度长度 单位弧度
|
|
84
|
+
* @param segment 分段
|
|
85
|
+
*/
|
|
86
|
+
Circle.toVertices = function (center, radius, startAngle, lengthAngle, segment) {
|
|
87
|
+
if (startAngle === void 0) { startAngle = 0; }
|
|
88
|
+
if (lengthAngle === void 0) { lengthAngle = Math.PI * 2; }
|
|
89
|
+
if (segment === void 0) { segment = 16; }
|
|
90
|
+
var Xvec = Vec3_1.Vec3.UnitX;
|
|
91
|
+
Xvec.multiplyScalar(radius);
|
|
92
|
+
var result = [];
|
|
93
|
+
var up = Vec3_1.Vec3.UnitY;
|
|
94
|
+
var perAngle = lengthAngle / segment;
|
|
95
|
+
for (var i = 0; i <= segment; i++) {
|
|
96
|
+
var langlei = perAngle * i + startAngle;
|
|
97
|
+
var vi = Xvec.clone().applyAxisAngle(up, langlei).add(center);
|
|
98
|
+
result.push(vi);
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
};
|
|
74
102
|
return Circle;
|
|
75
103
|
}());
|
|
76
104
|
exports.Circle = Circle;
|
|
77
|
-
function circle(center, radius
|
|
78
|
-
return new Circle(center, radius
|
|
105
|
+
function circle(center, radius) {
|
|
106
|
+
return new Circle(center, radius);
|
|
79
107
|
}
|
|
80
108
|
exports.circle = circle;
|
package/package.json
CHANGED
package/src/math/Color.ts
CHANGED
|
@@ -5,7 +5,7 @@ export class Color {
|
|
|
5
5
|
_b: number = 0.0;
|
|
6
6
|
_a: number = 1.0;
|
|
7
7
|
|
|
8
|
-
constructor(r: number = 0, g: number = 0, b: number = 0, a: number = 1) {
|
|
8
|
+
constructor(r: number = 0, g: number = 0, b: number = 0, a: number = 1) {
|
|
9
9
|
this._r = r;
|
|
10
10
|
this._g = g;
|
|
11
11
|
this._b = b;
|
|
@@ -168,6 +168,19 @@ export class Color {
|
|
|
168
168
|
|
|
169
169
|
return array;
|
|
170
170
|
}
|
|
171
|
+
|
|
172
|
+
fromArray(array: number[] = [], offset = 0) {
|
|
173
|
+
|
|
174
|
+
this.r = array[offset];
|
|
175
|
+
this.g = array[offset + 1];
|
|
176
|
+
this.b = array[offset + 2];
|
|
177
|
+
|
|
178
|
+
if (array.length >= 4 + offset)
|
|
179
|
+
this.a = array[offset + 3];
|
|
180
|
+
|
|
181
|
+
return array;
|
|
182
|
+
}
|
|
183
|
+
|
|
171
184
|
private byteToFloat(val: number) {
|
|
172
185
|
return val / 255.0;
|
|
173
186
|
};
|
package/src/struct/3d/Circle.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Vec3, v3 } from '../../math/Vec3';
|
|
2
|
-
import { angle, pointsCollinear } from '../../alg/common';
|
|
2
|
+
import { angle, pointsCollinear, rotate } from '../../alg/common';
|
|
3
3
|
import { Line } from './Line';
|
|
4
4
|
|
|
5
5
|
export class Circle {
|
|
6
6
|
startAngle: number = 0;
|
|
7
|
-
|
|
7
|
+
lengthAngle: number = Math.PI * 2;
|
|
8
8
|
radiusSqr: number = 0;
|
|
9
9
|
/**
|
|
10
10
|
* 圆圈
|
|
@@ -12,7 +12,9 @@ export class Circle {
|
|
|
12
12
|
* @param {Vec3} normal 法线
|
|
13
13
|
* @param {Number} radius 半径
|
|
14
14
|
*/
|
|
15
|
-
constructor(public center: Vec3 = new Vec3(), public radius: number = 0, public normal: Vec3 = Vec3.UnitY) {
|
|
15
|
+
constructor(public center: Vec3 = new Vec3(), public radius: number = 0, startAngle = 0, lengthAngle = Math.PI * 2, public normal: Vec3 = Vec3.UnitY) {
|
|
16
|
+
this.startAngle = startAngle;
|
|
17
|
+
this.lengthAngle = lengthAngle;
|
|
16
18
|
|
|
17
19
|
}
|
|
18
20
|
|
|
@@ -30,7 +32,7 @@ export class Circle {
|
|
|
30
32
|
arc1(fixp0: Vec3, fixp1: Vec3, movep: Vec3, normal?: Vec3) {
|
|
31
33
|
this.setFrom3Points(fixp0, fixp1, movep);
|
|
32
34
|
this.startAngle = 0
|
|
33
|
-
this.
|
|
35
|
+
this.lengthAngle = angle(fixp0.clone().sub(this.center).normalize(), fixp1.clone().sub(this.center).normalize(), this.normal || normal)
|
|
34
36
|
}
|
|
35
37
|
/**
|
|
36
38
|
* 全两个点确定半径,后面点确定 弧度 ,只需要检测鼠标移动时鼠标是否跨过第一条半径即可确定顺逆时针
|
|
@@ -47,8 +49,6 @@ export class Circle {
|
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
|
|
50
|
-
|
|
51
|
-
|
|
52
52
|
setFrom3Points(p0: Vec3, p1: Vec3, p2: Vec3, normal?: Vec3) {
|
|
53
53
|
// if (pointsCollinear(p0, p1, p2))
|
|
54
54
|
// throw ("calcCircleFromThreePoint:三点共线或者距离太近");
|
|
@@ -71,8 +71,37 @@ export class Circle {
|
|
|
71
71
|
this.normal = normal;
|
|
72
72
|
return this;
|
|
73
73
|
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 将圆环或者圆弧转化为路径点,生成XY平面上得三维点
|
|
78
|
+
* @param center 中心点
|
|
79
|
+
* @param radius 半径
|
|
80
|
+
* @param startAngle 起始角 右手坐标系 以X正坐标轴为起点 单位弧度
|
|
81
|
+
* @param lengthAngle 弧度长度 单位弧度
|
|
82
|
+
* @param segment 分段
|
|
83
|
+
*/
|
|
84
|
+
static toVertices(center: Vec3, radius: number, startAngle: number = 0, lengthAngle: number = Math.PI * 2, segment: number = 16) {
|
|
85
|
+
const Xvec: Vec3 = Vec3.UnitX;
|
|
86
|
+
Xvec.multiplyScalar(radius);
|
|
87
|
+
|
|
88
|
+
const result:Vec3[]=[]
|
|
89
|
+
|
|
90
|
+
const up: Vec3 = Vec3.UnitY;
|
|
91
|
+
const perAngle = lengthAngle / segment;
|
|
92
|
+
for (let i = 0; i <= segment; i++) {
|
|
93
|
+
const langlei = perAngle * i + startAngle;
|
|
94
|
+
|
|
95
|
+
const vi = Xvec.clone().applyAxisAngle(up, langlei).add(center);
|
|
96
|
+
|
|
97
|
+
result.push(vi);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
|
|
74
103
|
}
|
|
75
104
|
|
|
76
|
-
export function circle(center?: Vec3, radius?: number
|
|
77
|
-
return new Circle(center, radius
|
|
105
|
+
export function circle(center?: Vec3, radius?: number) {
|
|
106
|
+
return new Circle(center, radius);
|
|
78
107
|
}
|
package/src/shape/arc.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Description :
|
|
3
|
-
* @Author : 赵耀圣
|
|
4
|
-
* @QQ : 549184003
|
|
5
|
-
* @Date : 2021-03-15 09:40:01
|
|
6
|
-
* @LastEditTime : 2021-03-15 09:42:14
|
|
7
|
-
* @FilePath : \cga.js\src\shape\arc.ts
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { Vec3 } from "../math/Vec3";
|
|
11
|
-
|
|
12
|
-
export function Circle(center: Vec3, radius: number, segment: number, startAngle: number, lenAngle: number) {
|
|
13
|
-
|
|
14
|
-
}
|