修正 Matrix2 错误的问题 简化代码.添加测试

pull/44/head
ChenX 7 years ago
parent 46498b7a3a
commit 22bea5ee99

@ -1,5 +1,8 @@
import { getLoocAtUpVec, cZAxis } from "./../../src/Geometry/GeUtils" import { Vector3 } from 'three';
import { Vector3 } from "three";
import { getLoocAtUpVec } from './../../src/Geometry/GeUtils';
import { rotateLine } from "./../../src/Common/CurveUtils";
test('getLoocAtUpVec', () => test('getLoocAtUpVec', () =>
{ {
@ -14,3 +17,16 @@ test('getLoocAtUpVec', () =>
//前视图 //前视图
expect(getLoocAtUpVec(new Vector3(0, 1, 0)) /*?*/).toMatchSnapshot(); expect(getLoocAtUpVec(new Vector3(0, 1, 0)) /*?*/).toMatchSnapshot();
}); });
test('should behave...', () =>
{
let v = new Vector3(1, 0, 0);
rotateLine(v, 0.5);
expect(v).toMatchSnapshot();
rotateLine(v, -0.5);
expect(v).toMatchSnapshot();
});

@ -39,3 +39,19 @@ Vector3 {
"z": 1, "z": 1,
} }
`; `;
exports[`should behave... 1`] = `
Vector3 {
"x": 0.8775825618903728,
"y": 0.479425538604203,
"z": 0,
}
`;
exports[`should behave... 2`] = `
Vector3 {
"x": 1,
"y": 0,
"z": 0,
}
`;

@ -3,6 +3,7 @@ import * as THREE from 'three';
import { CreateBoardUtil } from '../ApplicationServices/mesh/createBoard'; import { CreateBoardUtil } from '../ApplicationServices/mesh/createBoard';
import { angleTo, equaln, equal } from '../Geometry/GeUtils'; import { angleTo, equaln, equal } from '../Geometry/GeUtils';
import { Matrix2 } from '../Geometry/Matrix2';
export enum ExtendDir export enum ExtendDir
{ {
@ -13,8 +14,7 @@ export enum ExtendDir
//旋转矢量 //旋转矢量
export function rotateLine(l: Vector3, ang: number) export function rotateLine(l: Vector3, ang: number)
{ {
let mat = new THREE.Matrix4().makeRotationZ(ang); new Matrix2().setRotate(ang).applyVector(l);
l.applyMatrix4(mat);
return l; return l;
} }
//2点加凸度获取圆弧面积 //2点加凸度获取圆弧面积

@ -1,8 +1,8 @@
import { Vector2 } from "three"; import { Vector2, Vector3 } from "three";
export class Matrix2 export class Matrix2
{ {
el = [1, 0, 0, 1]; private el = [1, 0, 0, 1];
set(n11: number, n12: number, n21: number, n22: number) set(n11: number, n12: number, n21: number, n22: number)
{ {
let te = this.el; let te = this.el;
@ -11,12 +11,14 @@ export class Matrix2
te[2] = n12; te[3] = n22; te[2] = n12; te[3] = n22;
return this; return this;
} }
applyVec2(vec: Vector2) applyVector(vec: Vector2 | Vector3)
{ {
let x = vec.x, y = vec.y; let x = vec.x, y = vec.y;
let e = this.el; let e = this.el;
vec.x = e[0] * x + e[2] * y; vec.x = e[0] * x + e[2] * y;
vec.y = e[1] * x + e[3] * y; vec.y = e[1] * x + e[3] * y;
return this;
} }
setRotate(theta) setRotate(theta)
@ -24,7 +26,8 @@ export class Matrix2
let el = this.el; let el = this.el;
let c = Math.cos(theta), s = Math.sin(theta); let c = Math.cos(theta), s = Math.sin(theta);
el[0] = c; el[1] = -s; this.set(c, -s,
el[2] = s; el[3] = c; s, c);
return this;
} }
} }

@ -16,7 +16,7 @@ export function RotateUVs(geo: THREE.Geometry)
{ {
for (let v of uv) for (let v of uv)
{ {
roMat.applyVec2(v); roMat.applyVector(v);
v.add(addV); v.add(addV);
} }
} }

Loading…
Cancel
Save