diff --git a/Charts/Core/vtkAxis.cxx b/Charts/Core/vtkAxis.cxx
index 4d47e16f8e21b2e1def0625c3436caff153c0b43..c5622a96d9e333a1cc1a16adf8754b1f16d2d71d 100644
--- a/Charts/Core/vtkAxis.cxx
+++ b/Charts/Core/vtkAxis.cxx
@@ -1769,11 +1769,11 @@ void vtkAxis::GenerateLogScaleTickMarks(int order, double min, double max, bool
   }
   if (min > 9.0)
   {
-    min = 1.0;
+    min = 9.0;
   }
   if (max < 1.0)
   {
-    max = 9.0;
+    max = 1.0;
   }
   if (max > 9.0)
   {
diff --git a/Common/DataModel/vtkPiecewiseFunction.cxx b/Common/DataModel/vtkPiecewiseFunction.cxx
index 53dbfb140abb3de769de504576a1a6bdd72aac67..39eb8ecc3f3b7369adddb1911264c0ae035d5a28 100644
--- a/Common/DataModel/vtkPiecewiseFunction.cxx
+++ b/Common/DataModel/vtkPiecewiseFunction.cxx
@@ -1111,7 +1111,7 @@ void vtkPiecewiseFunction::SetCustomSearchMethod(int type)
     vtkGenericWarningMacro("enum out of scope, binary search will be applied");
 
     // set to binary search because it is the most general searchMethod
-    this->Internal->CustomSearchMethod = BINARY_SEARCH;
+    type = BINARY_SEARCH;
   }
 
   this->Internal->CustomSearchMethod = static_cast<SearchMethod>(type);
diff --git a/Common/ExecutionModel/vtkImageToStructuredPoints.cxx b/Common/ExecutionModel/vtkImageToStructuredPoints.cxx
index c8f11ac0f617fc8dd50c0c69b0f899170c3f8674..64c9d2767e943e8fc3f2b9dee2e469c247cf624c 100644
--- a/Common/ExecutionModel/vtkImageToStructuredPoints.cxx
+++ b/Common/ExecutionModel/vtkImageToStructuredPoints.cxx
@@ -250,11 +250,11 @@ int vtkImageToStructuredPoints::RequestInformation(vtkInformation* vtkNotUsed(re
     {
       whole[1] = tmp[1];
     }
-    if (tmp[3] < whole[1])
+    if (tmp[3] < whole[3])
     {
       whole[3] = tmp[3];
     }
-    if (tmp[5] < whole[1])
+    if (tmp[5] < whole[5])
     {
       whole[5] = tmp[5];
     }
diff --git a/Filters/Hybrid/vtkImplicitModeller.cxx b/Filters/Hybrid/vtkImplicitModeller.cxx
index ee6f5f055dd639c28d085ca3c89aece7c3d8a46d..d7928b04e75fd75b1142a9bb92bbd964f3979b3c 100644
--- a/Filters/Hybrid/vtkImplicitModeller.cxx
+++ b/Filters/Hybrid/vtkImplicitModeller.cxx
@@ -24,6 +24,7 @@
 #include "vtkStructuredGrid.h"
 #include "vtkUnstructuredGrid.h"
 
+#include <algorithm>
 #include <cmath>
 
 VTK_ABI_NAMESPACE_BEGIN
@@ -113,9 +114,10 @@ void vtkImplicitModeller::SetCapValue(double value)
   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting CapValue to " << value);
   // clamp to between 0 and max for scalar type
   double max = this->GetScalarTypeMax(this->OutputScalarType);
-  if (this->CapValue != (value < 0 ? 0 : (value > max ? max : value)))
+  value = std::min(std::max(value, 0.0), max);
+  if (this->CapValue != value)
   {
-    this->CapValue = (value < 0 ? 0 : (value > max ? max : value));
+    this->CapValue = value;
     this->Modified();
   }
 }
diff --git a/Filters/Sources/vtkSelectionSource.cxx b/Filters/Sources/vtkSelectionSource.cxx
index 66dfd7eeb1857e1fdd7718d90383114e97e313e0..97ef0498614fcfabb73ec3c5c7944be9542adf4d 100644
--- a/Filters/Sources/vtkSelectionSource.cxx
+++ b/Filters/Sources/vtkSelectionSource.cxx
@@ -13,6 +13,7 @@
 #include "vtkStringArray.h"
 #include "vtkUnsignedIntArray.h"
 
+#include <algorithm>
 #include <set>
 #include <vector>
 
@@ -380,19 +381,12 @@ void vtkSelectionSource::SetContentType(unsigned int nodeId, int contentType)
     vtkErrorMacro("Invalid node id: " << nodeId);
     return;
   }
