Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
065d3dc6
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,发现更多精彩内容 >>
提交
065d3dc6
编写于
11月 23, 2015
作者:
S
simonThiele
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fist try of kicking out lodash
上级
e3283155
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
104 addition
and
45 deletion
+104
-45
test/unit/SmartComparer.js
test/unit/SmartComparer.js
+62
-22
test/unit/qunit-utils.js
test/unit/qunit-utils.js
+41
-20
test/unit/unittests_three.html
test/unit/unittests_three.html
+1
-3
未找到文件。
test/unit/SmartComparer.js
浏览文件 @
065d3dc6
...
...
@@ -9,9 +9,6 @@ function SmartComparer() {
// Diagnostic message, when comparison fails.
var
message
;
// Keys to skip during object comparison.
var
omitKeys
=
[
'
id
'
,
'
uuid
'
];
return
{
areEqual
:
areEqual
,
...
...
@@ -47,7 +44,7 @@ function SmartComparer() {
}
// Don't compare functions.
if
(
_
.
isFunction
(
val1
)
&&
_
.
isFunction
(
val2
)
)
return
true
;
if
(
isFunction
(
val1
)
&&
isFunction
(
val2
)
)
return
true
;
// Array comparison.
var
arrCmp
=
compareArrays
(
val1
,
val2
);
...
...
@@ -68,13 +65,30 @@ function SmartComparer() {
// if (JSON.stringify( val1 ) == JSON.stringify( val2 ) ) return true;
// Continue with default comparison.
if
(
_
.
isEqual
(
val1
,
val2
)
)
return
true
;
// Object differs (unknown reason).
return
makeFail
(
'
Values differ
'
,
val1
,
val2
);
}
function
isFunction
(
value
)
{
// The use of `Object#toString` avoids issues with the `typeof` operator
// in Safari 8 which returns 'object' for typed array constructors, and
// PhantomJS 1.9 which returns 'function' for `NodeList` instances.
var
tag
=
isObject
(
value
)
?
Object
.
prototype
.
toString
.
call
(
value
)
:
''
;
return
tag
==
'
[object Function]
'
||
tag
==
'
[object GeneratorFunction]
'
;
}
function
isObject
(
value
)
{
// Avoid a V8 JIT bug in Chrome 19-20.
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
var
type
=
typeof
value
;
return
!!
value
&&
(
type
==
'
object
'
||
type
==
'
function
'
);
}
function
compareArrays
(
val1
,
val2
)
{
...
...
@@ -107,8 +121,8 @@ function SmartComparer() {
function
compareObjects
(
val1
,
val2
)
{
var
isObj1
=
_
.
isObject
(
val1
);
var
isObj2
=
_
.
isObject
(
val2
);
var
isObj1
=
isObject
(
val1
);
var
isObj2
=
isObject
(
val2
);
// Compare type.
if
(
isObj1
!==
isObj2
)
return
makeFail
(
'
Values are not both objects
'
);
...
...
@@ -117,38 +131,64 @@ function SmartComparer() {
if
(
!
isObj1
)
return
undefined
;
// Compare keys.
var
keys1
=
_
(
val1
).
keys
().
difference
(
omitKeys
).
value
(
);
var
keys2
=
_
(
val2
).
keys
().
difference
(
omitKeys
).
value
(
);
var
keys1
=
Object
.
keys
(
val1
);
var
keys2
=
Object
.
keys
(
val2
);
var
missingActual
=
_
.
difference
(
keys1
,
keys2
);
var
keys1T
=
_
(
val1
).
keys
().
value
();
var
keys2T
=
_
(
val2
).
keys
().
value
();
var
missingActual
=
_
.
difference
(
keys1T
,
keys2T
);
if
(
missingActual
.
length
!==
0
)
{
console
.
log
(
missingActual
,
keys1T
,
keys2T
);
}
for
(
var
i
=
0
,
l
=
keys1
.
length
;
i
<
l
;
i
++
)
{
if
(
keys2
.
indexOf
(
keys1
[
i
])
<
0
)
{
return
makeFail
(
'
Property "
'
+
keys1
[
i
]
+
'
" is unexpected.
'
);
return
makeFail
(
'
Property "
'
+
missingActual
[
0
]
+
'
" is unexpected.
'
);
}
}
var
missingExpected
=
_
.
difference
(
keys2
,
keys1
);
if
(
missingExpected
.
length
!==
0
)
{
for
(
var
i
=
0
,
l
=
keys2
.
length
;
i
<
l
;
i
++
)
{
if
(
keys1
.
indexOf
(
keys2
[
i
])
<
0
)
{
return
makeFail
(
'
Property "
'
+
missingExpected
[
0
]
+
'
" is missing.
'
);
return
makeFail
(
'
Property "
'
+
keys2
[
i
]
+
'
" is missing.
'
);
}
}
// Keys are the same. For each key, compare content until a difference is found.
var
hadDifference
=
_
.
any
(
keys1
,
function
(
key
)
{
var
hadDifference
=
false
;
for
(
var
i
=
0
,
l
=
keys1
.
length
;
i
<
l
;
i
++
)
{
var
key
=
keys1
[
i
];
if
(
key
===
"
uuid
"
||
key
===
"
id
"
)
{
var
prop1
=
val1
[
key
];
var
prop2
=
val2
[
key
];
continue
;
}
var
prop1
=
val1
[
key
];
var
prop2
=
val2
[
key
];
// Compare property content.
var
eq
=
areEqual
(
prop1
,
prop2
);
// In case of failure, an message should already be set.
// Add context to low level message.
if
(
!
eq
)
addContext
(
'
property "
'
+
key
+
'
"
'
);
return
!
eq
;
if
(
!
eq
)
{
});
addContext
(
'
property "
'
+
key
+
'
"
'
);
hadDifference
=
true
;
}
}
return
!
hadDifference
;
...
...
test/unit/qunit-utils.js
浏览文件 @
065d3dc6
...
...
@@ -72,22 +72,31 @@ function checkGeometryJsonWriting( geom, json ) {
QUnit
.
assert
.
equalKey
(
geom
,
json
,
'
uuid
'
);
QUnit
.
assert
.
equal
(
json
.
id
,
undefined
,
"
should not persist id
"
);
var
params
=
geom
.
parameters
;
if
(
!
params
)
{
return
;
}
// All parameters from geometry should be persisted.
_
.
forOwn
(
geom
.
parameters
,
function
(
val
,
key
)
{
var
keys
=
Object
.
keys
(
params
);
for
(
var
i
=
0
,
l
=
keys
.
length
;
i
<
l
;
i
++
)
{
QUnit
.
assert
.
equalKey
(
geom
.
parameters
,
json
,
key
);
QUnit
.
assert
.
equalKey
(
params
,
json
,
keys
[
i
]
);
}
);
}
// All parameters from json should be transfered to the geometry.
// json is flat. Ignore first level json properties that are not parameters.
var
notParameters
=
[
"
metadata
"
,
"
uuid
"
,
"
type
"
];
_
.
forOwn
(
json
,
function
(
val
,
key
)
{
if
(
notParameters
.
indexOf
(
key
)
===
-
1
)
QUnit
.
assert
.
equalKey
(
geom
.
parameters
,
json
,
key
);
var
keys
=
Object
.
keys
(
json
);
for
(
var
i
=
0
,
l
=
keys
.
length
;
i
<
l
;
i
++
)
{
});
var
key
=
keys
[
i
];
if
(
notParameters
.
indexOf
(
key
)
===
-
1
)
QUnit
.
assert
.
equalKey
(
params
,
json
,
key
);
}
}
// Check parsing and reconstruction of json geometry
...
...
@@ -98,9 +107,8 @@ function checkGeometryJsonReading( json, geom ) {
var
loader
=
new
THREE
.
ObjectLoader
();
var
output
=
loader
.
parseGeometries
(
wrap
);
QUnit
.
assert
.
ok
(
output
[
geom
.
uuid
],
'
geometry matching source uuid not in output
'
);
QUnit
.
assert
.
smartEqual
(
output
[
geom
.
uuid
],
geom
,
'
Reconstruct geometry from ObjectLoader
'
);
QUnit
.
assert
.
ok
(
output
[
geom
.
uuid
],
'
geometry matching source uuid not in output
'
);
QUnit
.
assert
.
smartEqual
(
output
[
geom
.
uuid
],
geom
,
'
Reconstruct geometry from ObjectLoader
'
);
}
// Verify geom -> json -> geom
...
...
@@ -115,22 +123,35 @@ function checkGeometryJsonRoundtrip( geom ) {
// Look for undefined and NaN values in numerical fieds.
function
checkFinite
(
geom
)
{
var
isNotFinite
=
_
.
any
(
geom
.
vertices
,
function
(
v
)
{
var
allVerticesAreFinite
=
true
;
var
vertices
=
geom
.
vertices
||
[];
for
(
var
i
=
0
,
l
=
vertices
.
length
;
i
<
l
;
i
++
)
{
return
!
(
_
.
isFinite
(
v
.
x
)
||
_
.
isFinite
(
v
.
y
)
||
_
.
isFinite
(
v
.
z
)
)
;
var
v
=
geom
.
vertices
[
i
]
;
});
if
(
!
(
isFinite
(
v
.
x
)
||
isFinite
(
v
.
y
)
||
isFinite
(
v
.
z
)
)
)
{
allVerticesAreFinite
=
false
;
break
;
}
}
// TODO Buffers, normal, etc.
QUnit
.
assert
.
ok
(
isNotFinite
===
fals
e
,
"
contains non-finite coordinates
"
);
QUnit
.
assert
.
ok
(
allVerticesAreFinit
e
,
"
contains non-finite coordinates
"
);
}
// Run common geometry tests.
function
runStdGeometryTests
(
assert
,
geometries
)
{
_
.
each
(
geometries
,
function
(
geom
)
{
for
(
var
i
=
0
,
l
=
geometries
.
length
;
i
<
l
;
i
++
)
{
var
geom
=
geometries
[
i
];
checkFinite
(
geom
);
...
...
@@ -140,7 +161,7 @@ function runStdGeometryTests( assert, geometries ) {
// json round trip
checkGeometryJsonRoundtrip
(
geom
);
}
);
}
}
...
...
@@ -154,15 +175,16 @@ function runStdGeometryTests( assert, geometries ) {
// Run common light tests.
function
runStdLightTests
(
assert
,
lights
)
{
_
.
each
(
lights
,
function
(
light
)
{
for
(
var
i
=
0
,
l
=
lights
.
length
;
i
<
l
;
i
++
)
{
const
light
=
lights
[
i
];
// Clone
checkLightClone
(
light
);
// json round trip
checkLightJsonRoundtrip
(
light
);
});
}
}
...
...
@@ -209,4 +231,3 @@ function checkLightJsonRoundtrip( light ) {
checkLightJsonReading
(
json
,
light
);
}
test/unit/unittests_three.html
浏览文件 @
065d3dc6
...
...
@@ -7,6 +7,7 @@
</head>
<body>
<div
id=
"qunit"
></div>
<script
src=
"../../node_modules/lodash/index.js"
></script>
<script
src=
"qunit-1.18.0.js"
></script>
<script
src=
"qunit-utils.js"
></script>
<script
src=
"SmartComparer.js"
></script>
...
...
@@ -27,9 +28,6 @@
<script
src=
"core/InterleavedBuffer.js"
></script>
<script
src=
"core/InterleavedBufferAttribute.js"
></script>
<script
src=
"core/Raycaster.js"
></script>
<script
src=
"core/Face3.js"
></script>
<script
src=
"core/Geometry.js"
></script>
<script
src=
"core/BufferAttribute.js"
></script>
<script
src=
"core/BufferGeometry.js"
></script>
<script
src=
"core/Clock.js"
></script>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录