Browse Source

Remove defined_ bool from Rect & Sphere. Closes #986.

Lasse Öörni 10 years ago
parent
commit
eff2c913e8

+ 3 - 3
Source/Urho3D/AngelScript/MathAPI.cpp

@@ -823,6 +823,7 @@ static void RegisterRect(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Rect", "bool Equals(const Rect&in) const", asMETHOD(Rect, Equals), asCALL_THISCALL);
     engine->RegisterObjectMethod("Rect", "bool Equals(const Rect&in) const", asMETHOD(Rect, Equals), asCALL_THISCALL);
     engine->RegisterObjectMethod("Rect", "Intersection IsInside(const Vector2&in) const", asMETHOD(Rect, IsInside), asCALL_THISCALL);
     engine->RegisterObjectMethod("Rect", "Intersection IsInside(const Vector2&in) const", asMETHOD(Rect, IsInside), asCALL_THISCALL);
     engine->RegisterObjectMethod("Rect", "Vector4 ToVector4() const", asMETHOD(Rect, ToVector4), asCALL_THISCALL);
     engine->RegisterObjectMethod("Rect", "Vector4 ToVector4() const", asMETHOD(Rect, ToVector4), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Rect", "bool Defined() const", asMETHOD(Rect, Defined), asCALL_THISCALL);
     engine->RegisterObjectMethod("Rect", "Vector2 get_center() const", asMETHOD(Rect, Center), asCALL_THISCALL);
     engine->RegisterObjectMethod("Rect", "Vector2 get_center() const", asMETHOD(Rect, Center), asCALL_THISCALL);
     engine->RegisterObjectMethod("Rect", "Vector2 get_size() const", asMETHOD(Rect, Size), asCALL_THISCALL);
     engine->RegisterObjectMethod("Rect", "Vector2 get_size() const", asMETHOD(Rect, Size), asCALL_THISCALL);
     engine->RegisterObjectMethod("Rect", "Vector2 get_halfSize() const", asMETHOD(Rect, HalfSize), asCALL_THISCALL);
     engine->RegisterObjectMethod("Rect", "Vector2 get_halfSize() const", asMETHOD(Rect, HalfSize), asCALL_THISCALL);
@@ -832,7 +833,6 @@ static void RegisterRect(asIScriptEngine* engine)
     engine->RegisterObjectProperty("Rect", "float top", offsetof(Rect, min_.y_));
     engine->RegisterObjectProperty("Rect", "float top", offsetof(Rect, min_.y_));
     engine->RegisterObjectProperty("Rect", "float right", offsetof(Rect, max_.x_));
     engine->RegisterObjectProperty("Rect", "float right", offsetof(Rect, max_.x_));
     engine->RegisterObjectProperty("Rect", "float bottom", offsetof(Rect, max_.y_));
     engine->RegisterObjectProperty("Rect", "float bottom", offsetof(Rect, max_.y_));
-    engine->RegisterObjectProperty("Rect", "bool defined", offsetof(Rect, defined_));
 }
 }
 
 
 static void ConstructBoundingBox(BoundingBox* ptr)
 static void ConstructBoundingBox(BoundingBox* ptr)
