From 1d4333ebc4bf941c69261db7a0316c5b9ae894bc Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 3 Nov 2021 16:54:01 -0600 Subject: [PATCH 1/2] Replace INFINITY by std::numeric_limits. --- source/features/fault.cc | 6 ++-- source/features/subducting_plate.cc | 6 ++-- source/utilities.cc | 24 +++++++------- tests/unit_tests/unit_test_world_builder.cc | 36 ++++++++++----------- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/source/features/fault.cc b/source/features/fault.cc index 7222b34b2..204ddcaea 100644 --- a/source/features/fault.cc +++ b/source/features/fault.cc @@ -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::infinity() || (distance_along_plane) < std::numeric_limits::infinity()) { // We want to do both section (horizontal) and segment (vertical) interpolation. @@ -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::infinity() || (distance_along_plane) < std::numeric_limits::infinity()) { // We want to do both section (horizontal) and segment (vertical) interpolation. @@ -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::infinity() || (distance_along_plane) < std::numeric_limits::infinity()) { // We want to do both section (horizontal) and segment (vertical) interpolation. diff --git a/source/features/subducting_plate.cc b/source/features/subducting_plate.cc index d65d13775..0baa6a476 100644 --- a/source/features/subducting_plate.cc +++ b/source/features/subducting_plate.cc @@ -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::infinity() || (distance_along_plane) < std::numeric_limits::infinity()) { // We want to do both section (horizontal) and segment (vertical) interpolation. // first for thickness @@ -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::infinity() || (distance_along_plane) < std::numeric_limits::infinity()) { // We want to do both section (horizontal) and segment (vertical) interpolation. // first for thickness @@ -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::infinity() || (distance_along_plane) < std::numeric_limits::infinity()) { // We want to do both section (horizontal) and segment (vertical) interpolation. // first for thickness diff --git a/source/utilities.cc b/source/utilities.cc index b5c274e7e..8bbd03aa6 100644 --- a/source/utilities.cc +++ b/source/utilities.cc @@ -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::infinity(); + double new_distance = std::numeric_limits::infinity(); + double along_plane_distance = std::numeric_limits::infinity(); + double new_along_plane_distance = std::numeric_limits::infinity(); + double new_depth_reference_surface = std::numeric_limits::infinity(); const CoordinateSystem natural_coordinate_system = coordinate_system->natural_coordinate_system(); const bool bool_cartesian = natural_coordinate_system == cartesian; @@ -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::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::infinity(); // or NAN? + double fraction_CPL_P1P2 = std::numeric_limits::infinity(); bool continue_computation = false; if (interpolation_type != InterpolationType::ContinuousMonotoneSpline) @@ -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::infinity() && fraction_CPL_P1P2_strict >= 0. && fraction_CPL_P1P2_strict <= 1.); fraction_CPL_P1P2 = global_x_list[i_section_min_distance] - static_cast(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; @@ -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::infinity(); + new_along_plane_distance = std::numeric_limits::infinity(); + new_depth_reference_surface = std::numeric_limits::infinity(); } else { diff --git a/tests/unit_tests/unit_test_world_builder.cc b/tests/unit_tests/unit_test_world_builder.cc index 7e0fc4ead..0971dba5d 100644 --- a/tests/unit_tests/unit_test_world_builder.cc +++ b/tests/unit_tests/unit_test_world_builder.cc @@ -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(distance_from_planes.distance_from_plane == std::numeric_limits::infinity()); + CHECK(distance_from_planes.distance_along_plane == std::numeric_limits::infinity()); 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)); @@ -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(distance_from_planes.distance_from_plane == std::numeric_limits::infinity()); + CHECK(distance_from_planes.distance_along_plane == std::numeric_limits::infinity()); 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)); @@ -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(distance_from_planes.distance_from_plane == std::numeric_limits::infinity()); + CHECK(distance_from_planes.distance_along_plane == std::numeric_limits::infinity()); 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)); @@ -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(distance_from_planes.distance_from_plane == std::numeric_limits::infinity()); + CHECK(distance_from_planes.distance_along_plane == std::numeric_limits::infinity()); 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)); @@ -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(distance_from_planes.distance_from_plane == std::numeric_limits::infinity()); + CHECK(distance_from_planes.distance_along_plane == std::numeric_limits::infinity()); 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)); @@ -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(distance_from_planes.distance_from_plane == std::numeric_limits::infinity()); + CHECK(distance_from_planes.distance_along_plane == std::numeric_limits::infinity()); 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)); @@ -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(distance_from_planes.distance_from_plane == std::numeric_limits::infinity()); + CHECK(distance_from_planes.distance_along_plane == std::numeric_limits::infinity()); 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)); @@ -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(distance_from_planes.distance_from_plane == std::numeric_limits::infinity()); + CHECK(distance_from_planes.distance_along_plane == std::numeric_limits::infinity()); 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)); @@ -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(distance_from_planes.distance_from_plane == std::numeric_limits::infinity()); + CHECK(distance_from_planes.distance_along_plane == std::numeric_limits::infinity()); 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)); From 6ab538b19291219513a7ec2a661c45397add593e Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 3 Nov 2021 17:08:32 -0600 Subject: [PATCH 2/2] Replace comparison with floating point numbers. --- tests/unit_tests/unit_test_world_builder.cc | 36 ++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/unit_tests/unit_test_world_builder.cc b/tests/unit_tests/unit_test_world_builder.cc index 0971dba5d..574449676 100644 --- a/tests/unit_tests/unit_test_world_builder.cc +++ b/tests/unit_tests/unit_test_world_builder.cc @@ -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 == std::numeric_limits::infinity()); - CHECK(distance_from_planes.distance_along_plane == std::numeric_limits::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)); @@ -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 == std::numeric_limits::infinity()); - CHECK(distance_from_planes.distance_along_plane == std::numeric_limits::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)); @@ -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 == std::numeric_limits::infinity()); - CHECK(distance_from_planes.distance_along_plane == std::numeric_limits::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)); @@ -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 == std::numeric_limits::infinity()); - CHECK(distance_from_planes.distance_along_plane == std::numeric_limits::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)); @@ -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 == std::numeric_limits::infinity()); - CHECK(distance_from_planes.distance_along_plane == std::numeric_limits::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)); @@ -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 == std::numeric_limits::infinity()); - CHECK(distance_from_planes.distance_along_plane == std::numeric_limits::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)); @@ -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 == std::numeric_limits::infinity()); - CHECK(distance_from_planes.distance_along_plane == std::numeric_limits::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)); @@ -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 == std::numeric_limits::infinity()); - CHECK(distance_from_planes.distance_along_plane == std::numeric_limits::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)); @@ -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 == std::numeric_limits::infinity()); - CHECK(distance_from_planes.distance_along_plane == std::numeric_limits::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));