<commit_before>// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.

using Avalonia.Platform;

namespace Avalonia.Media
{
    /// <summary>
    /// Represents the geometry of a line.
    /// </summary>
    public class LineGeometry : Geometry
    {
        /// <summary>
        /// Defines the <see cref="StartPoint"/> property.
        /// </summary>
        public static readonly StyledProperty<Point> StartPointProperty =
            AvaloniaProperty.Register<LineGeometry, Point>(nameof(StartPoint));

        public Point StartPoint
        {
            get => GetValue(StartPointProperty);
            set => SetValue(StartPointProperty, value);
        }

        /// <summary>
        /// Defines the <see cref="EndPoint"/> property.
        /// </summary>
        public static readonly StyledProperty<Point> EndPointProperty =
            AvaloniaProperty.Register<LineGeometry, Point>(nameof(EndPoint));
        private bool _isDirty;

        public Point EndPoint
        {
            get => GetValue(EndPointProperty);
            set => SetValue(EndPointProperty, value);
        }

        static LineGeometry()
        {
            StartPointProperty.Changed.AddClassHandler<LineGeometry>(x => x.PointsChanged);
            EndPointProperty.Changed.AddClassHandler<LineGeometry>(x => x.PointsChanged);
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="LineGeometry"/> class.
        /// </summary>
        public LineGeometry()
        {
            IPlatformRenderInterface factory = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>();
            PlatformImpl = factory.CreateStreamGeometry();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="LineGeometry"/> class.
        /// </summary>
        /// <param name="startPoint">The start point.</param>
        /// <param name="endPoint">The end point.</param>
        public LineGeometry(Point startPoint, Point endPoint) : this()
        {
            StartPoint = startPoint;
            EndPoint = endPoint;
        }

        public override IGeometryImpl PlatformImpl
        {
            get
            {
                PrepareIfNeeded();
                return base.PlatformImpl;
            }
            protected set => base.PlatformImpl = value;
        }

        public void PrepareIfNeeded()
        {
            if (_isDirty)
            {
                _isDirty = false;

                using (var context = ((IStreamGeometryImpl)PlatformImpl).Open())
                {
                    context.BeginFigure(StartPoint, false);
                    context.LineTo(EndPoint);
                    context.EndFigure(false);
                }
            }
        }

        /// <inheritdoc/>
        public override Geometry Clone()
        {
            PrepareIfNeeded();
            return new LineGeometry(StartPoint, EndPoint);
        }

        private void PointsChanged(AvaloniaPropertyChangedEventArgs e) => _isDirty = true;
    }
}
<commit_msg>Fixed #1152<commit_after>// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.

using Avalonia.Platform;

namespace Avalonia.Media
{
    /// <summary>
    /// Represents the geometry of a line.
    /// </summary>
    public class LineGeometry : Geometry
    {
        /// <summary>
        /// Defines the <see cref="StartPoint"/> property.
        /// </summary>
        public static readonly StyledProperty<Point> StartPointProperty =
            AvaloniaProperty.Register<LineGeometry, Point>(nameof(StartPoint));

        public Point StartPoint
        {
            get => GetValue(StartPointProperty);
            set => SetValue(StartPointProperty, value);
        }

        /// <summary>
        /// Defines the <see cref="EndPoint"/> property.
        /// </summary>
        public static readonly StyledProperty<Point> EndPointProperty =
            AvaloniaProperty.Register<LineGeometry, Point>(nameof(EndPoint));
        private bool _isDirty = true;

        public Point EndPoint
        {
            get => GetValue(EndPointProperty);
            set => SetValue(EndPointProperty, value);
        }

        static LineGeometry()
        {
            StartPointProperty.Changed.AddClassHandler<LineGeometry>(x => x.PointsChanged);
            EndPointProperty.Changed.AddClassHandler<LineGeometry>(x => x.PointsChanged);
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="LineGeometry"/> class.
        /// </summary>
        public LineGeometry()
        {
            IPlatformRenderInterface factory = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>();
            PlatformImpl = factory.CreateStreamGeometry();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="LineGeometry"/> class.
        /// </summary>
        /// <param name="startPoint">The start point.</param>
        /// <param name="endPoint">The end point.</param>
        public LineGeometry(Point startPoint, Point endPoint) : this()
        {
            StartPoint = startPoint;
            EndPoint = endPoint;
        }

        public override IGeometryImpl PlatformImpl
        {
            get
            {
                PrepareIfNeeded();
                return base.PlatformImpl;
            }
            protected set => base.PlatformImpl = value;
        }

        public void PrepareIfNeeded()
        {
            if (_isDirty)
            {
                _isDirty = false;

                using (var context = ((IStreamGeometryImpl)PlatformImpl).Open())
                {
                    context.BeginFigure(StartPoint, false);
                    context.LineTo(EndPoint);
                    context.EndFigure(false);
                }
            }
        }

        /// <inheritdoc/>
        public override Geometry Clone()
        {
            PrepareIfNeeded();
            return new LineGeometry(StartPoint, EndPoint);
        }

        private void PointsChanged(AvaloniaPropertyChangedEventArgs e) => _isDirty = true;
    }
}

{'fraction_non_alphanumeric': 0.10197941409342834, 'fraction_numerical': 0.0006334125098970705, 'mean_word_length': 1.7677475898334793, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 71, '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': '662715', 'n_tokens_mistral': 1570, 'n_tokens_neox': 1521, 'n_words': 370}