You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

156 lines
3.5 KiB

using System;
using System.IO;
namespace Sog
{
[Serializable]
public struct Fixed64Bounds : IEquatable<Fixed64Bounds>
{
private Fixed64Vector3 m_Center;
private Fixed64Vector3 m_Extents;
public Fixed64Vector3 center
{
get
{
return m_Center;
}
set
{
m_Center = value;
}
}
public Fixed64Vector3 size
{
get
{
return m_Extents * 2f;
}
set
{
m_Extents = value * 0.5f;
}
}
public Fixed64Vector3 extents
{
get
{
return m_Extents;
}
set
{
m_Extents = value;
}
}
public Fixed64Vector3 min
{
get
{
return center - extents;
}
set
{
SetMinMax(value, max);
}
}
public Fixed64Vector3 max
{
get
{
return center + extents;
}
set
{
SetMinMax(min, value);
}
}
public Fixed64Bounds(Fixed64Vector3 center, Fixed64Vector3 size)
{
m_Center = center;
m_Extents = size * 0.5f;
}
public override int GetHashCode()
{
return center.GetHashCode() ^ (extents.GetHashCode() << 2);
}
public override bool Equals(object other)
{
if (!(other is Fixed64Bounds))
{
return false;
}
return Equals((Fixed64Bounds)other);
}
public bool Equals(Fixed64Bounds other)
{
return center.Equals(other.center) && extents.Equals(other.extents);
}
public static bool operator ==(Fixed64Bounds lhs, Fixed64Bounds rhs)
{
return lhs.center == rhs.center && lhs.extents == rhs.extents;
}
public static bool operator !=(Fixed64Bounds lhs, Fixed64Bounds rhs)
{
return !(lhs == rhs);
}
public void SetMinMax(Fixed64Vector3 min, Fixed64Vector3 max)
{
extents = (max - min) * 0.5f;
center = min + extents;
}
public void Encapsulate(Fixed64Vector3 point)
{
SetMinMax(Fixed64Vector3.Min(min, point), Fixed64Vector3.Max(max, point));
}
public void Encapsulate(Fixed64Bounds bounds)
{
Encapsulate(bounds.center - bounds.extents);
Encapsulate(bounds.center + bounds.extents);
}
public void Expand(float amount)
{
amount *= 0.5f;
extents += new Fixed64Vector3(amount, amount, amount);
}
public void Expand(Fixed64Vector3 amount)
{
extents += amount * 0.5f;
}
public override string ToString()
{
return String.Format("Center: {0}, Extents: {1}", m_Center, m_Extents);
}
public bool Contains(Fixed64Vector3 point)
{
var maxPoint = max;
var minPoint = min;
if(point.x >= minPoint.x && point.y >= minPoint.y && point.z >= minPoint.z
&& point.x <= maxPoint.x && point.y <= maxPoint.y && point.z <= maxPoint.z)
{
return true;
}
return false;
}
}
}