-  if (this->NodesInfo[nodeId]->ContentType !=
-    (contentType < vtkSelectionNode::SelectionContent::GLOBALIDS
-        ? vtkSelectionNode::SelectionContent::GLOBALIDS
-        : (contentType > vtkSelectionNode::SelectionContent::USER
-              ? vtkSelectionNode::SelectionContent::USER
-              : contentType)))
-  {
-    this->NodesInfo[nodeId]->ContentType =
-      (contentType < vtkSelectionNode::SelectionContent::GLOBALIDS
-          ? vtkSelectionNode::SelectionContent::GLOBALIDS
-          : (contentType > vtkSelectionNode::SelectionContent::USER
-                ? vtkSelectionNode::SelectionContent::USER
-                : contentType));
+  contentType =
+    std::min<int>(std::max<int>(contentType, vtkSelectionNode::SelectionContent::GLOBALIDS),
+      vtkSelectionNode::SelectionContent::USER);
+  if (this->NodesInfo[nodeId]->ContentType != contentType)
+  {
+    this->NodesInfo[nodeId]->ContentType = contentType;
     this->Modified();
   }
 }
@@ -442,11 +436,10 @@ void vtkSelectionSource::SetNumberOfLayers(unsigned int nodeId, int numberOfLaye
     vtkErrorMacro("Invalid node id: " << nodeId);
     return;
   }
-  if (this->NodesInfo[nodeId]->NumberOfLayers !=
-    (numberOfLayers < 0 ? 0 : (numberOfLayers > VTK_INT_MAX ? VTK_INT_MAX : numberOfLayers)))
+  numberOfLayers = std::min(std::max(numberOfLayers, 0), VTK_INT_MAX);
+  if (this->NodesInfo[nodeId]->NumberOfLayers != numberOfLayers)
   {
-    this->NodesInfo[nodeId]->NumberOfLayers =
-      (numberOfLayers < 0 ? 0 : (numberOfLayers > VTK_INT_MAX ? VTK_INT_MAX : numberOfLayers));
+    this->NodesInfo[nodeId]->NumberOfLayers = numberOfLayers;
     this->Modified();
   }
 }
