<commit_before>// Copyright (c) 2007-2018 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Lines;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Rulesets.Osu.Objects;
using OpenTK;

namespace osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks.Components
{
    public class ControlPointPiece : CompositeDrawable
    {
        private readonly Slider slider;
        private readonly int index;

        private readonly Path path;
        private readonly CircularContainer marker;

        [Resolved]
        private OsuColour colours { get; set; }

        public ControlPointPiece(Slider slider, int index)
        {
            this.slider = slider;
            this.index = index;

            Origin = Anchor.Centre;
            AutoSizeAxes = Axes.Both;

            InternalChildren = new Drawable[]
            {
                path = new SmoothPath
                {
                    Anchor = Anchor.Centre,
                    PathWidth = 1
                },
                marker = new CircularContainer
                {
                    Anchor = Anchor.Centre,
                    Origin = Anchor.Centre,
                    Size = new Vector2(10),
                    Masking = true,
                    Child = new Box { RelativeSizeAxes = Axes.Both }
                }
            };
        }

        protected override void Update()
        {
            base.Update();

            Position = slider.StackedPosition + slider.ControlPoints[index];

            marker.Colour = isSegmentSeparator ? colours.Red : colours.Yellow;

            path.ClearVertices();

            if (index != slider.ControlPoints.Length - 1)
            {
                path.AddVertex(Vector2.Zero);
                path.AddVertex(slider.ControlPoints[index + 1] - slider.ControlPoints[index]);
            }

            path.OriginPosition = path.PositionInBoundingBox(Vector2.Zero);
        }

        public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => marker.ReceivePositionalInputAt(screenSpacePos);

        protected override bool OnDragStart(DragStartEvent e) => true;

        protected override bool OnDrag(DragEvent e)
        {
            if (index == 0)
            {
                // Special handling for the head - only the position of the slider changes
                slider.Position += e.Delta;

                // Since control points are relative to the position of the slider, they all need to be offset backwards by the delta
                var newControlPoints = slider.ControlPoints.ToArray();
                for (int i = 1; i < newControlPoints.Length; i++)
                    newControlPoints[i] -= e.Delta;

                slider.ControlPoints = newControlPoints;
                slider.Curve.Calculate(true);
            }
            else
            {
                var newControlPoints = slider.ControlPoints.ToArray();
                newControlPoints[index] += e.Delta;

                slider.ControlPoints = newControlPoints;
                slider.Curve.Calculate(true);
            }

            return true;
        }

        protected override bool OnDragEnd(DragEndEvent e) => true;

        private bool isSegmentSeparator
        {
            get
            {
                bool separator = false;

                if (index < slider.ControlPoints.Length - 1)
                    separator |= slider.ControlPoints[index + 1] == slider.ControlPoints[index];
                if (index > 0)
                    separator |= slider.ControlPoints[index - 1] == slider.ControlPoints[index];

                return separator;
            }
        }
    }
}<commit_msg>Fix segment control points not changing in unison<commit_after>// Copyright (c) 2007-2018 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Lines;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Rulesets.Osu.Objects;
using OpenTK;

namespace osu.Game.Rulesets.Osu.Edit.Masks.SliderMasks.Components
{
    public class ControlPointPiece : CompositeDrawable
    {
        private readonly Slider slider;
        private readonly int index;

        private readonly Path path;
        private readonly CircularContainer marker;

        [Resolved]
        private OsuColour colours { get; set; }

        public ControlPointPiece(Slider slider, int index)
        {
            this.slider = slider;
            this.index = index;

            Origin = Anchor.Centre;
            AutoSizeAxes = Axes.Both;

            InternalChildren = new Drawable[]
            {
                path = new SmoothPath
                {
                    Anchor = Anchor.Centre,
                    PathWidth = 1
                },
                marker = new CircularContainer
                {
                    Anchor = Anchor.Centre,
                    Origin = Anchor.Centre,
                    Size = new Vector2(10),
                    Masking = true,
                    Child = new Box { RelativeSizeAxes = Axes.Both }
                }
            };
        }

        protected override void Update()
        {
            base.Update();

            Position = slider.StackedPosition + slider.ControlPoints[index];

            marker.Colour = isSegmentSeparator ? colours.Red : colours.Yellow;

            path.ClearVertices();

            if (index != slider.ControlPoints.Length - 1)
            {
                path.AddVertex(Vector2.Zero);
                path.AddVertex(slider.ControlPoints[index + 1] - slider.ControlPoints[index]);
            }

            path.OriginPosition = path.PositionInBoundingBox(Vector2.Zero);
        }

        public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => marker.ReceivePositionalInputAt(screenSpacePos);

        protected override bool OnDragStart(DragStartEvent e) => true;

        protected override bool OnDrag(DragEvent e)
        {
            var newControlPoints = slider.ControlPoints.ToArray();

            if (index == 0)
            {
                // Special handling for the head - only the position of the slider changes
                slider.Position += e.Delta;

                // Since control points are relative to the position of the slider, they all need to be offset backwards by the delta
                for (int i = 1; i < newControlPoints.Length; i++)
                    newControlPoints[i] -= e.Delta;
            }
            else
                newControlPoints[index] += e.Delta;

            if (isSegmentSeparatorWithNext)
                newControlPoints[index + 1] = newControlPoints[index];

            if (isSegmentSeparatorWithPrevious)
                newControlPoints[index - 1] = newControlPoints[index];

            slider.ControlPoints = newControlPoints;
            slider.Curve.Calculate(true);

            return true;
        }

        protected override bool OnDragEnd(DragEndEvent e) => true;

        private bool isSegmentSeparator => isSegmentSeparatorWithNext || isSegmentSeparatorWithPrevious;

        private bool isSegmentSeparatorWithNext => index < slider.ControlPoints.Length - 1 && slider.ControlPoints[index + 1] == slider.ControlPoints[index];

        private bool isSegmentSeparatorWithPrevious => index > 0 && slider.ControlPoints[index - 1] == slider.ControlPoints[index];
    }
}
{'fraction_non_alphanumeric': 0.08179385909032998, 'fraction_numerical': 0.006115428717034017, 'mean_word_length': 1.7787610619469028, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 18, 'https://': 2, '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': '5014713', 'n_tokens_mistral': 2099, 'n_tokens_neox': 1916, 'n_words': 481}