@@ -1001,7 +1001,6 @@ static void RegisterVolumes(asIScriptEngine* engine)
     engine->RegisterObjectMethod("BoundingBox", "void Define(const Frustum&in)", asMETHODPR(BoundingBox, Define, (const Frustum&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "void Define(const Frustum&in)", asMETHODPR(BoundingBox, Define, (const Frustum&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "void Define(const Polyhedron&in)", asMETHODPR(BoundingBox, Define, (const Polyhedron&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "void Define(const Polyhedron&in)", asMETHODPR(BoundingBox, Define, (const Polyhedron&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "void Define(const Sphere&in)", asMETHODPR(BoundingBox, Define, (const Sphere&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "void Define(const Sphere&in)", asMETHODPR(BoundingBox, Define, (const Sphere&), void), asCALL_THISCALL);
-    engine->RegisterObjectMethod("BoundingBox", "bool Defined() const", asMETHOD(BoundingBox, Defined), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "void Merge(const Vector3&in)", asMETHODPR(BoundingBox, Merge, (const Vector3&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "void Merge(const Vector3&in)", asMETHODPR(BoundingBox, Merge, (const Vector3&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "void Merge(const BoundingBox&in)", asMETHODPR(BoundingBox, Merge, (const BoundingBox&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "void Merge(const BoundingBox&in)", asMETHODPR(BoundingBox, Merge, (const BoundingBox&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "void Merge(const Frustum&in)", asMETHODPR(BoundingBox, Merge, (const Frustum&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "void Merge(const Frustum&in)", asMETHODPR(BoundingBox, Merge, (const Frustum&), void), asCALL_THISCALL);
@@ -1020,6 +1019,7 @@ static void RegisterVolumes(asIScriptEngine* engine)
     engine->RegisterObjectMethod("BoundingBox", "BoundingBox Transformed(const Matrix3x4&in) const", asMETHODPR(BoundingBox, Transformed, (const Matrix3x4&) const, BoundingBox), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "BoundingBox Transformed(const Matrix3x4&in) const", asMETHODPR(BoundingBox, Transformed, (const Matrix3x4&) const, BoundingBox), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "Rect Projected(const Matrix4&in) const", asMETHODPR(BoundingBox, Projected, (const Matrix4&) const, Rect), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "Rect Projected(const Matrix4&in) const", asMETHODPR(BoundingBox, Projected, (const Matrix4&) const, Rect), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "String ToString() const", asMETHOD(BoundingBox, ToString), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "String ToString() const", asMETHOD(BoundingBox, ToString), asCALL_THISCALL);
+    engine->RegisterObjectMethod("BoundingBox", "bool Defined() const", asMETHOD(BoundingBox, Defined), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "Vector3 get_center() const", asMETHOD(BoundingBox, Center), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "Vector3 get_center() const", asMETHOD(BoundingBox, Center), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "Vector3 get_size() const", asMETHOD(BoundingBox, Size), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "Vector3 get_size() const", asMETHOD(BoundingBox, Size), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "Vector3 get_halfSize() const", asMETHOD(BoundingBox, HalfSize), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoundingBox", "Vector3 get_halfSize() const", asMETHOD(BoundingBox, HalfSize), asCALL_THISCALL);
@@ -1085,6 +1085,7 @@ static void RegisterVolumes(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Sphere", "void Merge(const Frustum&in)", asMETHODPR(Sphere, Merge, (const Frustum&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("Sphere", "void Merge(const Frustum&in)", asMETHODPR(Sphere, Merge, (const Frustum&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("Sphere", "void Merge(const Sphere&in)", asMETHODPR(Sphere, Merge, (const Sphere&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("Sphere", "void Merge(const Sphere&in)", asMETHODPR(Sphere, Merge, (const Sphere&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("Sphere", "void Clear()", asMETHOD(Sphere, Clear), asCALL_THISCALL);
     engine->RegisterObjectMethod("Sphere", "void Clear()", asMETHOD(Sphere, Clear), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Sphere", "bool Defined() const", asMETHOD(Sphere, Defined), asCALL_THISCALL);
     engine->RegisterObjectMethod("Sphere", "Intersection IsInside(const Vector3&in) const", asMETHODPR(Sphere, IsInside, (const Vector3&) const, Intersection), asCALL_THISCALL);
     engine->RegisterObjectMethod("Sphere", "Intersection IsInside(const Vector3&in) const", asMETHODPR(Sphere, IsInside, (const Vector3&) const, Intersection), asCALL_THISCALL);
     engine->RegisterObjectMethod("Sphere", "Intersection IsInside(const Sphere&in) const", asMETHODPR(Sphere, IsInside, (const Sphere&) const, Intersection), asCALL_THISCALL);
     engine->RegisterObjectMethod("Sphere", "Intersection IsInside(const Sphere&in) const", asMETHODPR(Sphere, IsInside, (const Sphere&) const, Intersection), asCALL_THISCALL);
     engine->RegisterObjectMethod("Sphere", "Intersection IsInsideFast(const Sphere&in) const", asMETHODPR(Sphere, IsInsideFast, (const Sphere&) const, Intersection), asCALL_THISCALL);
     engine->RegisterObjectMethod("Sphere", "Intersection IsInsideFast(const Sphere&in) const", asMETHODPR(Sphere, IsInsideFast, (const Sphere&) const, Intersection), asCALL_THISCALL);
@@ -1093,7 +1094,6 @@ static void RegisterVolumes(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Sphere", "float Distance(const Vector3&in) const", asMETHOD(Sphere, Distance), asCALL_THISCALL);
     engine->RegisterObjectMethod("Sphere", "float Distance(const Vector3&in) const", asMETHOD(Sphere, Distance), asCALL_THISCALL);
     engine->RegisterObjectProperty("Sphere", "Vector3 center", offsetof(Sphere, center_));
     engine->RegisterObjectProperty("Sphere", "Vector3 center", offsetof(Sphere, center_));
     engine->RegisterObjectProperty("Sphere", "float radius", offsetof(Sphere, radius_));
     engine->RegisterObjectProperty("Sphere", "float radius", offsetof(Sphere, radius_));
-    engine->RegisterObjectProperty("Sphere", "bool defined", offsetof(Sphere, defined_));
 }
 }
 
 
 static void ConstructColor(Color* ptr)
 static void ConstructColor(Color* ptr)

+ 1 - 2
Source/Urho3D/LuaScript/pkgs/Math/BoundingBox.pkg

@@ -23,8 +23,6 @@ class BoundingBox
     void Define(const Polyhedron& poly);
     void Define(const Polyhedron& poly);
     void Define(const Sphere& sphere);
     void Define(const Sphere& sphere);
 
 
-    bool Defined() const;
-
     void Merge(const Vector3& point);
     void Merge(const Vector3& point);
     void Merge(const BoundingBox& box);
     void Merge(const BoundingBox& box);
     void Merge(const Frustum& frustum);
     void Merge(const Frustum& frustum);
@@ -36,6 +34,7 @@ class BoundingBox
     void Transform(const Matrix3x4& transform);
     void Transform(const Matrix3x4& transform);
     void Clear();
     void Clear();
 
 
+    bool Defined() const;
     Vector3 Center() const;
     Vector3 Center() const;
     Vector3 Size() const;
     Vector3 Size() const;
     Vector3 HalfSize() const;
     Vector3 HalfSize() const;

+ 3 - 1
Source/Urho3D/LuaScript/pkgs/Math/Rect.pkg

@@ -18,13 +18,15 @@ class Rect
     void Merge(const Rect& rect);
     void Merge(const Rect& rect);
     void Clear();
     void Clear();
     void Clip(const Rect& rect);
     void Clip(const Rect& rect);
+    
+    bool Defined() const;
     Vector2 Center() const;
     Vector2 Center() const;
     Vector2 Size() const;
     Vector2 Size() const;
     Vector2 HalfSize() const;
     Vector2 HalfSize() const;
     bool Equals(const Rect& rhs) const;
     bool Equals(const Rect& rhs) const;
     Intersection IsInside(const Vector2& point) const;
     Intersection IsInside(const Vector2& point) const;
     Vector4 ToVector4() const;
     Vector4 ToVector4() const;
-
+    
     String ToString() const;
     String ToString() const;
 
 
     Vector2 min_ @ min;
     Vector2 min_ @ min;

+ 1 - 2
Source/Urho3D/LuaScript/pkgs/Math/Sphere.pkg

@@ -26,15 +26,14 @@ class Sphere
 
 
     void Clear();
     void Clear();
 
 
+    bool Defined() const;
     Intersection IsInside(const Vector3& point) const;
     Intersection IsInside(const Vector3& point) const;
     Intersection IsInside(const Sphere& sphere) const;
     Intersection IsInside(const Sphere& sphere) const;
     Intersection IsInsideFast(const Sphere& sphere) const;
     Intersection IsInsideFast(const Sphere& sphere) const;
     Intersection IsInside(const BoundingBox& box) const;
     Intersection IsInside(const BoundingBox& box) const;
     Intersection IsInsideFast(const BoundingBox& box) const;
     Intersection IsInsideFast(const BoundingBox& box) const;
-
     float Distance(const Vector3& point) const;
     float Distance(const Vector3& point) const;
 
 
     Vector3 center_ @ center;
     Vector3 center_ @ center;
     float radius_ @ radius;
     float radius_ @ radius;
-    bool defined_ @ defined;
 };
 };

+ 6 - 6
Source/Urho3D/Math/BoundingBox.h

@@ -172,12 +172,6 @@ public:
         min_ = max_ = point;
         min_ = max_ = point;
     }
     }
 
 
-    /// Returns true if this bounding box is defined via a previous call to Define() or Merge().
-    bool Defined() const
-    {
-        return min_.x_ != M_INFINITY;
-    }
-
     /// Merge a point.
     /// Merge a point.
     void Merge(const Vector3& point)
     void Merge(const Vector3& point)
     {
     {
@@ -258,6 +252,12 @@ public:
 #endif
 #endif
     }
     }
 
 
+    /// Return true if this bounding box is defined via a previous call to Define() or Merge().
+    bool Defined() const
+    {
+        return min_.x_ != M_INFINITY;
+    }
+
     /// Return center.
     /// Return center.
     Vector3 Center() const { return (max_ + min_) * 0.5f; }
     Vector3 Center() const { return (max_ + min_) * 0.5f; }
 
 

+ 5 - 4
Source/Urho3D/Math/Rect.cpp

@@ -62,10 +62,11 @@ void Rect::Clip(const Rect& rect)
     if (rect.max_.y_ < max_.y_)
     if (rect.max_.y_ < max_.y_)
         max_.y_ = rect.max_.y_;
         max_.y_ = rect.max_.y_;
 
 
-    if (min_.x_ > max_.x_)
-        Swap(min_.x_, max_.x_);
-    if (min_.y_ > max_.y_)
-        Swap(min_.y_, max_.y_);
+    if (min_.x_ > max_.x_ || min_.y_ > max_.y_)
+    {
+        min_ = Vector2(M_INFINITY, M_INFINITY);
+        max_ = Vector2(-M_INFINITY, -M_INFINITY);
+    }
 }
 }
 
 
 }
 }

+ 15 - 35
Source/Urho3D/Math/Rect.h

@@ -33,49 +33,43 @@ class URHO3D_API Rect
 public:
 public:
     /// Construct an undefined rect.
     /// Construct an undefined rect.
     Rect() :
     Rect() :
-        min_(Vector2::ZERO),
-        max_(Vector2::ZERO),
-        defined_(false)
+        min_(M_INFINITY, M_INFINITY),
+        max_(-M_INFINITY, -M_INFINITY)
     {
     {
     }
     }
 
 
     /// Construct from minimum and maximum vectors.
     /// Construct from minimum and maximum vectors.
     Rect(const Vector2& min, const Vector2& max) :
     Rect(const Vector2& min, const Vector2& max) :
         min_(min),
         min_(min),
-        max_(max),
-        defined_(true)
+        max_(max)
     {
     {
     }
     }
 
 
     /// Construct from coordinates.
     /// Construct from coordinates.
     Rect(float left, float top, float right, float bottom) :
     Rect(float left, float top, float right, float bottom) :
         min_(left, top),
         min_(left, top),
-        max_(right, bottom),
-        defined_(true)
+        max_(right, bottom)
     {
     {
     }
     }
 
 
     /// Construct from a Vector4.
     /// Construct from a Vector4.
     Rect(const Vector4& vector) :
     Rect(const Vector4& vector) :
         min_(vector.x_, vector.y_),
         min_(vector.x_, vector.y_),
-        max_(vector.z_, vector.w_),
-        defined_(true)
+        max_(vector.z_, vector.w_)
     {
     {
     }
     }
 
 
     /// Construct from a float array.
     /// Construct from a float array.
     explicit Rect(const float* data) :
     explicit Rect(const float* data) :
         min_(data[0], data[1]),
         min_(data[0], data[1]),
-        max_(data[2], data[3]),
-        defined_(true)
+        max_(data[2], data[3])
     {
     {
     }
     }
 
 
     /// Copy-construct from another rect.
     /// Copy-construct from another rect.
     Rect(const Rect& rect) :
     Rect(const Rect& rect) :
         min_(rect.min_),
         min_(rect.min_),
-        max_(rect.max_),
-        defined_(rect.defined_)
+        max_(rect.max_)
     {
     {
     }
     }
 
 
@@ -84,7 +78,6 @@ public:
     {
     {
         min_ = rhs.min_;
         min_ = rhs.min_;
         max_ = rhs.max_;
         max_ = rhs.max_;
-        defined_ = rhs.defined_;
         return *this;
         return *this;
     }
     }
 
 
@@ -99,7 +92,6 @@ public:
     {
     {
         min_ = rect.min_;
         min_ = rect.min_;
         max_ = rect.max_;
         max_ = rect.max_;
-        defined_ = true;
     }
     }
 
 
     /// Define from minimum and maximum vectors.
     /// Define from minimum and maximum vectors.
@@ -107,25 +99,17 @@ public:
     {
     {
         min_ = min;
         min_ = min;
         max_ = max;
         max_ = max;
-        defined_ = true;
     }
     }
 
 
     /// Define from a point.
     /// Define from a point.
     void Define(const Vector2& point)
     void Define(const Vector2& point)
     {
     {
         min_ = max_ = point;
         min_ = max_ = point;
-        defined_ = true;
     }
     }
 
 
     /// Merge a point.
     /// Merge a point.
     void Merge(const Vector2& point)
     void Merge(const Vector2& point)
     {
     {
-        if (!defined_)
-        {
-            min_ = max_ = point;
-            defined_ = true;
-        }
-
         if (point.x_ < min_.x_)
         if (point.x_ < min_.x_)
             min_.x_ = point.x_;
             min_.x_ = point.x_;
         if (point.x_ > max_.x_)
         if (point.x_ > max_.x_)
@@ -139,13 +123,6 @@ public:
     /// Merge a rect.
     /// Merge a rect.
     void Merge(const Rect& rect)
     void Merge(const Rect& rect)
     {
     {
-        if (!defined_)
-        {
-            min_ = rect.min_;
-            max_ = rect.max_;
-            defined_ = true;
-        }
-
         if (rect.min_.x_ < min_.x_)
         if (rect.min_.x_ < min_.x_)
             min_.x_ = rect.min_.x_;
             min_.x_ = rect.min_.x_;
         if (rect.min_.y_ < min_.y_)
         if (rect.min_.y_ < min_.y_)
@@ -159,14 +136,19 @@ public:
     /// Clear to undefined state.
     /// Clear to undefined state.
     void Clear()
     void Clear()
     {
     {
-        min_ = Vector2::ZERO;
-        max_ = Vector2::ZERO;
-        defined_ = false;
+        min_ = Vector2(M_INFINITY, M_INFINITY);
+        max_ = Vector2(-M_INFINITY, -M_INFINITY);
     }
     }
 
 
     /// Clip with another rect.
     /// Clip with another rect.
     void Clip(const Rect& rect);
     void Clip(const Rect& rect);
 
 
+    /// Return true if this rect is defined via a previous call to Define() or Merge().
+    bool Defined() const
+    {
+        return min_.x_ != M_INFINITY;
+    }
+
     /// Return center.
     /// Return center.
     Vector2 Center() const { return (max_ + min_) * 0.5f; }
     Vector2 Center() const { return (max_ + min_) * 0.5f; }
 
 
@@ -201,8 +183,6 @@ public:
     Vector2 min_;
     Vector2 min_;
     /// Maximum vector.
     /// Maximum vector.
     Vector2 max_;
     Vector2 max_;
-    /// Defined flag.
-    bool defined_;
 
 
     /// Rect in the range (-1, -1) - (1, 1)
     /// Rect in the range (-1, -1) - (1, 1)
     static const Rect FULL;
     static const Rect FULL;

+ 4 - 5
Source/Urho3D/Math/Sphere.cpp

@@ -35,7 +35,7 @@ void Sphere::Define(const Vector3* vertices, unsigned count)
     if (!count)
     if (!count)
         return;
         return;
 
 
-    defined_ = false;
+    Clear();
     Merge(vertices, count);
     Merge(vertices, count);
 }
 }
 
 
@@ -44,7 +44,7 @@ void Sphere::Define(const BoundingBox& box)
     const Vector3& min = box.min_;
     const Vector3& min = box.min_;
     const Vector3& max = box.max_;
     const Vector3& max = box.max_;
 
 
-    defined_ = false;
+    Clear();
     Merge(min);
     Merge(min);
     Merge(Vector3(max.x_, min.y_, min.z_));
     Merge(Vector3(max.x_, min.y_, min.z_));
     Merge(Vector3(min.x_, max.y_, min.z_));
     Merge(Vector3(min.x_, max.y_, min.z_));
@@ -62,7 +62,7 @@ void Sphere::Define(const Frustum& frustum)
 
 
 void Sphere::Define(const Polyhedron& poly)
 void Sphere::Define(const Polyhedron& poly)
 {
 {
-    defined_ = false;
+    Clear();
     Merge(poly);
     Merge(poly);
 }
 }
 
 
@@ -105,11 +105,10 @@ void Sphere::Merge(const Polyhedron& poly)
 
 
 void Sphere::Merge(const Sphere& sphere)
 void Sphere::Merge(const Sphere& sphere)
 {
 {
-    if (!defined_)
+    if (radius_ < 0.0f)
     {
     {
         center_ = sphere.center_;
         center_ = sphere.center_;
         radius_ = sphere.radius_;
         radius_ = sphere.radius_;
-        defined_ = true;
         return;
         return;
     }
     }
 
 

+ 15 - 22
Source/Urho3D/Math/Sphere.h

@@ -38,51 +38,44 @@ public:
     /// Construct undefined.
     /// Construct undefined.
     Sphere() :
     Sphere() :
         center_(Vector3::ZERO),
         center_(Vector3::ZERO),
-        radius_(0.0f),
-        defined_(false)
+        radius_(-M_INFINITY)
     {
     {
     }
     }
 
 
     /// Copy-construct from another sphere.
     /// Copy-construct from another sphere.
     Sphere(const Sphere& sphere) :
     Sphere(const Sphere& sphere) :
         center_(sphere.center_),
         center_(sphere.center_),
-        radius_(sphere.radius_),
-        defined_(sphere.defined_)
+        radius_(sphere.radius_)
     {
     {
     }
     }
 
 
     /// Construct from center and radius.
     /// Construct from center and radius.
     Sphere(const Vector3& center, float radius) :
     Sphere(const Vector3& center, float radius) :
         center_(center),
         center_(center),
-        radius_(radius),
-        defined_(true)
+        radius_(radius)
     {
     {
     }
     }
 
 
     /// Construct from an array of vertices.
     /// Construct from an array of vertices.
-    Sphere(const Vector3* vertices, unsigned count) :
-        defined_(false)
+    Sphere(const Vector3* vertices, unsigned count)
     {
     {
         Define(vertices, count);
         Define(vertices, count);
     }
     }
 
 
     /// Construct from a bounding box.
     /// Construct from a bounding box.
-    Sphere(const BoundingBox& box) :
-        defined_(false)
+    Sphere(const BoundingBox& box)
     {
     {
         Define(box);
         Define(box);
     }
     }
 
 
     /// Construct from a frustum.
     /// Construct from a frustum.
-    Sphere(const Frustum& frustum) :
-        defined_(false)
+    Sphere(const Frustum& frustum)
     {
     {
         Define(frustum);
         Define(frustum);
     }
     }
 
 
     /// Construct from a polyhedron.
     /// Construct from a polyhedron.
-    Sphere(const Polyhedron& poly) :
-        defined_(false)
+    Sphere(const Polyhedron& poly)
     {
     {
         Define(poly);
         Define(poly);
     }
     }
@@ -92,7 +85,6 @@ public:
     {
     {
         center_ = rhs.center_;
         center_ = rhs.center_;
         radius_ = rhs.radius_;
         radius_ = rhs.radius_;
-        defined_ = rhs.defined_;
         return *this;
         return *this;
     }
     }
 
 
@@ -113,7 +105,6 @@ public:
     {
     {
         center_ = center;
         center_ = center;
         radius_ = radius;
         radius_ = radius;
-        defined_ = true;
     }
     }
 
 
     /// Define from an array of vertices.
     /// Define from an array of vertices.
@@ -128,11 +119,10 @@ public:
     /// Merge a point.
     /// Merge a point.
     void Merge(const Vector3& point)
     void Merge(const Vector3& point)
     {
     {
-        if (!defined_)
+        if (radius_ < 0.0f)
         {
         {
             center_ = point;
             center_ = point;
             radius_ = 0.0f;
             radius_ = 0.0f;
-            defined_ = true;
             return;
             return;
         }
         }
 
 
@@ -162,8 +152,13 @@ public:
     void Clear()
     void Clear()
     {
     {
         center_ = Vector3::ZERO;
         center_ = Vector3::ZERO;
-        radius_ = 0.0f;
-        defined_ = false;
+        radius_ = -M_INFINITY;
+    }
+
+    /// Return true if this sphere is defined via a previous call to Define() or Merge().
+    bool Defined() const
+    {
+        return radius_ >= 0.0f;
     }
     }
 
 
     /// Test if a point is inside.
     /// Test if a point is inside.
@@ -212,8 +207,6 @@ public:
     Vector3 center_;
     Vector3 center_;
     /// Sphere radius.
     /// Sphere radius.
     float radius_;
     float radius_;
-    /// Defined flag.
-    bool defined_;
 };
 };
 
 
 }
 }