diff --git a/IO/PostgreSQL/vtkPostgreSQLDatabase.h b/IO/PostgreSQL/vtkPostgreSQLDatabase.h
index 656a498814a91b7c0a32de6d2fbbbe374b3ca493..02b00c74fc193763d129a625e59397bb3d848dec 100644
--- a/IO/PostgreSQL/vtkPostgreSQLDatabase.h
+++ b/IO/PostgreSQL/vtkPostgreSQLDatabase.h
@@ -282,9 +282,10 @@ vtkSetStringPlusMTimeMacro(vtkPostgreSQLDatabase, ConnectOptions, URLMTime);
 inline void vtkPostgreSQLDatabase::SetServerPort(int _arg)
 {
   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting ServerPort to " << _arg);
-  if (this->ServerPort != (_arg < 0 ? 0 : (_arg > VTK_INT_MAX ? VTK_INT_MAX : _arg)))
+  _arg = std::min(std::max(_arg, 0), VTK_INT_MAX);
+  if (this->ServerPort != _arg)
   {
-    this->ServerPort = (_arg < 0 ? 0 : (_arg > VTK_INT_MAX ? VTK_INT_MAX : _arg));
+    this->ServerPort = _arg;
     this->Modified();
     this->URLMTime.Modified();
     this->Close(); // Force a re-open on next query
diff --git a/Interaction/Widgets/vtkCoordinateFrameRepresentation.cxx b/Interaction/Widgets/vtkCoordinateFrameRepresentation.cxx
index 0b0964e11c0e2717fcef2d96e01be0507dc02931..946e109e55863c6c3f74fcb0c78b769613a08f0b 100644
--- a/Interaction/Widgets/vtkCoordinateFrameRepresentation.cxx
+++ b/Interaction/Widgets/vtkCoordinateFrameRepresentation.cxx
@@ -31,6 +31,8 @@
 #include "vtkTransform.h"
 #include "vtkWindow.h"
 
+#include <algorithm>
+
 VTK_ABI_NAMESPACE_BEGIN
 vtkStandardNewMacro(vtkCoordinateFrameRepresentation);
 
@@ -337,18 +339,15 @@ int vtkCoordinateFrameRepresentation::ComputeInteractionState(int X, int Y, int
 //------------------------------------------------------------------------------
 void vtkCoordinateFrameRepresentation::SetRepresentationState(int state)
 {
+  // Clamp the state
+  state = std::min<int>(std::max<int>(state, vtkCoordinateFrameRepresentation::Outside),
+    vtkCoordinateFrameRepresentation::ModifyingLockerZVector);
+
   if (this->RepresentationState == state)
   {
     return;
   }
 
-  // Clamp the state
-  state = (state < vtkCoordinateFrameRepresentation::Outside
-      ? vtkCoordinateFrameRepresentation::Outside
-      : (state > vtkCoordinateFrameRepresentation::ModifyingLockerZVector
-            ? vtkCoordinateFrameRepresentation::ModifyingLockerZVector
-            : state));
-
   this->RepresentationState = state;
   this->Modified();
 
diff --git a/Interaction/Widgets/vtkDisplaySizedImplicitPlaneRepresentation.cxx b/Interaction/Widgets/vtkDisplaySizedImplicitPlaneRepresentation.cxx
index 145f35dbfb96f04a416fcb6359b33973b018f907..1f64c0bda99e4dac8bff2c625ec1e88c56d1f004 100644
--- a/Interaction/Widgets/vtkDisplaySizedImplicitPlaneRepresentation.cxx
+++ b/Interaction/Widgets/vtkDisplaySizedImplicitPlaneRepresentation.cxx
@@ -36,6 +36,7 @@
 #include "vtkTubeFilter.h"
 #include "vtkWindow.h"
 
+#include <algorithm>
 #include <cfloat> //for FLT_EPSILON
 
 VTK_ABI_NAMESPACE_BEGIN
@@ -379,18 +380,15 @@ int vtkDisplaySizedImplicitPlaneRepresentation::ComputeComplexInteractionState(
 //------------------------------------------------------------------------------
 void vtkDisplaySizedImplicitPlaneRepresentation::SetRepresentationState(int state)
 {
+  // Clamp the state
+  state = std::min<int>(std::max<int>(state, vtkDisplaySizedImplicitPlaneRepresentation::Outside),
+    vtkDisplaySizedImplicitPlaneRepresentation::Scaling);
+
   if (this->RepresentationState == state)
   {
     return;
   }
 
-  // Clamp the state
-  state = (state < vtkDisplaySizedImplicitPlaneRepresentation::Outside
-      ? vtkDisplaySizedImplicitPlaneRepresentation::Outside
-      : (state > vtkDisplaySizedImplicitPlaneRepresentation::Scaling
-            ? vtkDisplaySizedImplicitPlaneRepresentation::Scaling
-            : state));
-
   this->RepresentationState = state;
   this->Modified();
 
diff --git a/Interaction/Widgets/vtkFinitePlaneRepresentation.cxx b/Interaction/Widgets/vtkFinitePlaneRepresentation.cxx
index 7c4d238b0f33f1ad4ab6fcf72a3c232a8eafc06b..cbc67d319755ee4ef2a5c0cbdf709d59841f1c71 100644
--- a/Interaction/Widgets/vtkFinitePlaneRepresentation.cxx
+++ b/Interaction/Widgets/vtkFinitePlaneRepresentation.cxx
@@ -28,6 +28,8 @@
 #include "vtkTubeFilter.h"
 #include "vtkWindow.h"
 
+#include <algorithm>
+
 VTK_ABI_NAMESPACE_BEGIN
 vtkStandardNewMacro(vtkFinitePlaneRepresentation);
 
@@ -856,17 +858,15 @@ void vtkFinitePlaneRepresentation::SetHighlightNormal(int highlight)
 //------------------------------------------------------------------------------
 void vtkFinitePlaneRepresentation::SetRepresentationState(int state)
 {
+  // Clamp the state
+  state = std::min<int>(std::max<int>(state, vtkFinitePlaneRepresentation::Outside),
+    vtkFinitePlaneRepresentation::Pushing);
+
   if (this->RepresentationState == state)
   {
     return;
   }
 
-  // Clamp the state
-  state = (state < vtkFinitePlaneRepresentation::Outside
-      ? vtkFinitePlaneRepresentation::Outside
-      : (state > vtkFinitePlaneRepresentation::Pushing ? vtkFinitePlaneRepresentation::Pushing
-                                                       : state));
-
   this->RepresentationState = state;
   this->Modified();
 }
diff --git a/Interaction/Widgets/vtkImplicitConeRepresentation.cxx b/Interaction/Widgets/vtkImplicitConeRepresentation.cxx
index 9c7503344f987a686dafe73b0a5283e53c773aa3..f783ffd7f8dec590f48815e3caa1ec2792eb210c 100644
--- a/Interaction/Widgets/vtkImplicitConeRepresentation.cxx
+++ b/Interaction/Widgets/vtkImplicitConeRepresentation.cxx
@@ -31,6 +31,8 @@
 #include "vtkType.h"
 #include "vtkVector.h"
 
+#include <algorithm>
+
 VTK_ABI_NAMESPACE_BEGIN
 vtkStandardNewMacro(vtkImplicitConeRepresentation);
 
@@ -225,17 +227,15 @@ int vtkImplicitConeRepresentation::ComputeInteractionState(int X, int Y, int vtk
 //------------------------------------------------------------------------------
 void vtkImplicitConeRepresentation::SetRepresentationState(InteractionStateType state)
 {
+  // Clamp the state
+  state = std::min(
+    std::max(state, InteractionStateType::Outside), InteractionStateType::TranslatingOrigin);
+
   if (this->RepresentationState == state)
   {
     return;
   }
 
-  // Clamp the state
-  state = (state < InteractionStateType::Outside
-      ? InteractionStateType::Outside
-      : (state > InteractionStateType::TranslatingOrigin ? InteractionStateType::TranslatingOrigin
-                                                         : state));
-
   this->RepresentationState = state;
   this->Modified();
 
diff --git a/Interaction/Widgets/vtkImplicitCylinderRepresentation.cxx b/Interaction/Widgets/vtkImplicitCylinderRepresentation.cxx
index 4304e25c97d3455b627d68538ec4255f6076d792..dc1f40c5503c2b007c207b190e7777bfb8d4d150 100644
--- a/Interaction/Widgets/vtkImplicitCylinderRepresentation.cxx
+++ b/Interaction/Widgets/vtkImplicitCylinderRepresentation.cxx
@@ -308,18 +308,15 @@ int vtkImplicitCylinderRepresentation::ComputeInteractionState(int X, int Y, int
 //------------------------------------------------------------------------------
 void vtkImplicitCylinderRepresentation::SetRepresentationState(int state)
 {
+  // Clamp the state
+  state = std::min<int>(std::max<int>(state, vtkImplicitCylinderRepresentation::Outside),
+    vtkImplicitCylinderRepresentation::Scaling);
+
   if (this->RepresentationState == state)
   {
     return;
   }
 
-  // Clamp the state
-  state = (state < vtkImplicitCylinderRepresentation::Outside
-      ? vtkImplicitCylinderRepresentation::Outside
-      : (state > vtkImplicitCylinderRepresentation::Scaling
-            ? vtkImplicitCylinderRepresentation::Scaling
-            : state));
-
   this->RepresentationState = state;
   this->Modified();
 
diff --git a/Interaction/Widgets/vtkImplicitPlaneRepresentation.cxx b/Interaction/Widgets/vtkImplicitPlaneRepresentation.cxx
index 549ebc9eb1108fd9a8626d1520ac02e0e190eeef..8961986f9f97dbe73f15fbe5b9731d4eb303769b 100644
--- a/Interaction/Widgets/vtkImplicitPlaneRepresentation.cxx
+++ b/Interaction/Widgets/vtkImplicitPlaneRepresentation.cxx
@@ -32,6 +32,7 @@
 #include "vtkTubeFilter.h"
 #include "vtkWindow.h"
 
+#include <algorithm>
 #include <cfloat> //for FLT_EPSILON
 
 VTK_ABI_NAMESPACE_BEGIN
@@ -429,17 +430,15 @@ int vtkImplicitPlaneRepresentation::ComputeComplexInteractionState(
 //------------------------------------------------------------------------------
 void vtkImplicitPlaneRepresentation::SetRepresentationState(int state)
 {
+  // Clamp the state
+  state = std::min<int>(std::max<int>(state, vtkImplicitPlaneRepresentation::Outside),
+    vtkImplicitPlaneRepresentation::Scaling);
+
   if (this->RepresentationState == state)
   {
     return;
   }
 
-  // Clamp the state
-  state = (state < vtkImplicitPlaneRepresentation::Outside
-      ? vtkImplicitPlaneRepresentation::Outside
-      : (state > vtkImplicitPlaneRepresentation::Scaling ? vtkImplicitPlaneRepresentation::Scaling
-                                                         : state));
-
   this->RepresentationState = state;
   this->Modified();
 
diff --git a/Interaction/Widgets/vtkLineRepresentation.cxx b/Interaction/Widgets/vtkLineRepresentation.cxx
index ec6a4fde5b09fbdac0d9f09997e87dbda47d718b..e9154c66344a9b772201871ef4485cc1d253c443 100644
--- a/Interaction/Widgets/vtkLineRepresentation.cxx
+++ b/Interaction/Widgets/vtkLineRepresentation.cxx
@@ -24,6 +24,8 @@
 #include "vtkVectorText.h"
 #include "vtkWindow.h"
 
+#include <algorithm>
+
 VTK_ABI_NAMESPACE_BEGIN
 vtkStandardNewMacro(vtkLineRepresentation);
 
@@ -594,15 +596,14 @@ int vtkLineRepresentation::ComputeInteractionState(int x, int y, int vtkNotUsed(
 //------------------------------------------------------------------------------
 void vtkLineRepresentation::SetRepresentationState(int state)
 {
+  state = std::min<int>(
+    std::max<int>(state, vtkLineRepresentation::Outside), vtkLineRepresentation::Scaling);
+
   if (this->RepresentationState == state)
   {
     return;
   }
 
-  state = (state < vtkLineRepresentation::Outside
-      ? vtkLineRepresentation::Outside
-      : (state > vtkLineRepresentation::Scaling ? vtkLineRepresentation::Scaling : state));
-
   this->RepresentationState = state;
   this->Modified();
 
diff --git a/Rendering/Core/vtkCamera.cxx b/Rendering/Core/vtkCamera.cxx
index b9916283e5433a6e8ddb2d0682d2a373e0213c81..f494ad2a6677632414708ac3bff54b803138ad27 100644
--- a/Rendering/Core/vtkCamera.cxx
+++ b/Rendering/Core/vtkCamera.cxx
@@ -11,6 +11,7 @@
 #include "vtkTimeStamp.h"
 #include "vtkTransform.h"
 
+#include <algorithm>
 #include <cassert>
 #include <cmath>
 
@@ -877,9 +878,10 @@ void vtkCamera::SetViewAngle(double angle)
   double min = 0.00000001;
   double max = 179.0;
 
+  angle = std::min(std::max(angle, min), max);
   if (this->ViewAngle != angle)
   {
-    this->ViewAngle = (angle < min ? min : (angle > max ? max : angle));
+    this->ViewAngle = angle;
     this->Modified();
     this->ViewingRaysModified();
   }