#region Using directives

using System;
using System.Collections;

using OpenTK;
using OpenTK.Graphics;
using OpenTK.Math;
using OpenTK.Input;
using OpenTK.Platform;

#endregion

namespace DataProcessing
{
    public class Calculate
    {
        //vzdalenost 2 bodu v 2D 
        public static float VertexDistance2(Vertex firstVertice, Vertex secondVertice)
        {
            float sqrX = (firstVertice.X - secondVertice.X) * (firstVertice.X - secondVertice.X);
            float sqrZ = (firstVertice.Z - secondVertice.Z) * (firstVertice.Z - secondVertice.Z);

            return (float)Math.Sqrt(sqrX + sqrZ);
        }

        //vzdalenost 2 bodu v 3D 
        public static float VertexDistance3(Vertex firstVertice, Vertex secondVertice)
        {
            float sqrX = (firstVertice.X - secondVertice.X) * (firstVertice.X - secondVertice.X);
            float sqrY = (firstVertice.Y - secondVertice.Y) * (firstVertice.Y - secondVertice.Y);
            float sqrZ = (firstVertice.Z - secondVertice.Z) * (firstVertice.Z - secondVertice.Z);

            return (float)Math.Sqrt(sqrX + sqrY + sqrZ);
        }

        //vzdalenost 2 bodu v 3D
        public static float Distance3(float X1, float Y1, float Z1, float X2, float Y2, float Z2)
        {
            float sqrX = (X1 - X2) * (X1 - X2);
            float sqrY = (Y1 - Y2) * (Y1 - Y2);
            float sqrZ = (Z1 - Z2) * (Z1 - Z2);

            return (float)Math.Sqrt(sqrX + sqrY + sqrZ);
        }
        
        //vypocet normaly
        public static Vector3 Normal(Line firstLine, Line secondLine)
        {
            Vector3 vector1 = new Vector3();
            Vector3 vector2 = new Vector3();
            Vector3 normal = new Vector3();

            vector1.X = firstLine.StartPoint.X - firstLine.EndPoint.X;
            vector1.Y = firstLine.StartPoint.Y - firstLine.EndPoint.Y;
            vector1.Z = firstLine.StartPoint.Z - firstLine.EndPoint.Z;

            vector2.X = secondLine.EndPoint.X - firstLine.EndPoint.X;
            vector2.Y = secondLine.EndPoint.Y - firstLine.EndPoint.Y;
            vector2.Z = secondLine.EndPoint.Z - firstLine.EndPoint.Z;

            normal = Vector3.Cross(vector1, vector2);
            normal.NormalizeFast();
            if (normal.Y < 0)
                normal.Y = -normal.Y;

            return normal;
        }

        //velikost plochy
        public static int SurfaceSize(Vertex firstVertice, Vertex secondVertice)
        {
            float distance = VertexDistance3(firstVertice, secondVertice);

            return (int)((distance * distance) / 2);
        }
    }
}
