Skip to content

Commit

Permalink
Merge pull request #363 from bangerth/infinity
Browse files Browse the repository at this point in the history
Replace INFINITY by std::numeric_limits.
  • Loading branch information
MFraters authored Nov 5, 2021
2 parents 462d2a3 + 6ab538b commit f0144eb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
6 changes: 3 additions & 3 deletions source/features/fault.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ namespace WorldBuilder
//const size_t next_segment = current_segment + 1;
const double segment_fraction = distance_from_planes.fraction_of_segment;

if (abs(distance_from_plane) < INFINITY || (distance_along_plane) < INFINITY)
if (abs(distance_from_plane) < std::numeric_limits<double>::infinity() || (distance_along_plane) < std::numeric_limits<double>::infinity())
{
// We want to do both section (horizontal) and segment (vertical) interpolation.

Expand Down Expand Up @@ -575,7 +575,7 @@ namespace WorldBuilder
//const size_t next_segment = current_segment + 1;
const double segment_fraction = distance_from_planes.fraction_of_segment;

if (abs(distance_from_plane) < INFINITY || (distance_along_plane) < INFINITY)
if (abs(distance_from_plane) < std::numeric_limits<double>::infinity() || (distance_along_plane) < std::numeric_limits<double>::infinity())
{
// We want to do both section (horizontal) and segment (vertical) interpolation.

Expand Down Expand Up @@ -714,7 +714,7 @@ namespace WorldBuilder
//const size_t next_segment = current_segment + 1;
const double segment_fraction = distance_from_planes.fraction_of_segment;

if (abs(distance_from_plane) < INFINITY || (distance_along_plane) < INFINITY)
if (abs(distance_from_plane) < std::numeric_limits<double>::infinity() || (distance_along_plane) < std::numeric_limits<double>::infinity())
{
// We want to do both section (horizontal) and segment (vertical) interpolation.

Expand Down
6 changes: 3 additions & 3 deletions source/features/subducting_plate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ namespace WorldBuilder
//const size_t next_segment = current_segment + 1;
const double segment_fraction = distance_from_planes.fraction_of_segment;

if (abs(distance_from_plane) < INFINITY || (distance_along_plane) < INFINITY)
if (abs(distance_from_plane) < std::numeric_limits<double>::infinity() || (distance_along_plane) < std::numeric_limits<double>::infinity())
{
// We want to do both section (horizontal) and segment (vertical) interpolation.
// first for thickness
Expand Down Expand Up @@ -587,7 +587,7 @@ namespace WorldBuilder
//const size_t next_segment = current_segment + 1;
const double segment_fraction = distance_from_planes.fraction_of_segment;

if (abs(distance_from_plane) < INFINITY || (distance_along_plane) < INFINITY)
if (abs(distance_from_plane) < std::numeric_limits<double>::infinity() || (distance_along_plane) < std::numeric_limits<double>::infinity())
{
// We want to do both section (horizontal) and segment (vertical) interpolation.
// first for thickness
Expand Down Expand Up @@ -722,7 +722,7 @@ namespace WorldBuilder
//const size_t next_segment = current_segment + 1;
const double segment_fraction = distance_from_planes.fraction_of_segment;

if (abs(distance_from_plane) < INFINITY || (distance_along_plane) < INFINITY)
if (abs(distance_from_plane) < std::numeric_limits<double>::infinity() || (distance_along_plane) < std::numeric_limits<double>::infinity())
{
// We want to do both section (horizontal) and segment (vertical) interpolation.
// first for thickness
Expand Down
24 changes: 12 additions & 12 deletions source/utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,11 @@ namespace WorldBuilder
WBAssertThrow(global_x_list.size() == point_list.size(), "The given global_x_list doesn't have "
"the same size as the point list. This is required.");

double distance = INFINITY;
double new_distance = INFINITY;
double along_plane_distance = INFINITY;
double new_along_plane_distance = INFINITY;
double new_depth_reference_surface = INFINITY;
double distance = std::numeric_limits<double>::infinity();
double new_distance = std::numeric_limits<double>::infinity();
double along_plane_distance = std::numeric_limits<double>::infinity();
double new_along_plane_distance = std::numeric_limits<double>::infinity();
double new_depth_reference_surface = std::numeric_limits<double>::infinity();

const CoordinateSystem natural_coordinate_system = coordinate_system->natural_coordinate_system();
const bool bool_cartesian = natural_coordinate_system == cartesian;
Expand Down Expand Up @@ -504,12 +504,12 @@ namespace WorldBuilder
"Only the depth methods none, angle_at_starting_point_with_surface and "
"angle_at_begin_segment_with_surface are implemented");

double min_distance_check_point_surface_2d_line = INFINITY;
double min_distance_check_point_surface_2d_line = std::numeric_limits<double>::infinity();
size_t i_section_min_distance = 0;
Point<2> closest_point_on_line_2d(NaN::DSNAN,NaN::DSNAN,natural_coordinate_system);
Point<2> closest_point_on_line_2d_temp(0,0,natural_coordinate_system);
double fraction_CPL_P1P2_strict = INFINITY; // or NAN?
double fraction_CPL_P1P2 = INFINITY;
double fraction_CPL_P1P2_strict = std::numeric_limits<double>::infinity(); // or NAN?
double fraction_CPL_P1P2 = std::numeric_limits<double>::infinity();

bool continue_computation = false;
if (interpolation_type != InterpolationType::ContinuousMonotoneSpline)
Expand Down Expand Up @@ -556,7 +556,7 @@ namespace WorldBuilder
}
// If the point on the line does not lay between point P1 and P2
// then ignore it. Otherwise continue.
continue_computation = (fabs(fraction_CPL_P1P2_strict) < INFINITY && fraction_CPL_P1P2_strict >= 0. && fraction_CPL_P1P2_strict <= 1.);
continue_computation = (fabs(fraction_CPL_P1P2_strict) < std::numeric_limits<double>::infinity() && fraction_CPL_P1P2_strict >= 0. && fraction_CPL_P1P2_strict <= 1.);

fraction_CPL_P1P2 = global_x_list[i_section_min_distance] - static_cast<int>(global_x_list[i_section_min_distance])
+ (global_x_list[i_section_min_distance+1]-global_x_list[i_section_min_distance]) * fraction_CPL_P1P2_strict;
Expand Down Expand Up @@ -1006,9 +1006,9 @@ namespace WorldBuilder

if (c1 < 0 || c2 < c1)
{
new_distance = INFINITY;
new_along_plane_distance = INFINITY;
new_depth_reference_surface = INFINITY;
new_distance = std::numeric_limits<double>::infinity();
new_along_plane_distance = std::numeric_limits<double>::infinity();
new_depth_reference_surface = std::numeric_limits<double>::infinity();
}
else
{
Expand Down
36 changes: 18 additions & 18 deletions tests/unit_tests/unit_test_world_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4910,8 +4910,8 @@ TEST_CASE("WorldBuilder Utilities function: distance_point_from_curved_planes ca
x_spline,
y_spline);

CHECK(distance_from_planes.distance_from_plane == INFINITY);
CHECK(distance_from_planes.distance_along_plane == INFINITY);
CHECK(std::isinf(distance_from_planes.distance_from_plane));
CHECK(std::isinf(distance_from_planes.distance_along_plane));
CHECK(distance_from_planes.fraction_of_section == Approx(0.0));
CHECK(distance_from_planes.section == Approx(0.0));
CHECK(distance_from_planes.segment == Approx(0.0));
Expand All @@ -4936,8 +4936,8 @@ TEST_CASE("WorldBuilder Utilities function: distance_point_from_curved_planes ca
x_spline,
y_spline);

CHECK(distance_from_planes.distance_from_plane == INFINITY);
CHECK(distance_from_planes.distance_along_plane == INFINITY);
CHECK(std::isinf(distance_from_planes.distance_from_plane));
CHECK(std::isinf(distance_from_planes.distance_along_plane));
CHECK(distance_from_planes.fraction_of_section == Approx(0.0));
CHECK(distance_from_planes.section == Approx(0.0));
CHECK(distance_from_planes.segment == Approx(0.0));
Expand All @@ -4964,8 +4964,8 @@ TEST_CASE("WorldBuilder Utilities function: distance_point_from_curved_planes ca
x_spline,
y_spline);

CHECK(distance_from_planes.distance_from_plane == INFINITY);
CHECK(distance_from_planes.distance_along_plane == INFINITY);
CHECK(std::isinf(distance_from_planes.distance_from_plane));
CHECK(std::isinf(distance_from_planes.distance_along_plane));
CHECK(distance_from_planes.fraction_of_section == Approx(0.0));
CHECK(distance_from_planes.section == Approx(0.0));
CHECK(distance_from_planes.segment == Approx(0.0));
Expand All @@ -4990,8 +4990,8 @@ TEST_CASE("WorldBuilder Utilities function: distance_point_from_curved_planes ca
x_spline,
y_spline);

CHECK(distance_from_planes.distance_from_plane == INFINITY);
CHECK(distance_from_planes.distance_along_plane == INFINITY);
CHECK(std::isinf(distance_from_planes.distance_from_plane));
CHECK(std::isinf(distance_from_planes.distance_along_plane));
CHECK(distance_from_planes.fraction_of_section == Approx(0.0));
CHECK(distance_from_planes.section == Approx(0.0));
CHECK(distance_from_planes.segment == Approx(0.0));
Expand Down Expand Up @@ -5365,8 +5365,8 @@ TEST_CASE("WorldBuilder Utilities function: distance_point_from_curved_planes ca
x_spline,
y_spline);

CHECK(distance_from_planes.distance_from_plane == INFINITY);
CHECK(distance_from_planes.distance_along_plane == INFINITY);
CHECK(std::isinf(distance_from_planes.distance_from_plane));
CHECK(std::isinf(distance_from_planes.distance_along_plane));
CHECK(distance_from_planes.fraction_of_section == Approx(0.0));
CHECK(distance_from_planes.section == Approx(0.0));
CHECK(distance_from_planes.segment == Approx(0.0));
Expand Down Expand Up @@ -5478,8 +5478,8 @@ TEST_CASE("WorldBuilder Utilities function: distance_point_from_curved_planes ca
x_spline,
y_spline);

CHECK(distance_from_planes.distance_from_plane == INFINITY);
CHECK(distance_from_planes.distance_along_plane == INFINITY);
CHECK(std::isinf(distance_from_planes.distance_from_plane));
CHECK(std::isinf(distance_from_planes.distance_along_plane));
CHECK(distance_from_planes.fraction_of_section == Approx(0.0));
CHECK(distance_from_planes.section == Approx(0.0));
CHECK(distance_from_planes.segment == Approx(0.0));
Expand Down Expand Up @@ -5589,8 +5589,8 @@ TEST_CASE("WorldBuilder Utilities function: distance_point_from_curved_planes ca
x_spline,
y_spline);

CHECK(distance_from_planes.distance_from_plane == INFINITY);
CHECK(distance_from_planes.distance_along_plane == INFINITY);
CHECK(std::isinf(distance_from_planes.distance_from_plane));
CHECK(std::isinf(distance_from_planes.distance_along_plane));
CHECK(distance_from_planes.fraction_of_section == Approx(0.0));
CHECK(distance_from_planes.section == Approx(0.0));
CHECK(distance_from_planes.segment == Approx(0.0));
Expand Down Expand Up @@ -5853,8 +5853,8 @@ TEST_CASE("WorldBuilder Utilities function: distance_point_from_curved_planes ca
x_spline,
y_spline);

CHECK(distance_from_planes.distance_from_plane == INFINITY);
CHECK(distance_from_planes.distance_along_plane == INFINITY);
CHECK(std::isinf(distance_from_planes.distance_from_plane));
CHECK(std::isinf(distance_from_planes.distance_along_plane));
CHECK(distance_from_planes.fraction_of_section == Approx(0.0));
CHECK(distance_from_planes.section == Approx(0.0));
CHECK(distance_from_planes.segment == Approx(0.0));
Expand Down Expand Up @@ -6441,8 +6441,8 @@ TEST_CASE("WorldBuilder Utilities function: distance_point_from_curved_planes ca
y_spline);

// checked that distanceFromPlane should be infinity (it is on the other side of the circle this with a drawing
CHECK(distance_from_planes.distance_from_plane == INFINITY);
CHECK(distance_from_planes.distance_along_plane == INFINITY);
CHECK(std::isinf(distance_from_planes.distance_from_plane));
CHECK(std::isinf(distance_from_planes.distance_along_plane));
CHECK(distance_from_planes.fraction_of_section == Approx(0.0));
CHECK(distance_from_planes.section == Approx(0.0));
CHECK(distance_from_planes.segment == Approx(0.0));
Expand Down

0 comments on commit f0144eb

Please sign in to comment.