//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
namespace ImageSharp.Drawing.Shapes
{
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using Paths;
///
/// Represents a polygon made up exclusivly of a single Linear path.
///
public sealed class LinearPolygon : IShape
{
private Polygon innerPolygon;
///
/// Initializes a new instance of the class.
///
/// The points.
public LinearPolygon(params Vector2[] points)
{
this.innerPolygon = new Polygon(new LinearLineSegment(points));
}
///
/// Gets the bounding box of this shape.
///
///
/// The bounds.
///
public RectangleF Bounds => this.innerPolygon.Bounds;
///
/// Gets the maximum number intersections that a shape can have when testing a line.
///
///
/// The maximum intersections.
///
public int MaxIntersections
{
get
{
return this.innerPolygon.MaxIntersections;
}
}
///
/// the distance of the point from the outline of the shape, if the value is negative it is inside the polygon bounds
///
/// The point.
///
/// Returns the distance from the shape to the point
///
public float Distance(Vector2 point) => this.innerPolygon.Distance(point);
///
/// Based on a line described by and
/// populate a buffer for all points on the polygon that the line intersects.
///
/// The start point of the line.
/// The end point of the line.
/// The buffer that will be populated with intersections.
/// The count.
/// The offset.
///
/// The number of intersections populated into the buffer.
///
public int FindIntersections(Vector2 start, Vector2 end, Vector2[] buffer, int count, int offset)
{
return this.innerPolygon.FindIntersections(start, end, buffer, count, offset);
}
///
/// Returns an enumerator that iterates through the collection.
///
///
/// An enumerator that can be used to iterate through the collection.
///
public IEnumerator GetEnumerator() => this.innerPolygon.GetEnumerator();
///
/// Returns an enumerator that iterates through a collection.
///
///
/// An object that can be used to iterate through the collection.
///
IEnumerator IEnumerable.GetEnumerator() => this.innerPolygon.GetEnumerator();
}
}