<commit_before>﻿using math = System.Math;
using Vector2 = System.Windows.Point;

namespace GCS.Math
{
    public static class Geometry
    {
        #region GetIntersects
        public static Vector2[] GetIntersects(ILine line1, ILine line2)
        {
            if (Grad(line1) == Grad(line2))
            {
                if (Yint(line1) == Yint(line2))
                    throw new SameShapeException();
                else
                    return new Vector2[] { };
            }
            float intersect_x = (Yint(line2) - Yint(line1)) / (Grad(line1) - Grad(line2));
            return new[] { new Vector2(intersect_x, intersect_x * Grad(line1) + Yint(line1)) };
        }

        public static Vector2[] GetIntersects(ISegment seg1, ISegment seg2)
        {
            if (Grad(seg1) == Grad(seg2))
            {
                if (Yint(seg1) == Yint(seg2))
                    throw new SameShapeException();
                else
                    return new Vector2[] { };
            }
            
            float intersect_x = (Yint(seg2) - Yint(seg1)) / (Grad(seg1) - Grad(seg2));
            Vector2 intersect = new Vector2(intersect_x, intersect_x * Grad(seg1) + Yint(seg1));
            var seg1_len = seg1.Point1.Distance(seg1.Point2);
            var seg2_len = seg2.Point1.Distance(seg2.Point2);
            if (intersect.Distance(seg1.Point1) < seg1_len &&
                intersect.Distance(seg1.Point2) < seg1_len &&
                intersect.Distance(seg2.Point1) < seg2_len &&
                intersect.Distance(seg2.Point2) < seg2_len)
            {
                return new Vector2[] { intersect };
            }
            else return new Vector2[] { };
        }
        #endregion

        public static Vector2 GetNearest(IShape shape, Vector2 point)
        {
            throw new WorkWoorimException();
        }

        public static float GetNearestDistance(IShape shape, Vector2 point)
        {
            throw new WorkWoorimException();
        }

        public static float Grad(ILineLike line)
            => (float)((line.Point2.Y - line.Point1.Y) / (line.Point2.X - line.Point1.X));
        public static float Yint(ILineLike line)
            => (float)(line.Point1.Y - Grad(line) * line.Point1.X);
        public static float Distance(this Vector2 p1, Vector2 p2)
            => (float)math.Sqrt(math.Pow(p2.X - p1.X, 2) + math.Pow(p2.Y - p1.Y, 2));
    }
}<commit_msg>도형이 잘못된 도형인지 체크하는 로직 추가<commit_after>﻿using math = System.Math;
using Vector2 = System.Windows.Point;

namespace GCS.Math
{
    public static class Geometry
    {
        #region GetIntersects
        public static Vector2[] GetIntersects(ILine line1, ILine line2)
        {
            try
            {
                ThrowIfInvalidShape(line1);
                ThrowIfInvalidShape(line2);
            }
            catch { throw; }

            if (Grad(line1) == Grad(line2))
            {
                if (Yint(line1) == Yint(line2))
                    throw new SameShapeException();
                else
                    return new Vector2[] { };
            }
            float intersect_x = (Yint(line2) - Yint(line1)) / (Grad(line1) - Grad(line2));
            return new[] { new Vector2(intersect_x, intersect_x * Grad(line1) + Yint(line1)) };
        }

        public static Vector2[] GetIntersects(ISegment seg1, ISegment seg2)
        {
            try
            {
                ThrowIfInvalidShape(seg1);
                ThrowIfInvalidShape(seg2);
            }
            catch { throw; }

            if (Grad(seg1) == Grad(seg2))
            {
                if (Yint(seg1) == Yint(seg2))
                    throw new SameShapeException();
                else
                    return new Vector2[] { };
            }
            
            float intersect_x = (Yint(seg2) - Yint(seg1)) / (Grad(seg1) - Grad(seg2));
            Vector2 intersect = new Vector2(intersect_x, intersect_x * Grad(seg1) + Yint(seg1));
            var seg1_len = seg1.Point1.Distance(seg1.Point2);
            var seg2_len = seg2.Point1.Distance(seg2.Point2);
            if (intersect.Distance(seg1.Point1) < seg1_len &&
                intersect.Distance(seg1.Point2) < seg1_len &&
                intersect.Distance(seg2.Point1) < seg2_len &&
                intersect.Distance(seg2.Point2) < seg2_len)
            {
                return new Vector2[] { intersect };
            }
            else return new Vector2[] { };
        }
        #endregion

        public static Vector2 GetNearest(IShape shape, Vector2 point)
        {
            throw new WorkWoorimException();
        }

        public static float GetNearestDistance(IShape shape, Vector2 point)
        {
            throw new WorkWoorimException();
        }
        
        public static void ThrowIfInvalidShape(ILineLike shape)
        {
            if (shape.Point1 == shape.Point2) throw new InvalidShapeException();
        }

        public static void ThrowIfInvalidShape(ICircle shape)
        {
            if (shape.Center == shape.Another) throw new InvalidShapeException();
        }

        public static float Grad(ILineLike line)
            => (float)((line.Point2.Y - line.Point1.Y) / (line.Point2.X - line.Point1.X));
        public static float Yint(ILineLike line)
            => (float)(line.Point1.Y - Grad(line) * line.Point1.X);
        public static float Distance(this Vector2 p1, Vector2 p2)
            => (float)math.Sqrt(math.Pow(p2.X - p1.X, 2) + math.Pow(p2.Y - p1.Y, 2));
    }
}
{'fraction_non_alphanumeric': 0.10964833183047791, 'fraction_numerical': 0.028133453561767358, 'mean_word_length': 1.6510516252390057, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6396096', 'n_tokens_mistral': 1713, 'n_tokens_neox': 1659, 'n_words': 347}