Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
radix
Commits
d6666f46
Commit
d6666f46
authored
Jul 13, 2016
by
LEFEBVREJP email
Browse files
Adding cspanf to radixmath/util for dealing with periodic intervals
parent
cc83c067
Changes
3
Hide whitespace changes
Inline
Side-by-side
radixmath/tests/tstUtil.cc
View file @
d6666f46
...
...
@@ -4,6 +4,34 @@
#include
"radixmath/util.hh"
using
namespace
radix
;
TEST
(
radix
,
cspanf
)
{
Real
lon
=
-
190
;
Real
v
=
cspanf
(
lon
,
-
180
,
180
);
EXPECT_FLOAT_EQ
(
170
,
v
);
lon
=
190
;
v
=
cspanf
(
lon
,
-
180
,
180
);
EXPECT_FLOAT_EQ
(
v
,
-
170
);
lon
=
360
;
v
=
cspanf
(
lon
,
-
180
,
180
);
EXPECT_FLOAT_EQ
(
v
,
0
);
lon
=
-
360
;
v
=
cspanf
(
lon
,
-
180
,
180
);
EXPECT_FLOAT_EQ
(
v
,
0
);
Real
lat
=
-
100
;
v
=
cspanf
(
lat
,
-
90
,
90
);
EXPECT_FLOAT_EQ
(
80
,
v
);
lat
=
100
;
v
=
cspanf
(
lat
,
-
90
,
90
);
EXPECT_FLOAT_EQ
(
-
80
,
v
);
lat
=
180
;
v
=
cspanf
(
lat
,
-
90
,
90
);
EXPECT_FLOAT_EQ
(
v
,
0
);
lat
=
-
180
;
v
=
cspanf
(
lat
,
-
90
,
90
);
EXPECT_FLOAT_EQ
(
v
,
0
);
}
TEST
(
radix
,
greatCircleDistance
){
{
// Quadrant 2 north west hemisphere
double
delta
=
0.05
;
...
...
radixmath/util.cc
View file @
d6666f46
...
...
@@ -152,4 +152,19 @@ Real cylinderVolume(Real r, Real h)
return
(
PI
*
std
::
pow
(
r
,
2
)
*
h
);
}
Real
cspanf
(
Real
value
,
Real
begin
,
Real
end
)
{
Real
first
=
0.0
,
last
=
0.0
;
first
=
std
::
min
(
begin
,
end
);
last
=
std
::
max
(
begin
,
end
);
value
=
std
::
fmod
(
value
-
first
,
last
-
first
);
if
(
value
<=
0
)
{
return
value
+
last
;
}
else
{
return
value
+
first
;
}
}
}
// namespace radix
radixmath/util.hh
View file @
d6666f46
...
...
@@ -16,6 +16,18 @@
namespace
radix
{
/**
* @brief cspanf returns a value in the interval (begin,end]
* This function is used to reduce periodic variables to a standard range.
* It adjusts for the behaviour of the mod function which provides positive results
* for position input and negative results for negative input.
* @param value number to be reduced to the span
* @param begin first value of the span
* @param end last value of the span
* @return Real the reduced value
*/
Real
cspanf
(
Real
value
,
Real
begin
,
Real
end
);
/**
* @brief haversine The Haversine formula for calculating great-circle
* @param lat1
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment