#region << Using Directives >>
using System;
using System.Drawing;
using System.Windows.Forms;
using Volpe.Cafe.Utils;
#endregion

namespace Volpe.Cafe.EspressoUI.Charts
{
    [Serializable]
    static class ChartPaint
    {
        public static PointF[] GetTrackingArrowBounds(float x, float y, float size, int direction)
        {
            if (direction < 1 || direction > 4) { return null; }
            PointF[] pts = new PointF[8];
            //
            float d  = size / 8;
            float ng = (direction == 1 || direction == 2) ? -1 : 1; // whether to negate
            float px = x, py = y;
            if (direction == 2 || direction == 4)
            {   // swap X/Y if vertical arrow
                Swap(ref px, ref py);
            }

            py += (    d * ng); pts[0] = new PointF(px, py);
            px -= (2 * d * ng); pts[1] = new PointF(px, py);
            py -= (2 * d * ng); pts[2] = new PointF(px, py);
            px += (2 * d * ng); pts[3] = new PointF(px, py);
            py -= (    d * ng); pts[4] = new PointF(px, py);
            px += (2 * d * ng);
            py += (2 * d * ng); pts[5] = new PointF(px, py);
            px -= (2 * d * ng);
            py += (2 * d * ng); pts[6] = new PointF(px, py);
            py -= (    d * ng); pts[7] = new PointF(px, py);

            if (direction == 2 || direction == 4)
            {   // swap X/Y if vertical arrow
                for (int i = 0; i < pts.Length; i++)
                {
                    pts[i] = new PointF(pts[i].Y, pts[i].X);
                }
            }

            return pts;
        }

        static void Swap(ref float x, ref float y)
        {
            if (x != y)
            {
                float tmp = x;
                x = y;
                y = tmp;
            }
        }

    }
}
