// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. using System; using System.Collections.Generic; namespace SixLabors.PolygonClipper { /// /// Describes the lowest vertex of an edge bound for the sweep line. /// internal readonly struct LocalMinima : IEquatable { /// /// Initializes a new instance of the struct. /// internal LocalMinima(SweepVertex vertex) => this.Vertex = vertex; /// /// Gets the vertex associated with this local minima. /// internal SweepVertex Vertex { get; } public static bool operator ==(LocalMinima lm1, LocalMinima lm2) => lm1.Equals(lm2); public static bool operator !=(LocalMinima lm1, LocalMinima lm2) => !(lm1 == lm2); public override bool Equals(object? obj) => obj is LocalMinima minima && this.Equals(minima); public override int GetHashCode() => this.Vertex.GetHashCode(); public bool Equals(LocalMinima other) => ReferenceEquals(this.Vertex, other.Vertex); } /// /// Orders local minima so higher Y-values are processed first during the sweep. /// internal sealed class LocalMinimaComparer : IComparer { public int Compare(LocalMinima locMin1, LocalMinima locMin2) => locMin2.Vertex.Point.Y.CompareTo(locMin1.Vertex.Point.Y); } }