<commit_before>﻿using System;
using Microsoft.Xna.Framework;

namespace GCS
{
    public partial class Dot
    {
        public class EmptyDotRule : ShapeRule
        {
            public EmptyDotRule(Dot dot) : base(dot) { }

            public override void OnMoved()
            {
                if (IsHandling) return;
                IsHandling = true;

                MoveChilds();

                IsHandling = false;
            }

            public override void OnParentMoved()
            {
                throw new NotSupportedException("부모도 없는게..");
            }

            protected override void Fix()
            {
                // Do nothing. Just like you.
            }
        }

        public class DotOnShapeRule : ShapeRule
        {
            /// <summary>
            /// 선이면 비율, 원이면 각
            /// </summary>
            private float _ratio;

            public DotOnShapeRule(Dot dot, Shape parent) : base(dot)
            {
                dot.Parents.Add(parent);
                parent.Childs.Add(dot);

                RecalcRatio();
                Fix();
            }

            public override void OnMoved()
            {
                if (IsHandling) return;
                IsHandling = true;

                RecalcRatio();
                Fix();
                MoveChilds();

                IsHandling = false;
            }

            public override void OnParentMoved()
            {
                if (IsHandling) return;
                Fix();
                MoveChilds();
            }

            protected void RecalcRatio()
            {
                var dot = Shape as Dot;
                var parent = Shape.Parents[0];
                //타원이라고 다를 건 없음. 다만 로테이션을 신경써주면 될 뿐
                if (parent is Circle)
                {
                    var circle = parent as Circle;
                    _ratio = (float)Math.Atan2(circle.Center.Y - dot.Coord.Y,
                                               -dot.Coord.X + circle.Center.X) + (float)Math.PI;
                }
                else if (parent is LineLike)
                {
                    var line = parent as LineLike;
                    _ratio = (dot.Coord.X - line.Point1.X) / (line.Point2.X - line.Point1.X);
                }
            }

            protected override void Fix()
            {
                var dot = Shape as Dot;
                var parent = Shape.Parents[0];

                if (parent is Circle)
                {
                    var circle = parent as Circle;
                    dot.Coord = new Vector2(circle.Center.X + (float)Math.Cos(_ratio) * circle.Radius,
                                            circle.Center.Y + (float)Math.Sin(_ratio) * circle.Radius);
                }
                else if (parent is LineLike)
                {
                    var line = parent as LineLike;<commit_msg>타원 위의 DotRule 계산<commit_after>﻿using System;
using Microsoft.Xna.Framework;

namespace GCS
{
    public partial class Dot
    {
        public class EmptyDotRule : ShapeRule
        {
            public EmptyDotRule(Dot dot) : base(dot) { }

            public override void OnMoved()
            {
                if (IsHandling) return;
                IsHandling = true;

                MoveChilds();

                IsHandling = false;
            }

            public override void OnParentMoved()
            {
                throw new NotSupportedException("부모도 없는게..");
            }

            protected override void Fix()
            {
                // Do nothing. Just like you.
            }
        }

        public class DotOnShapeRule : ShapeRule
        {
            /// <summary>
            /// 선이면 비율, 원이면 각
            /// </summary>
            private float _ratio;

            public DotOnShapeRule(Dot dot, Shape parent) : base(dot)
            {
                dot.Parents.Add(parent);
                parent.Childs.Add(dot);

                RecalcRatio();
                Fix();
            }

            public override void OnMoved()
            {
                if (IsHandling) return;
                IsHandling = true;

                RecalcRatio();
                Fix();
                MoveChilds();

                IsHandling = false;
            }

            public override void OnParentMoved()
            {
                if (IsHandling) return;
                Fix();
                MoveChilds();
            }

            protected void RecalcRatio()
            {
                var dot = Shape as Dot;
                var parent = Shape.Parents[0];
                //타원이라고 다를 건 없음. 다만 로테이션을 신경써주면 될 뿐
                if (parent is Circle )
                {
                    var circle = parent as Circle;
                    _ratio = (float)Math.Atan2(circle.Center.Y - dot.Coord.Y,
                                               -dot.Coord.X + circle.Center.X) + (float)Math.PI;
                }
                else if (parent is Ellipse)
                {
                    Ellipse ellipse = parent as Ellipse;
                    Vector2 diff = ellipse.Focus1 - ellipse.Focus2;
                    float angle = (float)Math.Atan2(diff.Y, diff.X);
                    Ellipse elp = Ellipse.FromThreeDots(Dot.FromCoord(Geometry.Rotate(ellipse.Focus1, -angle)),
                        Dot.FromCoord(Geometry.Rotate(ellipse.Focus2, -angle)),
                        Dot.FromCoord(Geometry.Rotate(ellipse.PinPoint, -angle)));
                    Vector2 center = (elp.Focus1 + elp.Focus2) / 2;
                    _ratio = (float)Math.Atan2(dot.Coord.Y - center.Y, -dot.Coord.X + center.X) + (float)Math.PI;
                }
                else if (parent is LineLike)
                {
                    var line = parent as LineLike;
                    _ratio = (dot.Coord.X - line.Point1.X) / (line.Point2.X - line.Point1.X);
                }
            }

            protected override void Fix()
            {
                var dot = Shape as Dot;
                var parent = Shape.Parents[0];

                if (parent is Circle)
                {
                    var circle = parent as Circle;
                    dot.Coord = new Vector2(circle.Center.X + (float)Math.Cos(_ratio) * circle.Radius,
                                            circle.Center.Y + (float)Math.Sin(_ratio) * circle.Radius);
                }
                else if (parent is LineLike)
                {
                    var line = parent as LineLike;
{'fraction_non_alphanumeric': 0.08674329501915709, 'fraction_numerical': 0.0038314176245210726, 'mean_word_length': 0.9835866261398176, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6469876', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1716, 'n_words': 403}