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

namespace MIP_Evaluator.Start
{
    /// <summary>
    /// Implementation of IEqualityComparer
    /// Used to enable linq for mitosis distance checking
    /// </summary>
    public class MitosisRangeEqualityComparer : IEqualityComparer<Point>
    {
        /// <summary>
        /// Calculates if the euclid distance between two points is less or equals a settings value
        /// </summary>
        /// <param name="x">The first point</param>
        /// <param name="y">the second point</param>
        /// <returns>true if both points distance is less or equals a settings value</returns>
        public bool Equals(Point x, Point y)
        {
            var distanceOnX = Math.Abs(x.X - y.X);
            var distanceOnY = Math.Abs(x.Y - y.Y);
            return ((int)Math.Sqrt(distanceOnX * distanceOnX + distanceOnY * distanceOnY)) <= Settings.Default.RangeBetweenTwoMitosis;
        }

        public int GetHashCode(Point obj)
        {
            return base.GetHashCode();
        }
    }
}