Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
isc_physics
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
Show more breadcrumbs
orestis.malaspin
isc_physics
Commits
4416c853
Commit
4416c853
authored
4 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
added normalize
parent
99046854
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#12138
passed
4 years ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
travail_pratique/vec2/tests/vec2_tests.c
+25
-0
25 additions, 0 deletions
travail_pratique/vec2/tests/vec2_tests.c
travail_pratique/vec2/vec2.c
+6
-0
6 additions, 0 deletions
travail_pratique/vec2/vec2.c
travail_pratique/vec2/vec2.h
+2
-0
2 additions, 0 deletions
travail_pratique/vec2/vec2.h
with
33 additions
and
0 deletions
travail_pratique/vec2/tests/vec2_tests.c
+
25
−
0
View file @
4416c853
...
...
@@ -124,6 +124,30 @@ MU_TEST(test_vec2_norm) {
);
}
MU_TEST
(
test_vec2_normalize
)
{
mu_assert
(
vec2_is_approx_equal
(
vec2_normalize
(
e_x
),
e_x
,
MINUNIT_EPSILON
),
"||e_x||=1 => normalize(e_x)=e_x"
);
mu_assert
(
vec2_is_approx_equal
(
vec2_normalize
(
e_y
),
e_y
,
MINUNIT_EPSILON
),
"||e_y||=1 => normalize(e_y)=e_y"
);
mu_assert
(
vec2_is_approx_equal
(
vec2_normalize
(
four_two
),
vec2_mul
(
1
.
0
/
sqrt
(
20
.
0
),
four_two
),
MINUNIT_EPSILON
),
"||v|| = ||(4, 2)|| = sqrt(20) => normalize(v) = 1/sqrt(20) * (4, 2)"
);
mu_assert_double_eq
(
vec2_norm
(
vec2_normalize
(
four_two
)),
1
.
0
);
}
MU_TEST_SUITE
(
test_suite
)
{
MU_SUITE_CONFIGURE
(
&
test_setup
,
&
test_teardown
);
...
...
@@ -134,6 +158,7 @@ MU_TEST_SUITE(test_suite) {
MU_RUN_TEST
(
test_vec2_mul
);
MU_RUN_TEST
(
test_vec2_dot
);
MU_RUN_TEST
(
test_vec2_norm
);
MU_RUN_TEST
(
test_vec2_normalize
);
}
int
main
()
{
...
...
This diff is collapsed.
Click to expand it.
travail_pratique/vec2/vec2.c
+
6
−
0
View file @
4416c853
...
...
@@ -40,6 +40,12 @@ double vec2_norm(vec2 v) {
return
sqrt
(
vec2_norm_sqr
(
v
));
}
vec2
vec2_normalize
(
vec2
v
)
{
double
norm
=
vec2_norm
(
v
);
return
vec2_mul
(
1
.
0
/
norm
,
v
);
}
bool
vec2_is_approx_equal
(
vec2
lhs
,
vec2
rhs
,
double
eps
)
{
return
vec2_norm
(
vec2_sub
(
lhs
,
rhs
))
<
eps
;
}
...
...
This diff is collapsed.
Click to expand it.
travail_pratique/vec2/vec2.h
+
2
−
0
View file @
4416c853
...
...
@@ -21,6 +21,8 @@ double vec2_norm_sqr(vec2 v);
double
vec2_norm
(
vec2
v
);
vec2
vec2_normalize
(
vec2
v
);
bool
vec2_is_approx_equal
(
vec2
lhs
,
vec2
rhs
,
double
eps
);
void
vec2_print
(
vec2
v
);
...
...
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