using System;
using System.Collections.Generic;
using System.Drawing;

using Spark3D.Algebra3D;

namespace Spark3D.Objects3D.Shapes
{
    public class Cube : Object3DCommon, IObject3D
    {
        /// <summary>
        /// Make a cube object for 3D drawing purposes.
        /// </summary>
        /// <param name="size">Cube side dimension</param>
        public Cube(double size)
            : base(MakeFaces(size / 2.0))
        {
        }
        static IList<Polygon3D> MakeFaces(double r)
        {
            IList<Polygon3D> ret = new List<Polygon3D>();
            // Bottom
            ret.Add(
                new Polygon3D(
                new Vector3D[] 
                {
                     new Vector3D( r, r,r),
                     new Vector3D(-r, r,r),
                     new Vector3D(-r,-r,r),
                     new Vector3D( r,-r,r)
                }, Color.Blue));
            // Side
            ret.Add(
              new Polygon3D(
              new Vector3D[] 
                {
                     new Vector3D( r, r,r),
                     new Vector3D(-r, r,r),
                     new Vector3D(-r, r,-r),
                     new Vector3D( r, r,-r)
                }, Color.Violet));

            ret.Add(
              new Polygon3D(
              new Vector3D[] 
                {
                     new Vector3D( r, r, r),
                     new Vector3D( r, r,-r),
                     new Vector3D( r,-r,-r),
                     new Vector3D( r,-r, r)
                }, Color.Red));

            ret.Add(
              new Polygon3D(
              new Vector3D[] 
                {
                     new Vector3D( r,-r,r),
                     new Vector3D(-r,-r,r),
                     new Vector3D(-r,-r,-r),
                     new Vector3D( r,-r,-r)
                }, Color.Green));

            ret.Add(
              new Polygon3D(
              new Vector3D[] 
                {
                     new Vector3D(-r, r, r),
                     new Vector3D(-r, r,-r),
                     new Vector3D(-r,-r,-r),
                     new Vector3D(-r,-r, r)
                }, Color.Yellow));

            //
            //  Now do lids or flaps
            //
            double h = r / Math.Sqrt(2.0);
            ret.Add(
               new Polygon3D(
               new Vector3D[] 
                {
                     new Vector3D(-r+h, r,-r-h),
                     new Vector3D(-r, r,-r),
                     new Vector3D(-r,-r,-r),
                     new Vector3D(-r+h,-r,-r-h)
                }, Color.Aqua));
            ret.Add(
                        new Polygon3D(
                        new Vector3D[] 
                {
                     new Vector3D(r-h, r,-r-h),
                     new Vector3D(r, r,-r),
                     new Vector3D(r,-r,-r),
                     new Vector3D(r-h,-r,-r-h)
                }, Color.Aqua));

            return ret;
        }

    }
}