Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
AmpScan
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Joshua Steer
AmpScan
Commits
29e8836c
Commit
29e8836c
authored
5 years ago
by
jack-parsons
Browse files
Options
Downloads
Patches
Plain Diff
Adding tests for flip and rotMatrix.
Added validation to both flip and rotMatrix.
parent
43586e1e
Branches
Branches containing commit
No related tags found
1 merge request
!23
Merge in Jack's changes
Pipeline
#860
passed
5 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
AmpScan/core.py
+29
-6
29 additions, 6 deletions
AmpScan/core.py
tests/test_core.py
+45
-0
45 additions, 0 deletions
tests/test_core.py
with
74 additions
and
6 deletions
AmpScan/core.py
+
29
−
6
View file @
29e8836c
...
@@ -350,6 +350,11 @@ class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin):
...
@@ -350,6 +350,11 @@ class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin):
>>>
ang
=
[
np
.
pi
/
2
,
-
np
.
pi
/
4
,
np
.
pi
/
3
]
>>>
ang
=
[
np
.
pi
/
2
,
-
np
.
pi
/
4
,
np
.
pi
/
3
]
>>>
amp
.
rotateAng
(
ang
,
ang
=
'
rad
'
)
>>>
amp
.
rotateAng
(
ang
,
ang
=
'
rad
'
)
"""
"""
# Check that ang is valid
if
ang
not
in
(
'
rad
'
,
'
deg
'
):
raise
ValueError
(
"
Ang expected
'
rad
'
or
'
deg
'
but {} was found
"
.
format
(
ang
))
if
isinstance
(
rot
,
(
tuple
,
list
,
np
.
ndarray
)):
if
isinstance
(
rot
,
(
tuple
,
list
,
np
.
ndarray
)):
R
=
self
.
rotMatrix
(
rot
,
ang
)
R
=
self
.
rotMatrix
(
rot
,
ang
)
self
.
rotate
(
R
,
norms
)
self
.
rotate
(
R
,
norms
)
...
@@ -423,7 +428,7 @@ class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin):
...
@@ -423,7 +428,7 @@ class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin):
rot: array_like
rot: array_like
Rotation around [x, y, z]
Rotation around [x, y, z]
ang: str, default
'
rad
'
ang: str, default
'
rad
'
Specif
t
if the Euler angles are in degrees or radians
Specif
y
if the Euler angles are in degrees or radians
Returns
Returns
-------
-------
...
@@ -431,8 +436,20 @@ class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin):
...
@@ -431,8 +436,20 @@ class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin):
The calculated 3x3 rotation matrix
The calculated 3x3 rotation matrix
"""
"""
# Check that rot is valid
if
not
isinstance
(
rot
,
(
tuple
,
list
,
np
.
ndarray
)):
raise
TypeError
(
"
Expecting array-like rotation, but found:
"
+
type
(
rot
))
elif
len
(
rot
)
!=
3
:
raise
ValueError
(
"
Expecting 3 arguments but found: {}
"
.
format
(
len
(
rot
)))
# Check that ang is valid
if
ang
not
in
(
'
rad
'
,
'
deg
'
):
raise
ValueError
(
"
Ang expected
'
rad
'
or
'
deg
'
but {} was found
"
.
format
(
ang
))
if
ang
==
'
deg
'
:
if
ang
==
'
deg
'
:
rot
=
np
.
deg2rad
(
rot
)
rot
=
np
.
deg2rad
(
rot
)
[
angx
,
angy
,
angz
]
=
rot
[
angx
,
angy
,
angz
]
=
rot
Rx
=
np
.
array
([[
1
,
0
,
0
],
Rx
=
np
.
array
([[
1
,
0
,
0
],
[
0
,
np
.
cos
(
angx
),
-
np
.
sin
(
angx
)],
[
0
,
np
.
cos
(
angx
),
-
np
.
sin
(
angx
)],
...
@@ -456,8 +473,14 @@ class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin):
...
@@ -456,8 +473,14 @@ class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin):
The axis in which to flip the mesh
The axis in which to flip the mesh
"""
"""
self
.
vert
[:,
axis
]
*=
-
1.0
if
isinstance
(
axis
,
int
):
# Switch face order to normals face same direction
if
0
<=
axis
<
3
:
# Check axis is between 0-2
self
.
faces
[:,
[
1
,
2
]]
=
self
.
faces
[:,
[
2
,
1
]]
self
.
vert
[:,
axis
]
*=
-
1.0
self
.
calcNorm
()
# Switch face order to normals face same direction
self
.
calcVNorm
()
self
.
faces
[:,
[
1
,
2
]]
=
self
.
faces
[:,
[
2
,
1
]]
self
.
calcNorm
()
self
.
calcVNorm
()
else
:
raise
ValueError
(
"
Expected axis to be within range 0-2 but found: {}
"
.
format
(
axis
))
else
:
raise
TypeError
(
"
Expected axis to be int, but found: {}
"
.
format
(
type
(
axis
)))
This diff is collapsed.
Click to expand it.
tests/test_core.py
+
45
−
0
View file @
29e8836c
...
@@ -54,6 +54,12 @@ class TestCore(unittest.TestCase):
...
@@ -54,6 +54,12 @@ class TestCore(unittest.TestCase):
with
self
.
assertRaises
(
TypeError
):
with
self
.
assertRaises
(
TypeError
):
self
.
amp
.
rotateAng
(
dict
())
self
.
amp
.
rotateAng
(
dict
())
# Tests that incorrect number of elements causes ValueError
with
self
.
assertRaises
(
ValueError
):
self
.
amp
.
rotateAng
(
rot
,
"
test
"
)
with
self
.
assertRaises
(
ValueError
):
self
.
amp
.
rotateAng
(
rot
,
[])
def
test_rotate
(
self
):
def
test_rotate
(
self
):
"""
Tests the rotate method of AmpObject
"""
"""
Tests the rotate method of AmpObject
"""
# A test rotation and translation using list
# A test rotation and translation using list
...
@@ -121,6 +127,45 @@ class TestCore(unittest.TestCase):
...
@@ -121,6 +127,45 @@ class TestCore(unittest.TestCase):
with
self
.
assertRaises
(
TypeError
):
with
self
.
assertRaises
(
TypeError
):
self
.
amp
.
rigidTransform
(
R
=
7
)
self
.
amp
.
rigidTransform
(
R
=
7
)
def
test_rot_matrix
(
self
):
"""
Tests the rotMatrix method in AmpObject
"""
# Tests that a transformation by 0 in all axis is 0 matrix
all
(
self
.
amp
.
rotMatrix
([
0
,
0
,
0
])[
y
][
x
]
==
0
for
x
in
range
(
3
)
for
y
in
range
(
3
))
expected
=
[[
1
,
0
,
0
],
[
0
,
np
.
sqrt
(
3
)
/
2
,
1
/
2
],
[
0
,
-
1
/
2
,
np
.
sqrt
(
3
)
/
2
]]
all
(
self
.
amp
.
rotMatrix
([
np
.
pi
/
6
,
0
,
0
])[
y
][
x
]
==
expected
[
y
][
x
]
for
x
in
range
(
3
)
for
y
in
range
(
3
))
# Tests that string passed into rot causes TypeError
with
self
.
assertRaises
(
TypeError
):
self
.
amp
.
rotMatrix
(
"
"
)
with
self
.
assertRaises
(
TypeError
):
self
.
amp
.
rotMatrix
(
dict
())
# Tests that incorrect number of elements causes ValueError
with
self
.
assertRaises
(
ValueError
):
self
.
amp
.
rotMatrix
([
0
,
1
])
with
self
.
assertRaises
(
ValueError
):
self
.
amp
.
rotMatrix
([
0
,
1
,
3
,
0
])
def
test_flip
(
self
):
"""
Tests the flip method in AmpObject
"""
# Check invalid axis types cause TypeError
with
self
.
assertRaises
(
TypeError
):
self
.
amp
.
flip
(
"
"
)
with
self
.
assertRaises
(
TypeError
):
self
.
amp
.
flip
(
dict
())
# Check invalid axis values cause ValueError
with
self
.
assertRaises
(
ValueError
):
self
.
amp
.
flip
(
-
1
)
with
self
.
assertRaises
(
ValueError
):
self
.
amp
.
flip
(
3
)
@staticmethod
@staticmethod
def
get_path
(
filename
):
def
get_path
(
filename
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment