Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
62cac176
T
three.js
项目概览
车家大少爷
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
three.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
62cac176
编写于
3月 09, 2018
作者:
M
Mugen87
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Triangle: Refactor methods
上级
e5012e23
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
177 addition
and
88 deletion
+177
-88
docs/api/math/Triangle.html
docs/api/math/Triangle.html
+23
-23
examples/js/QuickHull.js
examples/js/QuickHull.js
+3
-3
src/Three.Legacy.js
src/Three.Legacy.js
+53
-0
src/math/Triangle.js
src/math/Triangle.js
+17
-17
src/objects/Mesh.js
src/objects/Mesh.js
+2
-2
test/unit/src/math/Triangle.tests.js
test/unit/src/math/Triangle.tests.js
+79
-43
未找到文件。
docs/api/math/Triangle.html
浏览文件 @
62cac176
...
...
@@ -48,20 +48,6 @@
<h2>
Methods
</h2>
<h3>
[method:Float area]()
</h3>
<div>
Return the area of the triangle.
</div>
<h3>
[method:Vector3 barycoordFromPoint]( [param:Vector3 point], [param:Vector3 target] )
</h3>
<div>
[page:Vector3 point] - [page:Vector3]
<br
/>
[page:Vector3 target] — the result will be copied into this Vector3.
<br
/><br
/>
Return a [link:https://en.wikipedia.org/wiki/Barycentric_coordinate_system barycentric coordinate]
from the given vector.
<br/><br/>
[link:http://commons.wikimedia.org/wiki/File:Barycentric_coordinates_1.png Picture of barycentric coordinates]
</div>
<h3>
[method:Triangle clone]()
</h3>
<div>
Returns a new triangle with the same [page:.a a], [page:.b b] and [page:.c c] properties as this one.
...
...
@@ -69,7 +55,7 @@
<h3>
[method:Vector3 closestPointToPoint]( [param:Vector3 point], [param:Vector3 target] )
</h3>
<div>
point
- [page:Vector3]
<br
/>
[page:Vector3 point]
- [page:Vector3]
<br
/>
[page:Vector3 target] — the result will be copied into this Vector3.
<br
/><br
/>
Returns the closest point on the triangle to [page:Vector3 point].
...
...
@@ -93,32 +79,46 @@
Returns true if the two triangles have identical [page:.a a], [page:.b b] and [page:.c c] properties.
</div>
<h3>
[method:Boolean intersectsBox]( [param:Box3 box] )
</h3>
<h3>
[method:Float getArea]()
</h3>
<div>
Return the area of the triangle.
</div>
<h3>
[method:Vector3 getBarycoord]( [param:Vector3 point], [param:Vector3 target] )
</h3>
<div>
[page:Box3 box] - Box to check for intersection against.
<br
/><br
/>
[page:Vector3 point] - [page:Vector3]
<br
/>
[page:Vector3 target] — the result will be copied into this Vector3.
<br
/><br
/>
Determines whether or not this triangle intersects [page:Box3 box].
Return a [link:https://en.wikipedia.org/wiki/Barycentric_coordinate_system barycentric coordinate]
from the given vector.
<br/><br/>
[link:http://commons.wikimedia.org/wiki/File:Barycentric_coordinates_1.png Picture of barycentric coordinates]
</div>
<h3>
[method:Vector3
m
idpoint]( [param:Vector3 target] )
</h3>
<h3>
[method:Vector3
getM
idpoint]( [param:Vector3 target] )
</h3>
<div>
[page:Vector3 target] — the result will be copied into this Vector3.
<br
/><br
/>
Calculate the midpoint of the triangle.
</div>
<h3>
[method:Vector3
n
ormal]( [param:Vector3 target] )
</h3>
<h3>
[method:Vector3
getN
ormal]( [param:Vector3 target] )
</h3>
<div>
[page:Vector3 target] — the result will be copied into this Vector3.
<br
/><br
/>
Calculate the [link:https://en.wikipedia.org/wiki/Normal_(geometry) normal vector] of the triangle.
</div>
<h3>
[method:Plane
p
lane]( [param:Plane target] )
</h3>
<h3>
[method:Plane
getP
lane]( [param:Plane target] )
</h3>
<div>
[page:Vector3 target] — the result will be copied into this
Vector3
.
<br
/><br
/>
[page:Vector3 target] — the result will be copied into this
Plane
.
<br
/><br
/>
Create a [page:Plane plane] based on the triangle. .
Calculate a [page:Plane plane] based on the triangle. .
</div>
<h3>
[method:Boolean intersectsBox]( [param:Box3 box] )
</h3>
<div>
[page:Box3 box] - Box to check for intersection against.
<br
/><br
/>
Determines whether or not this triangle intersects [page:Box3 box].
</div>
<h3>
[method:Triangle set]( [param:Vector3 a], [param:Vector3 b], [param:Vector3 c] ) [param:Triangle this]
</h3>
...
...
examples/js/QuickHull.js
浏览文件 @
62cac176
...
...
@@ -917,9 +917,9 @@
triangle
.
set
(
a
.
point
,
b
.
point
,
c
.
point
);
triangle
.
n
ormal
(
this
.
normal
);
triangle
.
m
idpoint
(
this
.
midpoint
);
this
.
area
=
triangle
.
a
rea
();
triangle
.
getN
ormal
(
this
.
normal
);
triangle
.
getM
idpoint
(
this
.
midpoint
);
this
.
area
=
triangle
.
getA
rea
();
this
.
constant
=
this
.
normal
.
dot
(
this
.
midpoint
);
...
...
src/Three.Legacy.js
浏览文件 @
62cac176
...
...
@@ -59,6 +59,7 @@ import { Matrix4 } from './math/Matrix4.js';
import
{
Plane
}
from
'
./math/Plane.js
'
;
import
{
Quaternion
}
from
'
./math/Quaternion.js
'
;
import
{
Ray
}
from
'
./math/Ray.js
'
;
import
{
Triangle
}
from
'
./math/Triangle.js
'
;
import
{
Vector2
}
from
'
./math/Vector2.js
'
;
import
{
Vector3
}
from
'
./math/Vector3.js
'
;
import
{
Vector4
}
from
'
./math/Vector4.js
'
;
...
...
@@ -710,6 +711,58 @@ Object.assign( Ray.prototype, {
}
);
Object
.
assign
(
Triangle
.
prototype
,
{
area
:
function
()
{
console
.
warn
(
'
THREE.Triangle: .area() has been renamed to .getArea().
'
);
return
this
.
getArea
();
},
barycoordFromPoint
:
function
(
point
,
target
)
{
console
.
warn
(
'
THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().
'
);
return
this
.
getBarycoord
(
point
,
target
);
},
midpoint
:
function
(
target
)
{
console
.
warn
(
'
THREE.Triangle: .midpoint() has been renamed to .getMidpoint().
'
);
return
this
.
getMidpoint
(
target
);
},
normal
:
function
(
target
)
{
console
.
warn
(
'
THREE.Triangle: .normal() has been renamed to .getNormal().
'
);
return
this
.
getNormal
(
target
);
},
plane
:
function
(
target
)
{
console
.
warn
(
'
THREE.Triangle: .plane() has been renamed to .getPlane().
'
);
return
this
.
getPlane
(
target
);
}
}
);
Object
.
assign
(
Triangle
,
{
barycoordFromPoint
:
function
(
point
,
a
,
b
,
c
,
target
)
{
console
.
warn
(
'
THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().
'
);
return
Triangle
.
getBarycoord
(
point
,
a
,
b
,
c
,
target
);
},
normal
:
function
(
a
,
b
,
c
,
target
)
{
console
.
warn
(
'
THREE.Triangle: .normal() has been renamed to .getNormal().
'
);
return
Triangle
.
getNormal
(
a
,
b
,
c
,
target
);
}
}
);
Object
.
assign
(
Shape
.
prototype
,
{
extractAllPoints
:
function
(
divisions
)
{
...
...
src/math/Triangle.js
浏览文件 @
62cac176
...
...
@@ -17,15 +17,15 @@ function Triangle( a, b, c ) {
Object
.
assign
(
Triangle
,
{
n
ormal
:
function
()
{
getN
ormal
:
function
()
{
var
v0
=
new
Vector3
();
return
function
n
ormal
(
a
,
b
,
c
,
target
)
{
return
function
getN
ormal
(
a
,
b
,
c
,
target
)
{
if
(
target
===
undefined
)
{
console
.
warn
(
'
THREE.Triangle: .
n
ormal() target is now required
'
);
console
.
warn
(
'
THREE.Triangle: .
getN
ormal() target is now required
'
);
target
=
new
Vector3
();
}
...
...
@@ -49,13 +49,13 @@ Object.assign( Triangle, {
// static/instance method to calculate barycentric coordinates
// based on: http://www.blackpawn.com/texts/pointinpoly/default.html
barycoordFromPoint
:
function
()
{
getBarycoord
:
function
()
{
var
v0
=
new
Vector3
();
var
v1
=
new
Vector3
();
var
v2
=
new
Vector3
();
return
function
barycoordFromPoint
(
point
,
a
,
b
,
c
,
target
)
{
return
function
getBarycoord
(
point
,
a
,
b
,
c
,
target
)
{
v0
.
subVectors
(
c
,
a
);
v1
.
subVectors
(
b
,
a
);
...
...
@@ -71,7 +71,7 @@ Object.assign( Triangle, {
if
(
target
===
undefined
)
{
console
.
warn
(
'
THREE.Triangle: .
barycoordFromPoint
() target is now required
'
);
console
.
warn
(
'
THREE.Triangle: .
getBarycoord
() target is now required
'
);
target
=
new
Vector3
();
}
...
...
@@ -102,7 +102,7 @@ Object.assign( Triangle, {
return
function
containsPoint
(
point
,
a
,
b
,
c
)
{
Triangle
.
barycoordFromPoint
(
point
,
a
,
b
,
c
,
v1
);
Triangle
.
getBarycoord
(
point
,
a
,
b
,
c
,
v1
);
return
(
v1
.
x
>=
0
)
&&
(
v1
.
y
>=
0
)
&&
(
(
v1
.
x
+
v1
.
y
)
<=
1
);
...
...
@@ -150,12 +150,12 @@ Object.assign( Triangle.prototype, {
},
a
rea
:
function
()
{
getA
rea
:
function
()
{
var
v0
=
new
Vector3
();
var
v1
=
new
Vector3
();
return
function
a
rea
()
{
return
function
getA
rea
()
{
v0
.
subVectors
(
this
.
c
,
this
.
b
);
v1
.
subVectors
(
this
.
a
,
this
.
b
);
...
...
@@ -166,11 +166,11 @@ Object.assign( Triangle.prototype, {
}(),
m
idpoint
:
function
(
target
)
{
getM
idpoint
:
function
(
target
)
{
if
(
target
===
undefined
)
{
console
.
warn
(
'
THREE.Triangle: .
m
idpoint() target is now required
'
);
console
.
warn
(
'
THREE.Triangle: .
getM
idpoint() target is now required
'
);
target
=
new
Vector3
();
}
...
...
@@ -179,17 +179,17 @@ Object.assign( Triangle.prototype, {
},
n
ormal
:
function
(
target
)
{
getN
ormal
:
function
(
target
)
{
return
Triangle
.
n
ormal
(
this
.
a
,
this
.
b
,
this
.
c
,
target
);
return
Triangle
.
getN
ormal
(
this
.
a
,
this
.
b
,
this
.
c
,
target
);
},
p
lane
:
function
(
target
)
{
getP
lane
:
function
(
target
)
{
if
(
target
===
undefined
)
{
console
.
warn
(
'
THREE.Triangle: .
p
lane() target is now required
'
);
console
.
warn
(
'
THREE.Triangle: .
getP
lane() target is now required
'
);
target
=
new
Vector3
();
}
...
...
@@ -198,9 +198,9 @@ Object.assign( Triangle.prototype, {
},
barycoordFromPoint
:
function
(
point
,
target
)
{
getBarycoord
:
function
(
point
,
target
)
{
return
Triangle
.
barycoordFromPoint
(
point
,
this
.
a
,
this
.
b
,
this
.
c
,
target
);
return
Triangle
.
getBarycoord
(
point
,
this
.
a
,
this
.
b
,
this
.
c
,
target
);
},
...
...
src/objects/Mesh.js
浏览文件 @
62cac176
...
...
@@ -147,7 +147,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
function
uvIntersection
(
point
,
p1
,
p2
,
p3
,
uv1
,
uv2
,
uv3
)
{
Triangle
.
barycoordFromPoint
(
point
,
p1
,
p2
,
p3
,
barycoord
);
Triangle
.
getBarycoord
(
point
,
p1
,
p2
,
p3
,
barycoord
);
uv1
.
multiplyScalar
(
barycoord
.
x
);
uv2
.
multiplyScalar
(
barycoord
.
y
);
...
...
@@ -211,7 +211,7 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
}
var
face
=
new
Face3
(
a
,
b
,
c
);
Triangle
.
n
ormal
(
vA
,
vB
,
vC
,
face
.
normal
);
Triangle
.
getN
ormal
(
vA
,
vB
,
vC
,
face
.
normal
);
intersection
.
face
=
face
;
intersection
.
faceIndex
=
a
;
...
...
test/unit/src/math/Triangle.tests.js
浏览文件 @
62cac176
...
...
@@ -6,6 +6,7 @@
import
{
Triangle
}
from
'
../../../../src/math/Triangle
'
;
import
{
Box3
}
from
'
../../../../src/math/Box3
'
;
import
{
Plane
}
from
'
../../../../src/math/Plane
'
;
import
{
Vector3
}
from
'
../../../../src/math/Vector3
'
;
import
{
zero3
,
...
...
@@ -33,13 +34,13 @@ export default QUnit.module( 'Maths', () => {
}
);
// STATIC STUFF
QUnit
.
todo
(
"
n
ormal
"
,
(
assert
)
=>
{
QUnit
.
todo
(
"
getN
ormal
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
}
);
QUnit
.
todo
(
"
barycoordFromPoint
"
,
(
assert
)
=>
{
QUnit
.
todo
(
"
getBarycoord
"
,
(
assert
)
=>
{
assert
.
ok
(
false
,
"
everything's gonna be alright
"
);
...
...
@@ -99,123 +100,158 @@ export default QUnit.module( 'Maths', () => {
}
);
QUnit
.
test
(
"
a
rea
"
,
(
assert
)
=>
{
QUnit
.
test
(
"
getA
rea
"
,
(
assert
)
=>
{
var
a
=
new
Triangle
();
assert
.
ok
(
a
.
a
rea
()
==
0
,
"
Passed!
"
);
assert
.
ok
(
a
.
getA
rea
()
==
0
,
"
Passed!
"
);
var
a
=
new
Triangle
(
new
Vector3
(
0
,
0
,
0
),
new
Vector3
(
1
,
0
,
0
),
new
Vector3
(
0
,
1
,
0
)
);
assert
.
ok
(
a
.
a
rea
()
==
0.5
,
"
Passed!
"
);
assert
.
ok
(
a
.
getA
rea
()
==
0.5
,
"
Passed!
"
);
var
a
=
new
Triangle
(
new
Vector3
(
2
,
0
,
0
),
new
Vector3
(
0
,
0
,
0
),
new
Vector3
(
0
,
0
,
2
)
);
assert
.
ok
(
a
.
a
rea
()
==
2
,
"
Passed!
"
);
assert
.
ok
(
a
.
getA
rea
()
==
2
,
"
Passed!
"
);
// colinear triangle.
var
a
=
new
Triangle
(
new
Vector3
(
2
,
0
,
0
),
new
Vector3
(
0
,
0
,
0
),
new
Vector3
(
3
,
0
,
0
)
);
assert
.
ok
(
a
.
a
rea
()
==
0
,
"
Passed!
"
);
assert
.
ok
(
a
.
getA
rea
()
==
0
,
"
Passed!
"
);
}
);
QUnit
.
test
(
"
m
idpoint
"
,
(
assert
)
=>
{
QUnit
.
test
(
"
getM
idpoint
"
,
(
assert
)
=>
{
var
a
=
new
Triangle
();
var
midpoint
=
new
Vector3
();
assert
.
ok
(
a
.
midpoint
().
equals
(
new
Vector3
(
0
,
0
,
0
)
),
"
Passed!
"
);
a
.
getMidpoint
(
midpoint
);
assert
.
ok
(
midpoint
.
equals
(
new
Vector3
(
0
,
0
,
0
)
),
"
Passed!
"
);
var
a
=
new
Triangle
(
new
Vector3
(
0
,
0
,
0
),
new
Vector3
(
1
,
0
,
0
),
new
Vector3
(
0
,
1
,
0
)
);
assert
.
ok
(
a
.
midpoint
().
equals
(
new
Vector3
(
1
/
3
,
1
/
3
,
0
)
),
"
Passed!
"
);
a
.
getMidpoint
(
midpoint
);
assert
.
ok
(
midpoint
.
equals
(
new
Vector3
(
1
/
3
,
1
/
3
,
0
)
),
"
Passed!
"
);
var
a
=
new
Triangle
(
new
Vector3
(
2
,
0
,
0
),
new
Vector3
(
0
,
0
,
0
),
new
Vector3
(
0
,
0
,
2
)
);
assert
.
ok
(
a
.
midpoint
().
equals
(
new
Vector3
(
2
/
3
,
0
,
2
/
3
)
),
"
Passed!
"
);
a
.
getMidpoint
(
midpoint
);
assert
.
ok
(
midpoint
.
equals
(
new
Vector3
(
2
/
3
,
0
,
2
/
3
)
),
"
Passed!
"
);
}
);
QUnit
.
test
(
"
n
ormal
"
,
(
assert
)
=>
{
QUnit
.
test
(
"
getN
ormal
"
,
(
assert
)
=>
{
var
a
=
new
Triangle
();
var
normal
=
new
Vector3
();
assert
.
ok
(
a
.
normal
().
equals
(
new
Vector3
(
0
,
0
,
0
)
),
"
Passed!
"
);
a
.
getNormal
(
normal
);
assert
.
ok
(
normal
.
equals
(
new
Vector3
(
0
,
0
,
0
)
),
"
Passed!
"
);
var
a
=
new
Triangle
(
new
Vector3
(
0
,
0
,
0
),
new
Vector3
(
1
,
0
,
0
),
new
Vector3
(
0
,
1
,
0
)
);
assert
.
ok
(
a
.
normal
().
equals
(
new
Vector3
(
0
,
0
,
1
)
),
"
Passed!
"
);
a
.
getNormal
(
normal
);
assert
.
ok
(
normal
.
equals
(
new
Vector3
(
0
,
0
,
1
)
),
"
Passed!
"
);
var
a
=
new
Triangle
(
new
Vector3
(
2
,
0
,
0
),
new
Vector3
(
0
,
0
,
0
),
new
Vector3
(
0
,
0
,
2
)
);
assert
.
ok
(
a
.
normal
().
equals
(
new
Vector3
(
0
,
1
,
0
)
),
"
Passed!
"
);
a
.
getNormal
(
normal
);
assert
.
ok
(
normal
.
equals
(
new
Vector3
(
0
,
1
,
0
)
),
"
Passed!
"
);
}
);
QUnit
.
test
(
"
p
lane
"
,
(
assert
)
=>
{
QUnit
.
test
(
"
getP
lane
"
,
(
assert
)
=>
{
var
a
=
new
Triangle
();
assert
.
notOk
(
isNaN
(
a
.
plane
().
distanceToPoint
(
a
.
a
)
),
"
Passed!
"
);
assert
.
notOk
(
isNaN
(
a
.
plane
().
distanceToPoint
(
a
.
b
)
),
"
Passed!
"
);
assert
.
notOk
(
isNaN
(
a
.
plane
().
distanceToPoint
(
a
.
c
)
),
"
Passed!
"
);
assert
.
notPropEqual
(
a
.
plane
().
normal
,
{
var
plane
=
new
Plane
();
var
normal
=
new
Vector3
();
a
.
getPlane
(
plane
);
assert
.
notOk
(
isNaN
(
plane
.
distanceToPoint
(
a
.
a
)
),
"
Passed!
"
);
assert
.
notOk
(
isNaN
(
plane
.
distanceToPoint
(
a
.
b
)
),
"
Passed!
"
);
assert
.
notOk
(
isNaN
(
plane
.
distanceToPoint
(
a
.
c
)
),
"
Passed!
"
);
assert
.
notPropEqual
(
plane
.
normal
,
{
x
:
NaN
,
y
:
NaN
,
z
:
NaN
},
"
Passed!
"
);
var
a
=
new
Triangle
(
new
Vector3
(
0
,
0
,
0
),
new
Vector3
(
1
,
0
,
0
),
new
Vector3
(
0
,
1
,
0
)
);
assert
.
ok
(
a
.
plane
().
distanceToPoint
(
a
.
a
)
==
0
,
"
Passed!
"
);
assert
.
ok
(
a
.
plane
().
distanceToPoint
(
a
.
b
)
==
0
,
"
Passed!
"
);
assert
.
ok
(
a
.
plane
().
distanceToPoint
(
a
.
c
)
==
0
,
"
Passed!
"
);
assert
.
ok
(
a
.
plane
().
normal
.
equals
(
a
.
normal
()
),
"
Passed!
"
);
a
.
getPlane
(
plane
);
a
.
getNormal
(
normal
);
assert
.
ok
(
plane
.
distanceToPoint
(
a
.
a
)
==
0
,
"
Passed!
"
);
assert
.
ok
(
plane
.
distanceToPoint
(
a
.
b
)
==
0
,
"
Passed!
"
);
assert
.
ok
(
plane
.
distanceToPoint
(
a
.
c
)
==
0
,
"
Passed!
"
);
assert
.
ok
(
plane
.
normal
.
equals
(
normal
),
"
Passed!
"
);
var
a
=
new
Triangle
(
new
Vector3
(
2
,
0
,
0
),
new
Vector3
(
0
,
0
,
0
),
new
Vector3
(
0
,
0
,
2
)
);
assert
.
ok
(
a
.
plane
().
distanceToPoint
(
a
.
a
)
==
0
,
"
Passed!
"
);
assert
.
ok
(
a
.
plane
().
distanceToPoint
(
a
.
b
)
==
0
,
"
Passed!
"
);
assert
.
ok
(
a
.
plane
().
distanceToPoint
(
a
.
c
)
==
0
,
"
Passed!
"
);
assert
.
ok
(
a
.
plane
().
normal
.
clone
().
normalize
().
equals
(
a
.
normal
()
),
"
Passed!
"
);
a
.
getPlane
(
plane
);
a
.
getNormal
(
normal
);
assert
.
ok
(
plane
.
distanceToPoint
(
a
.
a
)
==
0
,
"
Passed!
"
);
assert
.
ok
(
plane
.
distanceToPoint
(
a
.
b
)
==
0
,
"
Passed!
"
);
assert
.
ok
(
plane
.
distanceToPoint
(
a
.
c
)
==
0
,
"
Passed!
"
);
assert
.
ok
(
plane
.
normal
.
clone
().
normalize
().
equals
(
normal
),
"
Passed!
"
);
}
);
QUnit
.
test
(
"
barycoordFromPoint
"
,
(
assert
)
=>
{
QUnit
.
test
(
"
getBarycoord
"
,
(
assert
)
=>
{
var
a
=
new
Triangle
();
var
bad
=
new
Vector3
(
-
2
,
-
1
,
-
1
);
var
barycoord
=
new
Vector3
();
var
midpoint
=
new
Vector3
();
assert
.
ok
(
a
.
barycoordFromPoint
(
a
.
a
).
equals
(
bad
),
"
Passed!
"
);
assert
.
ok
(
a
.
barycoordFromPoint
(
a
.
b
).
equals
(
bad
),
"
Passed!
"
);
assert
.
ok
(
a
.
barycoordFromPoint
(
a
.
c
).
equals
(
bad
),
"
Passed!
"
);
a
.
getBarycoord
(
a
.
a
,
barycoord
);
assert
.
ok
(
barycoord
.
equals
(
bad
),
"
Passed!
"
);
a
.
getBarycoord
(
a
.
b
,
barycoord
);
assert
.
ok
(
barycoord
.
equals
(
bad
),
"
Passed!
"
);
a
.
getBarycoord
(
a
.
c
,
barycoord
);
assert
.
ok
(
barycoord
.
equals
(
bad
),
"
Passed!
"
);
var
a
=
new
Triangle
(
new
Vector3
(
0
,
0
,
0
),
new
Vector3
(
1
,
0
,
0
),
new
Vector3
(
0
,
1
,
0
)
);
assert
.
ok
(
a
.
barycoordFromPoint
(
a
.
a
).
equals
(
new
Vector3
(
1
,
0
,
0
)
),
"
Passed!
"
);
assert
.
ok
(
a
.
barycoordFromPoint
(
a
.
b
).
equals
(
new
Vector3
(
0
,
1
,
0
)
),
"
Passed!
"
);
assert
.
ok
(
a
.
barycoordFromPoint
(
a
.
c
).
equals
(
new
Vector3
(
0
,
0
,
1
)
),
"
Passed!
"
);
assert
.
ok
(
a
.
barycoordFromPoint
(
a
.
midpoint
()
).
distanceTo
(
new
Vector3
(
1
/
3
,
1
/
3
,
1
/
3
)
)
<
0.0001
,
"
Passed!
"
);
a
.
getMidpoint
(
midpoint
);
a
.
getBarycoord
(
a
.
a
,
barycoord
);
assert
.
ok
(
barycoord
.
equals
(
new
Vector3
(
1
,
0
,
0
)
),
"
Passed!
"
);
a
.
getBarycoord
(
a
.
b
,
barycoord
);
assert
.
ok
(
barycoord
.
equals
(
new
Vector3
(
0
,
1
,
0
)
),
"
Passed!
"
);
a
.
getBarycoord
(
a
.
c
,
barycoord
);
assert
.
ok
(
barycoord
.
equals
(
new
Vector3
(
0
,
0
,
1
)
),
"
Passed!
"
);
a
.
getBarycoord
(
midpoint
,
barycoord
);
assert
.
ok
(
barycoord
.
distanceTo
(
new
Vector3
(
1
/
3
,
1
/
3
,
1
/
3
)
)
<
0.0001
,
"
Passed!
"
);
var
a
=
new
Triangle
(
new
Vector3
(
2
,
0
,
0
),
new
Vector3
(
0
,
0
,
0
),
new
Vector3
(
0
,
0
,
2
)
);
assert
.
ok
(
a
.
barycoordFromPoint
(
a
.
a
).
equals
(
new
Vector3
(
1
,
0
,
0
)
),
"
Passed!
"
);
assert
.
ok
(
a
.
barycoordFromPoint
(
a
.
b
).
equals
(
new
Vector3
(
0
,
1
,
0
)
),
"
Passed!
"
);
assert
.
ok
(
a
.
barycoordFromPoint
(
a
.
c
).
equals
(
new
Vector3
(
0
,
0
,
1
)
),
"
Passed!
"
);
assert
.
ok
(
a
.
barycoordFromPoint
(
a
.
midpoint
()
).
distanceTo
(
new
Vector3
(
1
/
3
,
1
/
3
,
1
/
3
)
)
<
0.0001
,
"
Passed!
"
);
a
.
getMidpoint
(
midpoint
);
a
.
getBarycoord
(
a
.
a
,
barycoord
);
assert
.
ok
(
barycoord
.
equals
(
new
Vector3
(
1
,
0
,
0
)
),
"
Passed!
"
);
a
.
getBarycoord
(
a
.
b
,
barycoord
);
assert
.
ok
(
barycoord
.
equals
(
new
Vector3
(
0
,
1
,
0
)
),
"
Passed!
"
);
a
.
getBarycoord
(
a
.
c
,
barycoord
);
assert
.
ok
(
barycoord
.
equals
(
new
Vector3
(
0
,
0
,
1
)
),
"
Passed!
"
);
a
.
getBarycoord
(
midpoint
,
barycoord
);
assert
.
ok
(
barycoord
.
distanceTo
(
new
Vector3
(
1
/
3
,
1
/
3
,
1
/
3
)
)
<
0.0001
,
"
Passed!
"
);
}
);
QUnit
.
test
(
"
containsPoint
"
,
(
assert
)
=>
{
var
a
=
new
Triangle
();
var
midpoint
=
new
Vector3
();
assert
.
ok
(
!
a
.
containsPoint
(
a
.
a
),
"
Passed!
"
);
assert
.
ok
(
!
a
.
containsPoint
(
a
.
b
),
"
Passed!
"
);
assert
.
ok
(
!
a
.
containsPoint
(
a
.
c
),
"
Passed!
"
);
var
a
=
new
Triangle
(
new
Vector3
(
0
,
0
,
0
),
new
Vector3
(
1
,
0
,
0
),
new
Vector3
(
0
,
1
,
0
)
);
a
.
getMidpoint
(
midpoint
);
assert
.
ok
(
a
.
containsPoint
(
a
.
a
),
"
Passed!
"
);
assert
.
ok
(
a
.
containsPoint
(
a
.
b
),
"
Passed!
"
);
assert
.
ok
(
a
.
containsPoint
(
a
.
c
),
"
Passed!
"
);
assert
.
ok
(
a
.
containsPoint
(
a
.
midpoint
()
),
"
Passed!
"
);
assert
.
ok
(
a
.
containsPoint
(
midpoint
),
"
Passed!
"
);
assert
.
ok
(
!
a
.
containsPoint
(
new
Vector3
(
-
1
,
-
1
,
-
1
)
),
"
Passed!
"
);
var
a
=
new
Triangle
(
new
Vector3
(
2
,
0
,
0
),
new
Vector3
(
0
,
0
,
0
),
new
Vector3
(
0
,
0
,
2
)
);
a
.
getMidpoint
(
midpoint
);
assert
.
ok
(
a
.
containsPoint
(
a
.
a
),
"
Passed!
"
);
assert
.
ok
(
a
.
containsPoint
(
a
.
b
),
"
Passed!
"
);
assert
.
ok
(
a
.
containsPoint
(
a
.
c
),
"
Passed!
"
);
assert
.
ok
(
a
.
containsPoint
(
a
.
midpoint
()
),
"
Passed!
"
);
assert
.
ok
(
a
.
containsPoint
(
midpoint
),
"
Passed!
"
);
assert
.
ok
(
!
a
.
containsPoint
(
new
Vector3
(
-
1
,
-
1
,
-
1
)
),
"
Passed!
"
);
}
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录