Example #1
0
        //public ContainmentType Contains(BoundingBox box)
        //{
        //    //test if all corner is in the same side of a face by just checking min and max
        //    if (box.Max.X < Min.X
        //        || box.Min.X > Max.X
        //        || box.Max.Y < Min.Y
        //        || box.Min.Y > Max.Y
        //        || box.Max.Z < Min.Z
        //        || box.Min.Z > Max.Z)
        //        return ContainmentType.Disjoint;


        //    if (box.Min.X >= Min.X
        //        && box.Max.X <= Max.X
        //        && box.Min.Y >= Min.Y
        //        && box.Max.Y <= Max.Y
        //        && box.Min.Z >= Min.Z
        //        && box.Max.Z <= Max.Z)
        //        return ContainmentType.Contains;

        //    return ContainmentType.Intersects;
        //}

        //public void Contains(ref BoundingBox box, out ContainmentType result)
        //{
        //    result = Contains(box);
        //}

        //public ContainmentType Contains(BoundingFrustum frustum)
        //{
        //    //TODO: bad done here need a fix.
        //    //Because question is not frustum contain box but reverse and this is not the same
        //    int i;
        //    ContainmentType contained;
        //    Vector3[] corners = frustum.GetCorners();

        //    // First we check if frustum is in box
        //    for (i = 0; i < corners.Length; i++)
        //    {
        //        this.Contains(ref corners[i], out contained);
        //        if (contained == ContainmentType.Disjoint)
        //            break;
        //    }

        //    if (i == corners.Length) // This means we checked all the corners and they were all contain or instersect
        //        return ContainmentType.Contains;

        //    if (i != 0)             // if i is not equal to zero, we can fastpath and say that this box intersects
        //        return ContainmentType.Intersects;


        //    // If we get here, it means the first (and only) point we checked was actually contained in the frustum.
        //    // So we assume that all other points will also be contained. If one of the points is disjoint, we can
        //    // exit immediately saying that the result is Intersects
        //    i++;
        //    for (; i < corners.Length; i++)
        //    {
        //        this.Contains(ref corners[i], out contained);
        //        if (contained != ContainmentType.Contains)
        //            return ContainmentType.Intersects;

        //    }

        //    // If we get here, then we know all the points were actually contained, therefore result is Contains
        //    return ContainmentType.Contains;
        //}

        //public ContainmentType Contains(BoundingSphere sphere)
        //{
        //    if (sphere.Center.X - Min.X > sphere.Radius
        //        && sphere.Center.Y - Min.Y > sphere.Radius
        //        && sphere.Center.Z - Min.Z > sphere.Radius
        //        && Max.X - sphere.Center.X > sphere.Radius
        //        && Max.Y - sphere.Center.Y > sphere.Radius
        //        && Max.Z - sphere.Center.Z > sphere.Radius)
        //        return ContainmentType.Contains;

        //    double dmin = 0;

        //    if (sphere.Center.X - Min.X <= sphere.Radius)
        //        dmin += (sphere.Center.X - Min.X) * (sphere.Center.X - Min.X);
        //    else if (Max.X - sphere.Center.X <= sphere.Radius)
        //        dmin += (sphere.Center.X - Max.X) * (sphere.Center.X - Max.X);
        //    if (sphere.Center.Y - Min.Y <= sphere.Radius)
        //        dmin += (sphere.Center.Y - Min.Y) * (sphere.Center.Y - Min.Y);
        //    else if (Max.Y - sphere.Center.Y <= sphere.Radius)
        //        dmin += (sphere.Center.Y - Max.Y) * (sphere.Center.Y - Max.Y);
        //    if (sphere.Center.Z - Min.Z <= sphere.Radius)
        //        dmin += (sphere.Center.Z - Min.Z) * (sphere.Center.Z - Min.Z);
        //    else if (Max.Z - sphere.Center.Z <= sphere.Radius)
        //        dmin += (sphere.Center.Z - Max.Z) * (sphere.Center.Z - Max.Z);

        //    if (dmin <= sphere.Radius * sphere.Radius)
        //        return ContainmentType.Intersects;

        //    return ContainmentType.Disjoint;
        //}

        //public void Contains(ref BoundingSphere sphere, out ContainmentType result)
        //{
        //    result = this.Contains(sphere);
        //}

        //public ContainmentType Contains(Vector3 point)
        //{
        //    ContainmentType result;
        //    this.Contains(ref point, out result);
        //    return result;
        //}

        //public void Contains(ref Vector3 point, out ContainmentType result)
        //{
        //    //first we get if point is out of box
        //    if (point.X < this.Min.X
        //        || point.X > this.Max.X
        //        || point.Y < this.Min.Y
        //        || point.Y > this.Max.Y
        //        || point.Z < this.Min.Z
        //        || point.Z > this.Max.Z)
        //    {
        //        result = ContainmentType.Disjoint;
        //    }//or if point is on box because coordonate of point is lesser or equal
        //    else if (point.X == this.Min.X
        //        || point.X == this.Max.X
        //        || point.Y == this.Min.Y
        //        || point.Y == this.Max.Y
        //        || point.Z == this.Min.Z
        //        || point.Z == this.Max.Z)
        //        result = ContainmentType.Intersects;
        //    else
        //        result = ContainmentType.Contains;


        //}

        public static BoundingBox CreateFromPoints(IEnumerable <Vector3d> points)
        {
            if (points == null)
            {
                throw new ArgumentNullException();
            }

            // TODO: Just check that Count > 0
            var empty   = true;
            var vector2 = new Vector3d(double.MaxValue);
            var vector1 = new Vector3d(double.MinValue);

            foreach (var vector3 in points)
            {
                vector2 = Vector3d.ComponentMin(vector2, vector3);
                vector1 = Vector3d.ComponentMax(vector1, vector3);
                empty   = false;
            }

            if (empty)
            {
                throw new ArgumentException();
            }

            return(new BoundingBox(vector2, vector1));
        }