зеркало из https://github.com/SixLabors/Shapes.git
dropped point struct in favour of Vector2
This commit is contained in:
Родитель
49dd434333
Коммит
aa73628a49
|
@ -26,14 +26,14 @@ namespace Shaper2D
|
|||
/// <summary>
|
||||
/// The line points.
|
||||
/// </summary>
|
||||
private readonly ImmutableArray<Point> linePoints;
|
||||
private readonly Point[] controlPoints;
|
||||
private readonly ImmutableArray<Vector2> linePoints;
|
||||
private readonly Vector2[] controlPoints;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BezierLineSegment"/> class.
|
||||
/// </summary>
|
||||
/// <param name="points">The points.</param>
|
||||
public BezierLineSegment(Point[] points)
|
||||
public BezierLineSegment(Vector2[] points)
|
||||
{
|
||||
Guard.NotNull(points, nameof(points));
|
||||
Guard.MustBeGreaterThanOrEqualTo(points.Length, 4, nameof(points));
|
||||
|
@ -58,7 +58,7 @@ namespace Shaper2D
|
|||
/// <param name="controlPoint2">The control point2.</param>
|
||||
/// <param name="end">The end.</param>
|
||||
/// <param name="additionalPoints">The additional points.</param>
|
||||
public BezierLineSegment(Point start, Point controlPoint1, Point controlPoint2, Point end, params Point[] additionalPoints)
|
||||
public BezierLineSegment(Vector2 start, Vector2 controlPoint1, Vector2 controlPoint2, Vector2 end, params Vector2[] additionalPoints)
|
||||
: this(new[] { start, controlPoint1, controlPoint2, end }.Merge(additionalPoints))
|
||||
{
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ namespace Shaper2D
|
|||
/// <value>
|
||||
/// The end point.
|
||||
/// </value>
|
||||
public Point EndPoint { get; private set; }
|
||||
public Vector2 EndPoint { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current <see cref="ILineSegment" /> a simple linear path.
|
||||
|
@ -77,7 +77,7 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// Returns the current <see cref="ILineSegment" /> as simple linear path.
|
||||
/// </returns>
|
||||
public ImmutableArray<Point> Flatten()
|
||||
public ImmutableArray<Vector2> Flatten()
|
||||
{
|
||||
return this.linePoints;
|
||||
}
|
||||
|
@ -95,11 +95,11 @@ namespace Shaper2D
|
|||
return this;
|
||||
}
|
||||
|
||||
var points = new Point[this.controlPoints.Length];
|
||||
var points = new Vector2[this.controlPoints.Length];
|
||||
var i = 0;
|
||||
foreach (var p in this.controlPoints)
|
||||
{
|
||||
points[i++] = p.Transform(matrix);
|
||||
points[i++] = Vector2.Transform(p, matrix);
|
||||
}
|
||||
|
||||
return new BezierLineSegment(points);
|
||||
|
@ -112,13 +112,13 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// The <see cref="T:Vector2[]"/>.
|
||||
/// </returns>
|
||||
private ImmutableArray<Point> GetDrawingPoints(Point[] controlPoints)
|
||||
private ImmutableArray<Vector2> GetDrawingPoints(Vector2[] controlPoints)
|
||||
{
|
||||
// TODO we need to calculate an optimal SegmentsPerCurve value depending on the calculated length of this curve
|
||||
int curveCount = (controlPoints.Length - 1) / 3;
|
||||
int finalPointCount = (SegmentsPerCurve * curveCount) + 1; // we have SegmentsPerCurve for each curve plus the origon point;
|
||||
|
||||
Point[] drawingPoints = new Point[finalPointCount];
|
||||
Vector2[] drawingPoints = new Vector2[finalPointCount];
|
||||
|
||||
int position = 0;
|
||||
int targetPoint = controlPoints.Length - 3;
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
// <copyright file="ClipperExtensions.cs" company="Scott Williams">
|
||||
// Copyright (c) Scott Williams and contributors.
|
||||
// Licensed under the Apache License, Version 2.0.
|
||||
// </copyright>
|
||||
|
||||
namespace Shaper2D
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Shaper2D.PolygonClipper;
|
||||
|
||||
/// <summary>
|
||||
/// Clipping extensions for shapes
|
||||
/// </summary>
|
||||
public static class ClipperExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Clips the specified holes.
|
||||
/// </summary>
|
||||
/// <param name="shape">The shape.</param>
|
||||
/// <param name="holes">The holes.</param>
|
||||
/// <returns>Returns a new shape with the holes cliped out out the shape.</returns>
|
||||
public static IShape Clip(this IShape shape, IEnumerable<IShape> holes)
|
||||
{
|
||||
var clipper = new PolygonClipper.Clipper();
|
||||
|
||||
clipper.AddShape(shape, ClippingType.Subject);
|
||||
clipper.AddShapes(holes, ClippingType.Clip);
|
||||
var result = clipper.GenerateClippedShapes();
|
||||
return new ComplexPolygon(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clips the specified holes.
|
||||
/// </summary>
|
||||
/// <param name="shape">The shape.</param>
|
||||
/// <param name="holes">The holes.</param>
|
||||
/// <returns>Returns a new shape with the holes cliped out out the shape.</returns>
|
||||
public static IShape Clip(this IShape shape, params IShape[] holes) => shape.Clip((IEnumerable<IShape>)holes);
|
||||
}
|
||||
}
|
|
@ -21,14 +21,14 @@ namespace Shaper2D
|
|||
public sealed class ComplexPolygon : IShape
|
||||
{
|
||||
private const float ClipperScaleFactor = 100f;
|
||||
private IShape[] shapes;
|
||||
private ImmutableArray<IShape> shapes;
|
||||
private ImmutableArray<IPath> paths;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ComplexPolygon" /> class.
|
||||
/// Initializes a new instance of the <see cref="ComplexPolygon"/> class.
|
||||
/// </summary>
|
||||
/// <param name="shapes">The shapes.</param>
|
||||
public ComplexPolygon(params IShape[] shapes)
|
||||
public ComplexPolygon(ImmutableArray<IShape> shapes)
|
||||
{
|
||||
Guard.NotNull(shapes, nameof(shapes));
|
||||
Guard.MustBeGreaterThanOrEqualTo(shapes.Length, 1, nameof(shapes));
|
||||
|
@ -76,6 +76,15 @@ namespace Shaper2D
|
|||
this.Bounds = new Rectangle(minX, minY, maxX - minX, maxY - minY);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ComplexPolygon" /> class.
|
||||
/// </summary>
|
||||
/// <param name="shapes">The shapes.</param>
|
||||
public ComplexPolygon(params IShape[] shapes)
|
||||
: this(ImmutableArray.Create(shapes))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the paths that make up this shape
|
||||
/// </summary>
|
||||
|
@ -112,7 +121,7 @@ namespace Shaper2D
|
|||
/// therefore for apoint to be in more that one we must be in a hole of another, theoretically this could
|
||||
/// then flip again to be in a outlin inside a hole inside an outline :)
|
||||
/// </remarks>
|
||||
float IShape.Distance(Point point)
|
||||
float IShape.Distance(Vector2 point)
|
||||
{
|
||||
float dist = float.MaxValue;
|
||||
bool inside = false;
|
||||
|
@ -154,7 +163,7 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// The number of intersections populated into the buffer.
|
||||
/// </returns>
|
||||
public int FindIntersections(Point start, Point end, Point[] buffer, int count, int offset)
|
||||
public int FindIntersections(Vector2 start, Vector2 end, Vector2[] buffer, int count, int offset)
|
||||
{
|
||||
int totalAdded = 0;
|
||||
for (int i = 0; i < this.shapes.Length; i++)
|
||||
|
@ -175,7 +184,7 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// <c>true</c> if the <see cref="IShape" /> contains the specified point; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public bool Contains(Point point)
|
||||
public bool Contains(Vector2 point)
|
||||
{
|
||||
bool inside = false;
|
||||
foreach (IShape shape in this.shapes)
|
||||
|
@ -198,7 +207,7 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// The locations along the line segment that intersect with the edges of the shape.
|
||||
/// </returns>
|
||||
public IEnumerable<Point> FindIntersections(Point start, Point end)
|
||||
public IEnumerable<Vector2> FindIntersections(Vector2 start, Vector2 end)
|
||||
{
|
||||
for (int i = 0; i < this.shapes.Length; i++)
|
||||
{
|
||||
|
|
|
@ -19,13 +19,13 @@ namespace Shaper2D
|
|||
/// <value>
|
||||
/// The end point.
|
||||
/// </value>
|
||||
Point EndPoint { get; }
|
||||
Vector2 EndPoint { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Converts the <see cref="ILineSegment" /> into a simple linear path..
|
||||
/// </summary>
|
||||
/// <returns>Returns the current <see cref="ILineSegment" /> as simple linear path.</returns>
|
||||
ImmutableArray<Point> Flatten();
|
||||
ImmutableArray<Vector2> Flatten();
|
||||
|
||||
/// <summary>
|
||||
/// Transforms the current LineSegment using specified matrix.
|
||||
|
|
|
@ -36,13 +36,13 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// Returns details about the point and its distance away from the path.
|
||||
/// </returns>
|
||||
PointInfo Distance(Point point);
|
||||
PointInfo Distance(Vector2 point);
|
||||
|
||||
/// <summary>
|
||||
/// Converts the <see cref="IPath" /> into a simple linear path..
|
||||
/// </summary>
|
||||
/// <returns>Returns the current <see cref="IPath" /> as simple linear path.</returns>
|
||||
ImmutableArray<Point> Flatten();
|
||||
ImmutableArray<Vector2> Flatten();
|
||||
|
||||
/// <summary>
|
||||
/// Transforms the path using the specified matrix.
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// Returns the distance from the shape to the point
|
||||
/// </returns>
|
||||
float Distance(Point point);
|
||||
float Distance(Vector2 point);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the <see cref="IShape"/> contains the specified point
|
||||
|
@ -54,7 +54,7 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// <c>true</c> if the <see cref="IShape"/> contains the specified point; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
bool Contains(Point point);
|
||||
bool Contains(Vector2 point);
|
||||
|
||||
/// <summary>
|
||||
/// Based on a line described by <paramref name="start"/> and <paramref name="end"/>
|
||||
|
@ -68,7 +68,7 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// The number of intersections populated into the buffer.
|
||||
/// </returns>
|
||||
int FindIntersections(Point start, Point end, Point[] buffer, int count, int offset);
|
||||
int FindIntersections(Vector2 start, Vector2 end, Vector2[] buffer, int count, int offset);
|
||||
|
||||
/// <summary>
|
||||
/// Based on a line described by <paramref name="start"/> and <paramref name="end"/>
|
||||
|
@ -77,7 +77,7 @@ namespace Shaper2D
|
|||
/// <param name="start">The start.</param>
|
||||
/// <param name="end">The end.</param>
|
||||
/// <returns>The locations along the line segment that intersect with the edges of the shape.</returns>
|
||||
IEnumerable<Point> FindIntersections(Point start, Point end);
|
||||
IEnumerable<Vector2> FindIntersections(Vector2 start, Vector2 end);
|
||||
|
||||
/// <summary>
|
||||
/// Transforms the shape using the specified matrix.
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace Shaper2D
|
|||
/// <summary>
|
||||
/// The points.
|
||||
/// </summary>
|
||||
private readonly ImmutableArray<Point> points;
|
||||
private readonly ImmutableArray<Vector2> points;
|
||||
|
||||
/// <summary>
|
||||
/// The closed path.
|
||||
|
@ -86,7 +86,7 @@ namespace Shaper2D
|
|||
/// </summary>
|
||||
/// <param name="points">The points.</param>
|
||||
/// <param name="isClosedPath">if set to <c>true</c> [is closed path].</param>
|
||||
internal InternalPath(ImmutableArray<Point> points, bool isClosedPath)
|
||||
internal InternalPath(ImmutableArray<Vector2> points, bool isClosedPath)
|
||||
{
|
||||
this.points = points;
|
||||
this.closedPath = isClosedPath;
|
||||
|
@ -140,7 +140,7 @@ namespace Shaper2D
|
|||
/// <value>
|
||||
/// The points.
|
||||
/// </value>
|
||||
internal ImmutableArray<Point> Points => this.points;
|
||||
internal ImmutableArray<Vector2> Points => this.points;
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the distance from the path.
|
||||
|
@ -195,7 +195,7 @@ namespace Shaper2D
|
|||
/// <param name="count">The count.</param>
|
||||
/// <param name="offset">The offset.</param>
|
||||
/// <returns>number iof intersections hit</returns>
|
||||
public int FindIntersections(Vector2 start, Vector2 end, Point[] buffer, int count, int offset)
|
||||
public int FindIntersections(Vector2 start, Vector2 end, Vector2[] buffer, int count, int offset)
|
||||
{
|
||||
int polyCorners = this.points.Length;
|
||||
|
||||
|
@ -216,7 +216,7 @@ namespace Shaper2D
|
|||
Vector2 point = FindIntersection(this.points[i], this.points[next], start, end);
|
||||
if (point != MaxVector)
|
||||
{
|
||||
if (this.points[i].ToVector2() != point || (this.closedPath && i == 0))
|
||||
if (this.points[i] != point || (this.closedPath && i == 0))
|
||||
{
|
||||
// we skip starts and get it next time unless its an open path and this is the first seg
|
||||
buffer[position + offset] = point;
|
||||
|
@ -235,9 +235,9 @@ namespace Shaper2D
|
|||
/// <param name="start">The start.</param>
|
||||
/// <param name="end">The end.</param>
|
||||
/// <returns>The points along the line the intersect with the boundaries of the polygon.</returns>
|
||||
public IEnumerable<Point> FindIntersections(Vector2 start, Vector2 end)
|
||||
public IEnumerable<Vector2> FindIntersections(Vector2 start, Vector2 end)
|
||||
{
|
||||
var buffer = ArrayPool<Point>.Shared.Rent(this.points.Length);
|
||||
var buffer = ArrayPool<Vector2>.Shared.Rent(this.points.Length);
|
||||
try
|
||||
{
|
||||
var hits = this.FindIntersections(start, end, buffer, this.points.Length, 0);
|
||||
|
@ -248,7 +248,7 @@ namespace Shaper2D
|
|||
}
|
||||
finally
|
||||
{
|
||||
ArrayPool<Point>.Shared.Return(buffer);
|
||||
ArrayPool<Vector2>.Shared.Return(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,7 +257,7 @@ namespace Shaper2D
|
|||
/// </summary>
|
||||
/// <param name="point">The point.</param>
|
||||
/// <returns>Returns true if the point is inside the closed path.</returns>
|
||||
public bool PointInPolygon(Point point)
|
||||
public bool PointInPolygon(Vector2 point)
|
||||
{
|
||||
// You can only be inside a path if its "closed"
|
||||
if (!this.closedPath)
|
||||
|
@ -295,7 +295,7 @@ namespace Shaper2D
|
|||
{
|
||||
inside ^= true;
|
||||
|
||||
if (p == this.points[i].ToVector2())
|
||||
if (p == this.points[i])
|
||||
{
|
||||
// if left point is the match then skip it we will hit it on the way around on the right
|
||||
inside ^= true;
|
||||
|
@ -415,9 +415,9 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// The <see cref="T:Vector2[]"/>.
|
||||
/// </returns>
|
||||
private static ImmutableArray<Point> Simplify(ImmutableArray<ILineSegment> segments)
|
||||
private static ImmutableArray<Vector2> Simplify(ImmutableArray<ILineSegment> segments)
|
||||
{
|
||||
List<Point> simplified = new List<Point>();
|
||||
List<Vector2> simplified = new List<Vector2>();
|
||||
foreach (ILineSegment seg in segments)
|
||||
{
|
||||
simplified.AddRange(seg.Flatten());
|
||||
|
@ -474,7 +474,7 @@ namespace Shaper2D
|
|||
return;
|
||||
}
|
||||
|
||||
ImmutableArray<Point> poly = this.points;
|
||||
ImmutableArray<Vector2> poly = this.points;
|
||||
int polyCorners = poly.Length;
|
||||
this.distance = new float[polyCorners];
|
||||
|
||||
|
@ -550,27 +550,7 @@ namespace Shaper2D
|
|||
/// <summary>
|
||||
/// The point on the current line.
|
||||
/// </summary>
|
||||
public Point PointOnLine;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transforms the specified matrix.
|
||||
/// </summary>
|
||||
/// <param name="matrix">The matrix.</param>
|
||||
/// <returns></returns>
|
||||
public InternalPath Transform(Matrix3x2 matrix)
|
||||
{
|
||||
if (matrix.IsIdentity)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
var transformedpoints = new Point[this.points.Length];
|
||||
for (var i = 0; i < this.points.Length; i++)
|
||||
{
|
||||
transformedpoints[i] = this.points[i].Transform(matrix);
|
||||
}
|
||||
return new InternalPath(ImmutableArray.Create(transformedpoints), this.closedPath);
|
||||
public Vector2 PointOnLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,14 +19,14 @@ namespace Shaper2D
|
|||
/// <summary>
|
||||
/// The collection of points.
|
||||
/// </summary>
|
||||
private readonly ImmutableArray<Point> points;
|
||||
private readonly ImmutableArray<Vector2> points;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LinearLineSegment"/> class.
|
||||
/// </summary>
|
||||
/// <param name="start">The start.</param>
|
||||
/// <param name="end">The end.</param>
|
||||
public LinearLineSegment(Point start, Point end)
|
||||
public LinearLineSegment(Vector2 start, Vector2 end)
|
||||
: this(new[] { start, end })
|
||||
{
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ namespace Shaper2D
|
|||
/// <param name="point1">The point1.</param>
|
||||
/// <param name="point2">The point2.</param>
|
||||
/// <param name="additionalPoints">Additional points</param>
|
||||
public LinearLineSegment(Point point1, Point point2, params Point[] additionalPoints)
|
||||
public LinearLineSegment(Vector2 point1, Vector2 point2, params Vector2[] additionalPoints)
|
||||
: this(new[] { point1, point2 }.Merge(additionalPoints))
|
||||
{
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ namespace Shaper2D
|
|||
/// Initializes a new instance of the <see cref="LinearLineSegment"/> class.
|
||||
/// </summary>
|
||||
/// <param name="points">The points.</param>
|
||||
public LinearLineSegment(Point[] points)
|
||||
public LinearLineSegment(Vector2[] points)
|
||||
{
|
||||
Guard.NotNull(points, nameof(points));
|
||||
Guard.MustBeGreaterThanOrEqualTo(points.Count(), 2, nameof(points));
|
||||
|
@ -62,7 +62,7 @@ namespace Shaper2D
|
|||
/// <value>
|
||||
/// The end point.
|
||||
/// </value>
|
||||
public Point EndPoint { get; private set; }
|
||||
public Vector2 EndPoint { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Converts the <see cref="ILineSegment" /> into a simple linear path..
|
||||
|
@ -70,7 +70,7 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// Returns the current <see cref="ILineSegment" /> as simple linear path.
|
||||
/// </returns>
|
||||
public ImmutableArray<Point> Flatten()
|
||||
public ImmutableArray<Vector2> Flatten()
|
||||
{
|
||||
return this.points;
|
||||
}
|
||||
|
@ -90,11 +90,11 @@ namespace Shaper2D
|
|||
return this;
|
||||
}
|
||||
|
||||
var points = new Point[this.points.Length];
|
||||
var points = new Vector2[this.points.Length];
|
||||
var i = 0;
|
||||
foreach (var p in this.points)
|
||||
{
|
||||
points[i++] = p.Transform(matrix);
|
||||
points[i++] = Vector2.Transform(p, matrix);
|
||||
}
|
||||
|
||||
return new LinearLineSegment(points);
|
||||
|
|
|
@ -53,13 +53,13 @@ namespace Shaper2D
|
|||
public float Length => this.innerPath.Length;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ImmutableArray<Point> Flatten()
|
||||
public ImmutableArray<Vector2> Flatten()
|
||||
{
|
||||
return this.innerPath.Points;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public PointInfo Distance(Point point)
|
||||
public PointInfo Distance(Vector2 point)
|
||||
{
|
||||
return this.innerPath.DistanceFromPath(point);
|
||||
}
|
||||
|
|
|
@ -1,244 +0,0 @@
|
|||
// <copyright file="Point.cs" company="Scott Williams">
|
||||
// Copyright (c) Scott Williams and contributors.
|
||||
// Licensed under the Apache License, Version 2.0.
|
||||
// </copyright>
|
||||
|
||||
namespace Shaper2D
|
||||
{
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an ordered pair of integer x- and y-coordinates that defines a point in
|
||||
/// a two-dimensional plane.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This struct is fully mutable. This is done (against the guidelines) for the sake of performance,
|
||||
/// as it avoids the need to create new values for modification operations.
|
||||
/// </remarks>
|
||||
public struct Point : IEquatable<Point>
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an unset <see cref="Point"/>.
|
||||
/// </summary>
|
||||
public static readonly Point Empty = default(Point);
|
||||
|
||||
/// <summary>
|
||||
/// Represents a <see cref="Point"/> that has X and Y values set to zero.
|
||||
/// </summary>
|
||||
public static readonly Point Zero = new Point(0, 0);
|
||||
|
||||
private readonly Vector2 backingVector;
|
||||
|
||||
private bool isSet;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Point"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="x">The horizontal position of the point.</param>
|
||||
/// <param name="y">The vertical position of the point.</param>
|
||||
public Point(float x, float y)
|
||||
: this(new Vector2(x, y))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Point"/> struct.
|
||||
/// </summary>
|
||||
/// <param name="vector">
|
||||
/// The vector representing the width and height.
|
||||
/// </param>
|
||||
public Point(Vector2 vector)
|
||||
{
|
||||
this.backingVector = vector;
|
||||
this.isSet = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the x-coordinate of this <see cref="Point"/>.
|
||||
/// </summary>
|
||||
public float X => this.backingVector.X;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the y-coordinate of this <see cref="Point"/>.
|
||||
/// </summary>
|
||||
public float Y => this.backingVector.Y;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this <see cref="Point"/> is empty.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public bool IsEmpty => !this.isSet;
|
||||
|
||||
/// <summary>
|
||||
/// Performs an implicit conversion from <see cref="Point"/> to <see cref="Vector2"/>.
|
||||
/// </summary>
|
||||
/// <param name="d">The d.</param>
|
||||
/// <returns>
|
||||
/// The result of the conversion.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator Vector2(Point d)
|
||||
{
|
||||
return d.backingVector;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an implicit conversion from <see cref="Vector2"/> to <see cref="Point"/>.
|
||||
/// </summary>
|
||||
/// <param name="d">The d.</param>
|
||||
/// <returns>
|
||||
/// The result of the conversion.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator Point(Vector2 d)
|
||||
{
|
||||
return new Point(d);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the sum of adding two points.
|
||||
/// </summary>
|
||||
/// <param name="left">The point on the left hand of the operand.</param>
|
||||
/// <param name="right">The point on the right hand of the operand.</param>
|
||||
/// <returns>
|
||||
/// The <see cref="Point"/>
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Point operator +(Point left, Point right)
|
||||
{
|
||||
return new Point(left.backingVector + right.backingVector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the difference left by subtracting one point from another.
|
||||
/// </summary>
|
||||
/// <param name="left">The point on the left hand of the operand.</param>
|
||||
/// <param name="right">The point on the right hand of the operand.</param>
|
||||
/// <returns>
|
||||
/// The <see cref="Point"/>
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Point operator -(Point left, Point right)
|
||||
{
|
||||
return new Point(left.backingVector - right.backingVector);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Point"/> objects for equality.
|
||||
/// </summary>
|
||||
/// <param name="left">
|
||||
/// The <see cref="Point"/> on the left side of the operand.
|
||||
/// </param>
|
||||
/// <param name="right">
|
||||
/// The <see cref="Point"/> on the right side of the operand.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// True if the current left is equal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Point left, Point right)
|
||||
{
|
||||
if (left.isSet && right.isSet)
|
||||
{
|
||||
return left.backingVector == right.backingVector;
|
||||
}
|
||||
|
||||
return left.isSet == right.isSet;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two <see cref="Point"/> objects for inequality.
|
||||
/// </summary>
|
||||
/// <param name="left">
|
||||
/// The <see cref="Point"/> on the left side of the operand.
|
||||
/// </param>
|
||||
/// <param name="right">
|
||||
/// The <see cref="Point"/> on the right side of the operand.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// True if the current left is unequal to the <paramref name="right"/> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Point left, Point right)
|
||||
{
|
||||
if (left.isSet && right.isSet)
|
||||
{
|
||||
return left.backingVector != right.backingVector;
|
||||
}
|
||||
|
||||
return left.isSet != right.isSet;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Vector2"/> representation for this <see cref="Point"/>.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Vector2"/> representation for this object.</returns>
|
||||
public Vector2 ToVector2()
|
||||
{
|
||||
return this.backingVector;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Translates this <see cref="Point" /> by the specified amount.
|
||||
/// </summary>
|
||||
/// <param name="p">The <see cref="Point" /> used offset this <see cref="Point" />.</param>
|
||||
/// <returns>A new point offset by the size</returns>
|
||||
public Point Offset(Size p)
|
||||
{
|
||||
return new Point(this.backingVector + p.ToVector2());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the specified matrix to this point
|
||||
/// </summary>
|
||||
/// <param name="matrix">The matrix.</param>
|
||||
/// <returns>A new point with the transofrm applied upon it.</returns>
|
||||
public Point Transform(Matrix3x2 matrix)
|
||||
{
|
||||
return new Point(Vector2.Transform(this.backingVector, matrix));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.backingVector.GetHashCode();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
if (this.IsEmpty)
|
||||
{
|
||||
return "Point [ Empty ]";
|
||||
}
|
||||
|
||||
return $"Point [ X={this.X}, Y={this.Y} ]";
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is Point)
|
||||
{
|
||||
return this == (Point)obj;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the current object is equal to another object of the same type.
|
||||
/// </summary>
|
||||
/// <param name="other">An object to compare with this object.</param>
|
||||
/// <returns>
|
||||
/// true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.
|
||||
/// </returns>
|
||||
public bool Equals(Point other)
|
||||
{
|
||||
return this == other;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ namespace Shaper2D
|
|||
/// <summary>
|
||||
/// The search point
|
||||
/// </summary>
|
||||
public Point SearchPoint;
|
||||
public Vector2 SearchPoint;
|
||||
|
||||
/// <summary>
|
||||
/// The distance along path <see cref="ClosestPointOnPath"/> is away from the start of the path
|
||||
|
@ -30,6 +30,6 @@ namespace Shaper2D
|
|||
/// <summary>
|
||||
/// The closest point to <see cref="SearchPoint"/> that lies on the path.
|
||||
/// </summary>
|
||||
public Point ClosestPointOnPath;
|
||||
public Vector2 ClosestPointOnPath;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// The distance of the point away from the shape
|
||||
/// </returns>
|
||||
public float Distance(Point point)
|
||||
public float Distance(Vector2 point)
|
||||
{
|
||||
bool isInside = this.innerPath.PointInPolygon(point);
|
||||
if (isInside)
|
||||
|
@ -115,7 +115,7 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// <c>true</c> if the <see cref="IShape" /> contains the specified point; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public bool Contains(Point point)
|
||||
public bool Contains(Vector2 point)
|
||||
{
|
||||
return this.innerPath.PointInPolygon(point);
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// distance metadata about the point.
|
||||
/// </returns>
|
||||
PointInfo IPath.Distance(Point point)
|
||||
PointInfo IPath.Distance(Vector2 point)
|
||||
{
|
||||
return this.innerPath.DistanceFromPath(point);
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// Returns the current <see cref="ILineSegment" /> as simple linear path.
|
||||
/// </returns>
|
||||
public ImmutableArray<Point> Flatten()
|
||||
public ImmutableArray<Vector2> Flatten()
|
||||
{
|
||||
return this.innerPath.Points;
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// The number of intersections populated into the buffer.
|
||||
/// </returns>
|
||||
public int FindIntersections(Point start, Point end, Point[] buffer, int count, int offset)
|
||||
public int FindIntersections(Vector2 start, Vector2 end, Vector2[] buffer, int count, int offset)
|
||||
{
|
||||
return this.innerPath.FindIntersections(start, end, buffer, count, offset);
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// The locations along the line segment that intersect with the edges of the shape.
|
||||
/// </returns>
|
||||
public IEnumerable<Point> FindIntersections(Point start, Point end)
|
||||
public IEnumerable<Vector2> FindIntersections(Vector2 start, Vector2 end)
|
||||
{
|
||||
return this.innerPath.FindIntersections(start, end);
|
||||
}
|
||||
|
|
|
@ -2442,7 +2442,7 @@ namespace Shaper2D.PolygonClipper
|
|||
}
|
||||
else
|
||||
{
|
||||
var points = new Point[cnt];
|
||||
var points = new Vector2[cnt];
|
||||
OutPoint op = outRec.Points.Previous;
|
||||
for (int j = 0; j < cnt; j++)
|
||||
{
|
||||
|
|
|
@ -14,14 +14,14 @@ namespace Shaper2D
|
|||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
/// A way of optermising drawing rectangles.
|
||||
/// A way of optimizing drawing rectangles.
|
||||
/// </summary>
|
||||
/// <seealso cref="Shaper2D.IShape" />
|
||||
public class Rectangle : IShape, IPath
|
||||
{
|
||||
private readonly Vector2 topLeft;
|
||||
private readonly Vector2 bottomRight;
|
||||
private readonly ImmutableArray<Point> points;
|
||||
private readonly ImmutableArray<Vector2> points;
|
||||
private readonly ImmutableArray<IPath> pathCollection;
|
||||
private readonly float halfLength;
|
||||
private readonly float length;
|
||||
|
@ -34,7 +34,7 @@ namespace Shaper2D
|
|||
/// <param name="width">The width.</param>
|
||||
/// <param name="height">The height.</param>
|
||||
public Rectangle(float x, float y, float width, float height)
|
||||
: this(new Point(x, y), new Size(width, height))
|
||||
: this(new Vector2(x, y), new Size(width, height))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -43,14 +43,14 @@ namespace Shaper2D
|
|||
/// </summary>
|
||||
/// <param name="topLeft">The top left.</param>
|
||||
/// <param name="bottomRight">The bottom right.</param>
|
||||
public Rectangle(Point topLeft, Point bottomRight)
|
||||
public Rectangle(Vector2 topLeft, Vector2 bottomRight)
|
||||
{
|
||||
this.Location = topLeft;
|
||||
this.topLeft = topLeft;
|
||||
this.bottomRight = bottomRight;
|
||||
this.Size = new Size(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y);
|
||||
|
||||
this.points = ImmutableArray.Create(new Point[4]
|
||||
this.points = ImmutableArray.Create(new Vector2[4]
|
||||
{
|
||||
this.topLeft,
|
||||
new Vector2(this.bottomRight.X, this.topLeft.Y),
|
||||
|
@ -68,8 +68,8 @@ namespace Shaper2D
|
|||
/// </summary>
|
||||
/// <param name="location">The location.</param>
|
||||
/// <param name="size">The size.</param>
|
||||
public Rectangle(Point location, Size size)
|
||||
: this(location, location.Offset(size))
|
||||
public Rectangle(Vector2 location, Size size)
|
||||
: this(location, location + size.ToVector2())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ namespace Shaper2D
|
|||
/// <value>
|
||||
/// The location.
|
||||
/// </value>
|
||||
public Point Location { get; }
|
||||
public Vector2 Location { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the left.
|
||||
|
@ -185,10 +185,9 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// The <see cref="bool" />
|
||||
/// </returns>
|
||||
public bool Contains(Point point)
|
||||
public bool Contains(Vector2 point)
|
||||
{
|
||||
var v = point.ToVector2();
|
||||
return Vector2.Clamp(v, this.topLeft, this.bottomRight) == v;
|
||||
return Vector2.Clamp(point, this.topLeft, this.bottomRight) == point;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -198,7 +197,7 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// Returns details about the point and its distance away from the path.
|
||||
/// </returns>
|
||||
PointInfo IPath.Distance(Point point)
|
||||
PointInfo IPath.Distance(Vector2 point)
|
||||
{
|
||||
bool inside; // dont care about inside/outside for paths just distance
|
||||
return this.Distance(point, false, out inside);
|
||||
|
@ -222,7 +221,7 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// Returns the distance from the shape to the point
|
||||
/// </returns>
|
||||
public float Distance(Point point)
|
||||
public float Distance(Vector2 point)
|
||||
{
|
||||
bool insidePoly;
|
||||
PointInfo result = this.Distance(point, true, out insidePoly);
|
||||
|
@ -240,9 +239,9 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// The locations along the line segment that intersect with the edges of the shape.
|
||||
/// </returns>
|
||||
public IEnumerable<Point> FindIntersections(Point start, Point end)
|
||||
public IEnumerable<Vector2> FindIntersections(Vector2 start, Vector2 end)
|
||||
{
|
||||
var buffer = new Point[2];
|
||||
var buffer = new Vector2[2];
|
||||
var c = this.FindIntersections(start, end, buffer, 2, 0);
|
||||
switch (c)
|
||||
{
|
||||
|
@ -251,7 +250,7 @@ namespace Shaper2D
|
|||
case 1:
|
||||
return new[] { buffer[0] };
|
||||
default:
|
||||
return Enumerable.Empty<Point>();
|
||||
return Enumerable.Empty<Vector2>();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,14 +267,14 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// The number of intersections populated into the buffer.
|
||||
/// </returns>
|
||||
public int FindIntersections(Point start, Point end, Point[] buffer, int count, int offset)
|
||||
public int FindIntersections(Vector2 start, Vector2 end, Vector2[] buffer, int count, int offset)
|
||||
{
|
||||
int discovered = 0;
|
||||
Vector2 startPoint = Vector2.Clamp(start, this.topLeft, this.bottomRight);
|
||||
Vector2 endPoint = Vector2.Clamp(end, this.topLeft, this.bottomRight);
|
||||
|
||||
// start doesn't change when its inside the shape thus not crossing
|
||||
if (startPoint != start.ToVector2())
|
||||
if (startPoint != start)
|
||||
{
|
||||
if (startPoint == Vector2.Clamp(startPoint, start, end))
|
||||
{
|
||||
|
@ -286,7 +285,7 @@ namespace Shaper2D
|
|||
}
|
||||
|
||||
// end didn't change it must not intercept with an edge
|
||||
if (endPoint != end.ToVector2())
|
||||
if (endPoint != end)
|
||||
{
|
||||
if (endPoint == Vector2.Clamp(endPoint, start, end))
|
||||
{
|
||||
|
@ -334,7 +333,7 @@ namespace Shaper2D
|
|||
/// <returns>
|
||||
/// Returns the current <see cref="ILineSegment" /> as simple linear path.
|
||||
/// </returns>
|
||||
ImmutableArray<Point> IPath.Flatten()
|
||||
ImmutableArray<Vector2> IPath.Flatten()
|
||||
{
|
||||
return this.points;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace Shaper2D
|
|||
private readonly List<ILineSegment[]> figures = new List<ILineSegment[]>();
|
||||
private readonly List<ILineSegment> segments = new List<ILineSegment>();
|
||||
private readonly Matrix3x2 defaultTransform;
|
||||
private Point currentPoint = Point.Empty;
|
||||
private Vector2 currentPoint = Vector2.Zero;
|
||||
private Matrix3x2 currentTransform;
|
||||
|
||||
/// <summary>
|
||||
|
@ -52,7 +52,7 @@ namespace Shaper2D
|
|||
/// Sets the origin all subsequent point should be relative to.
|
||||
/// </summary>
|
||||
/// <param name="origin">The origin.</param>
|
||||
public void SetOrigin(Point origin)
|
||||
public void SetOrigin(Vector2 origin)
|
||||
{
|
||||
this.currentTransform.Translation = origin;
|
||||
}
|
||||
|
@ -77,9 +77,9 @@ namespace Shaper2D
|
|||
/// Adds the line connecting the current point to the new point.
|
||||
/// </summary>
|
||||
/// <param name="point">The point.</param>
|
||||
public void AddLine(Point point)
|
||||
public void AddLine(Vector2 point)
|
||||
{
|
||||
var endPoint = point.Transform(this.currentTransform);
|
||||
var endPoint = Vector2.Transform(point, this.currentTransform);
|
||||
this.segments.Add(new LinearLineSegment(this.currentPoint, endPoint));
|
||||
this.currentPoint = endPoint;
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ namespace Shaper2D
|
|||
/// Adds a series of line segments connecting the current point to the new points.
|
||||
/// </summary>
|
||||
/// <param name="points">The points.</param>
|
||||
public void AddLines(IEnumerable<Point> points)
|
||||
public void AddLines(IEnumerable<Vector2> points)
|
||||
{
|
||||
foreach (var p in points)
|
||||
{
|
||||
|
@ -113,13 +113,13 @@ namespace Shaper2D
|
|||
/// <param name="controlPoint1">The control point1.</param>
|
||||
/// <param name="controlPoint2">The control point2.</param>
|
||||
/// <param name="endPoint">The end point.</param>
|
||||
public void AddBezier(Point controlPoint1, Point controlPoint2, Point endPoint)
|
||||
public void AddBezier(Vector2 controlPoint1, Vector2 controlPoint2, Vector2 endPoint)
|
||||
{
|
||||
endPoint = endPoint.Transform(this.currentTransform);
|
||||
endPoint = Vector2.Transform(endPoint, this.currentTransform);
|
||||
this.segments.Add(new BezierLineSegment(
|
||||
this.currentPoint,
|
||||
controlPoint1.Transform(this.currentTransform),
|
||||
controlPoint2.Transform(this.currentTransform),
|
||||
Vector2.Transform(controlPoint1, this.currentTransform),
|
||||
Vector2.Transform(controlPoint2, this.currentTransform),
|
||||
endPoint));
|
||||
this.currentPoint = endPoint;
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ namespace Shaper2D
|
|||
/// Moves the current point.
|
||||
/// </summary>
|
||||
/// <param name="point">The point.</param>
|
||||
public void MoveTo(Point point)
|
||||
public void MoveTo(Vector2 point)
|
||||
{
|
||||
if (this.segments.Any())
|
||||
{
|
||||
|
@ -136,7 +136,7 @@ namespace Shaper2D
|
|||
this.segments.Clear();
|
||||
}
|
||||
|
||||
this.currentPoint = point.Transform(this.currentTransform);
|
||||
this.currentPoint = Vector2.Transform(point, this.currentTransform);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -146,7 +146,7 @@ namespace Shaper2D
|
|||
/// <param name="y">The y.</param>
|
||||
public void MoveTo(float x, float y)
|
||||
{
|
||||
this.MoveTo(new Point(x, y));
|
||||
this.MoveTo(new Vector2(x, y));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
"type": "build"
|
||||
},
|
||||
"System.Collections.Immutable": "1.2.0",
|
||||
"System.Numerics.Vectors": "4.1.1",
|
||||
"System.Buffers": "4.0.0"
|
||||
},
|
||||
"frameworks": {
|
||||
|
@ -62,12 +61,26 @@
|
|||
"System.Resources.ResourceManager": "4.0.1",
|
||||
"System.Runtime.Extensions": "4.1.0",
|
||||
"System.Runtime.InteropServices": "4.1.0",
|
||||
"System.Numerics.Vectors": "4.1.1",
|
||||
"System.Runtime.Numerics": "4.0.1"
|
||||
}
|
||||
},
|
||||
"net45": {
|
||||
"dependencies": {
|
||||
"System.Runtime": "4.0.0"
|
||||
"System.Numerics.Vectors": "4.1.1"
|
||||
},
|
||||
"frameworkAssemblies": {
|
||||
"System.Runtime": { "type": "build" }
|
||||
}
|
||||
},
|
||||
"net461": {
|
||||
"dependencies": {
|
||||
"System.Threading.Tasks.Parallel": "4.0.0"
|
||||
},
|
||||
"frameworkAssemblies": {
|
||||
"System.Runtime": { "type": "build" },
|
||||
"System.Numerics": "4.0.0.0",
|
||||
"System.Numerics.Vectors": "4.0.0.0"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -6,23 +6,25 @@ using Xunit;
|
|||
|
||||
namespace Shaper2D.Tests
|
||||
{
|
||||
using System.Numerics;
|
||||
|
||||
public class BezierLineSegmentTests
|
||||
{
|
||||
[Fact]
|
||||
public void SingleSegmentConstructor()
|
||||
{
|
||||
var segment = new BezierLineSegment(new Point(0, 0), new Point(10, 0), new Point(10, 0), new Point(20, 0));
|
||||
var segment = new BezierLineSegment(new Vector2(0, 0), new Vector2(10, 0), new Vector2(10, 0), new Vector2(20, 0));
|
||||
var points = segment.Flatten();
|
||||
Assert.Equal(51, points.Length);
|
||||
Assert.Contains(new Point(0, 0), points);
|
||||
Assert.Contains(new Point(10, 0), points);
|
||||
Assert.Contains(new Point(20, 0), points);
|
||||
Assert.Contains(new Vector2(0, 0), points);
|
||||
Assert.Contains(new Vector2(10, 0), points);
|
||||
Assert.Contains(new Vector2(20, 0), points);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MustHaveAtleast4Points()
|
||||
{
|
||||
var error = Assert.Throws<ArgumentOutOfRangeException>(() => new BezierLineSegment(new[] { new Point(0, 0) }));
|
||||
var error = Assert.Throws<ArgumentOutOfRangeException>(() => new BezierLineSegment(new[] { new Vector2(0, 0) }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,21 +13,21 @@ namespace Shaper2D.Tests
|
|||
[Fact]
|
||||
public void MultipleLineSegmentsSimplePathsAreMerged()
|
||||
{
|
||||
var seg1 = new LinearLineSegment(new Point(0, 0), new Point(2, 2));
|
||||
var seg2 = new LinearLineSegment(new Point(4, 4), new Point(5, 5));
|
||||
var seg1 = new LinearLineSegment(new Vector2(0, 0), new Vector2(2, 2));
|
||||
var seg2 = new LinearLineSegment(new Vector2(4, 4), new Vector2(5, 5));
|
||||
|
||||
var path = new InternalPath(new ILineSegment[] { seg1, seg2 }, true);
|
||||
|
||||
Assert.Equal(new Point(0, 0), path.Points[0]);
|
||||
Assert.Equal(new Point(2, 2), path.Points[1]);
|
||||
Assert.Equal(new Point(4, 4), path.Points[2]);
|
||||
Assert.Equal(new Point(5, 5), path.Points[3]);
|
||||
Assert.Equal(new Vector2(0, 0), path.Points[0]);
|
||||
Assert.Equal(new Vector2(2, 2), path.Points[1]);
|
||||
Assert.Equal(new Vector2(4, 4), path.Points[2]);
|
||||
Assert.Equal(new Vector2(5, 5), path.Points[3]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Length_Closed()
|
||||
{
|
||||
var seg1 = new LinearLineSegment(new Point(0, 0), new Point(0, 2));
|
||||
var seg1 = new LinearLineSegment(new Vector2(0, 0), new Vector2(0, 2));
|
||||
|
||||
var path = new InternalPath(seg1, true);
|
||||
|
||||
|
@ -37,7 +37,7 @@ namespace Shaper2D.Tests
|
|||
[Fact]
|
||||
public void Length_Open()
|
||||
{
|
||||
var seg1 = new LinearLineSegment(new Point(0, 0), new Point(0, 2));
|
||||
var seg1 = new LinearLineSegment(new Vector2(0, 0), new Vector2(0, 2));
|
||||
|
||||
var path = new InternalPath(seg1, false);
|
||||
|
||||
|
@ -47,8 +47,8 @@ namespace Shaper2D.Tests
|
|||
[Fact]
|
||||
public void Bounds()
|
||||
{
|
||||
var seg1 = new LinearLineSegment(new Point(0, 0), new Point(2, 2));
|
||||
var seg2 = new LinearLineSegment(new Point(4, 4), new Point(5, 5));
|
||||
var seg1 = new LinearLineSegment(new Vector2(0, 0), new Vector2(2, 2));
|
||||
var seg2 = new LinearLineSegment(new Vector2(4, 4), new Vector2(5, 5));
|
||||
|
||||
var path = new InternalPath(new ILineSegment[] { seg1, seg2 }, true);
|
||||
|
||||
|
@ -58,10 +58,10 @@ namespace Shaper2D.Tests
|
|||
Assert.Equal(5, path.Bounds.Bottom);
|
||||
}
|
||||
|
||||
private static InternalPath Create(Point location, Size size, bool closed = true)
|
||||
private static InternalPath Create(Vector2 location, Size size, bool closed = true)
|
||||
{
|
||||
var seg1 = new LinearLineSegment(location, location + new Point(size.Width, 0));
|
||||
var seg2 = new LinearLineSegment(location + new Point(size.Width, size.Height), location + new Point(0, size.Height));
|
||||
var seg1 = new LinearLineSegment(location, location + new Vector2(size.Width, 0));
|
||||
var seg2 = new LinearLineSegment(location + new Vector2(size.Width, size.Height), location + new Vector2(0, size.Height));
|
||||
|
||||
return new InternalPath(new ILineSegment[] { seg1, seg2 }, closed);
|
||||
}
|
||||
|
@ -70,15 +70,15 @@ namespace Shaper2D.Tests
|
|||
new TheoryData<TestPoint, TestSize, TestPoint, bool>
|
||||
{
|
||||
{
|
||||
new Point(10,10), // loc
|
||||
new Vector2(10,10), // loc
|
||||
new Size(100,100), // size
|
||||
new Point(10,10), // test
|
||||
new Vector2(10,10), // test
|
||||
true
|
||||
}, //corner is inside
|
||||
{
|
||||
new Point(10,10), // loc
|
||||
new Vector2(10,10), // loc
|
||||
new Size(100,100), // size
|
||||
new Point(9,9), // test
|
||||
new Vector2(9,9), // test
|
||||
false
|
||||
}, //corner is inside
|
||||
};
|
||||
|
@ -86,32 +86,32 @@ namespace Shaper2D.Tests
|
|||
public static TheoryData<TestPoint, float, float> PathDistanceTheoryData =
|
||||
new TheoryData<TestPoint, float, float>
|
||||
{
|
||||
{ new Point(0, 0), 0f, 0f },
|
||||
{ new Point(1, 0), 0f, 1f },
|
||||
{ new Point(9, 0), 0f, 9f },
|
||||
{ new Point(10, 0), 0f, 10f },
|
||||
{ new Point(10, 1), 0f, 11f },
|
||||
{ new Point(10, 9), 0f, 19f },
|
||||
{ new Point(10, 10), 0f, 20f },
|
||||
{ new Point(9, 10), 0f, 21f },
|
||||
{ new Point(1, 10), 0f, 29f },
|
||||
{ new Point(0, 10), 0f, 30f },
|
||||
{ new Point(0, 9), 0f, 31f },
|
||||
{ new Point(0, 1), 0f, 39f },
|
||||
{ new Point(4, 3), 3f, 4f },
|
||||
{ new Point(3, 4), 3f, 36f },
|
||||
{ new Point(-1, 0), 1f, 0f },
|
||||
{ new Point(1, -1), 1f, 1f },
|
||||
{ new Point(9, -1), 1f, 9f },
|
||||
{ new Point(11, 0), 1f, 10f },
|
||||
{ new Point(11, 1), 1f, 11f },
|
||||
{ new Point(11, 9), 1f, 19f },
|
||||
{ new Point(11, 10), 1f, 20f },
|
||||
{ new Point(9, 11), 1f, 21f },
|
||||
{ new Point(1, 11), 1f, 29f },
|
||||
{ new Point(-1, 10), 1f, 30f },
|
||||
{ new Point(-1, 9), 1f, 31f },
|
||||
{ new Point(-1, 1), 1f, 39f },
|
||||
{ new Vector2(0, 0), 0f, 0f },
|
||||
{ new Vector2(1, 0), 0f, 1f },
|
||||
{ new Vector2(9, 0), 0f, 9f },
|
||||
{ new Vector2(10, 0), 0f, 10f },
|
||||
{ new Vector2(10, 1), 0f, 11f },
|
||||
{ new Vector2(10, 9), 0f, 19f },
|
||||
{ new Vector2(10, 10), 0f, 20f },
|
||||
{ new Vector2(9, 10), 0f, 21f },
|
||||
{ new Vector2(1, 10), 0f, 29f },
|
||||
{ new Vector2(0, 10), 0f, 30f },
|
||||
{ new Vector2(0, 9), 0f, 31f },
|
||||
{ new Vector2(0, 1), 0f, 39f },
|
||||
{ new Vector2(4, 3), 3f, 4f },
|
||||
{ new Vector2(3, 4), 3f, 36f },
|
||||
{ new Vector2(-1, 0), 1f, 0f },
|
||||
{ new Vector2(1, -1), 1f, 1f },
|
||||
{ new Vector2(9, -1), 1f, 9f },
|
||||
{ new Vector2(11, 0), 1f, 10f },
|
||||
{ new Vector2(11, 1), 1f, 11f },
|
||||
{ new Vector2(11, 9), 1f, 19f },
|
||||
{ new Vector2(11, 10), 1f, 20f },
|
||||
{ new Vector2(9, 11), 1f, 21f },
|
||||
{ new Vector2(1, 11), 1f, 29f },
|
||||
{ new Vector2(-1, 10), 1f, 30f },
|
||||
{ new Vector2(-1, 9), 1f, 31f },
|
||||
{ new Vector2(-1, 1), 1f, 39f },
|
||||
};
|
||||
|
||||
[Theory]
|
||||
|
@ -125,20 +125,20 @@ namespace Shaper2D.Tests
|
|||
[Fact]
|
||||
public void PointInPolygon_OpenPath()
|
||||
{
|
||||
var seg1 = new LinearLineSegment(new Point(0, 0), new Point(0, 10), new Point(10, 10), new Point(10, 0));
|
||||
var seg1 = new LinearLineSegment(new Vector2(0, 0), new Vector2(0, 10), new Vector2(10, 10), new Vector2(10, 0));
|
||||
|
||||
var p = new InternalPath(seg1, false);
|
||||
Assert.False(p.PointInPolygon(new Point(5, 5)));
|
||||
Assert.False(p.PointInPolygon(new Vector2(5, 5)));
|
||||
|
||||
var p2 = new InternalPath(seg1, true);
|
||||
Assert.True(p2.PointInPolygon(new Point(5, 5f)));
|
||||
Assert.True(p2.PointInPolygon(new Vector2(5, 5f)));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(PathDistanceTheoryData))]
|
||||
public void DistanceFromPath_Path(TestPoint point, float expectedDistance, float alongPath)
|
||||
{
|
||||
var shape = Create(new Point(0, 0), new Size(10, 10));
|
||||
var shape = Create(new Vector2(0, 0), new Size(10, 10));
|
||||
var info = shape.DistanceFromPath(point);
|
||||
Assert.Equal(expectedDistance, info.DistanceFromPath);
|
||||
Assert.Equal(alongPath, info.DistanceAlongPath);
|
||||
|
@ -147,8 +147,8 @@ namespace Shaper2D.Tests
|
|||
[Fact]
|
||||
public void DistanceFromPath_Path_Closed()
|
||||
{
|
||||
var shape = Create(new Point(0, 0), new Size(10, 10), false);
|
||||
var info = shape.DistanceFromPath(new Point(5, 5));
|
||||
var shape = Create(new Vector2(0, 0), new Size(10, 10), false);
|
||||
var info = shape.DistanceFromPath(new Vector2(5, 5));
|
||||
Assert.Equal(5, info.DistanceFromPath);
|
||||
Assert.Equal(5, info.DistanceAlongPath);
|
||||
}
|
||||
|
@ -156,73 +156,73 @@ namespace Shaper2D.Tests
|
|||
[Fact]
|
||||
public void Intersections_buffer()
|
||||
{
|
||||
var shape = Create(new Point(0, 0), new Size(10, 10));
|
||||
var buffer = new Point[shape.Points.Length];
|
||||
var hits = shape.FindIntersections(new Point(5, -10), new Vector2(5, 20), buffer, 4, 0);
|
||||
var shape = Create(new Vector2(0, 0), new Size(10, 10));
|
||||
var buffer = new Vector2[shape.Points.Length];
|
||||
var hits = shape.FindIntersections(new Vector2(5, -10), new Vector2(5, 20), buffer, 4, 0);
|
||||
|
||||
Assert.Equal(2, hits);
|
||||
Assert.Equal(new Point(5, 0), buffer[0]);
|
||||
Assert.Equal(new Point(5, 10), buffer[1]);
|
||||
Assert.Equal(new Vector2(5, 0), buffer[0]);
|
||||
Assert.Equal(new Vector2(5, 10), buffer[1]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Intersections_enumerabe()
|
||||
{
|
||||
var shape = Create(new Point(0, 0), new Size(10, 10));
|
||||
var buffer = shape.FindIntersections(new Point(5, -10), new Vector2(5, 20)).ToArray();
|
||||
var shape = Create(new Vector2(0, 0), new Size(10, 10));
|
||||
var buffer = shape.FindIntersections(new Vector2(5, -10), new Vector2(5, 20)).ToArray();
|
||||
|
||||
Assert.Equal(2, buffer.Length);
|
||||
Assert.Equal(new Point(5, 0), buffer[0]);
|
||||
Assert.Equal(new Point(5, 10), buffer[1]);
|
||||
Assert.Equal(new Vector2(5, 0), buffer[0]);
|
||||
Assert.Equal(new Vector2(5, 10), buffer[1]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Intersections_enumerabe_openpath()
|
||||
{
|
||||
var shape = Create(new Point(0, 0), new Size(10, 10), false);
|
||||
var buffer = shape.FindIntersections(new Point(5, -10), new Vector2(5, 20)).ToArray();
|
||||
var shape = Create(new Vector2(0, 0), new Size(10, 10), false);
|
||||
var buffer = shape.FindIntersections(new Vector2(5, -10), new Vector2(5, 20)).ToArray();
|
||||
|
||||
Assert.Equal(2, buffer.Length);
|
||||
Assert.Equal(new Point(5, 0), buffer[0]);
|
||||
Assert.Equal(new Point(5, 10), buffer[1]);
|
||||
Assert.Equal(new Vector2(5, 0), buffer[0]);
|
||||
Assert.Equal(new Vector2(5, 10), buffer[1]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Intersections_Diagonal()
|
||||
{
|
||||
var shape = new InternalPath(new LinearLineSegment(new Point(0, 0), new Point(10, 10)), false);
|
||||
var shape = new InternalPath(new LinearLineSegment(new Vector2(0, 0), new Vector2(10, 10)), false);
|
||||
|
||||
var buffer = shape.FindIntersections(new Point(0, 10), new Vector2(10, 0)).ToArray();
|
||||
var buffer = shape.FindIntersections(new Vector2(0, 10), new Vector2(10, 0)).ToArray();
|
||||
|
||||
Assert.Equal(1, buffer.Length);
|
||||
Assert.Equal(new Point(5, 5), buffer[0]);
|
||||
Assert.Equal(new Vector2(5, 5), buffer[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Intersections_Diagonal_NoHit()
|
||||
{
|
||||
var shape = new InternalPath(new LinearLineSegment(new Point(0, 0), new Point(4, 4)), false);
|
||||
var shape = new InternalPath(new LinearLineSegment(new Vector2(0, 0), new Vector2(4, 4)), false);
|
||||
|
||||
var buffer = shape.FindIntersections(new Point(0, 10), new Vector2(10, 0)).ToArray();
|
||||
var buffer = shape.FindIntersections(new Vector2(0, 10), new Vector2(10, 0)).ToArray();
|
||||
|
||||
Assert.Equal(0, buffer.Length);
|
||||
}
|
||||
[Fact]
|
||||
public void Intersections_Diagonal_and_straight_Hit()
|
||||
{
|
||||
var shape = new InternalPath(new LinearLineSegment(new Point(0, 0), new Point(4, 4)), false);
|
||||
var shape = new InternalPath(new LinearLineSegment(new Vector2(0, 0), new Vector2(4, 4)), false);
|
||||
|
||||
var buffer = shape.FindIntersections(new Point(3, 10), new Vector2(3, 0)).ToArray();
|
||||
var buffer = shape.FindIntersections(new Vector2(3, 10), new Vector2(3, 0)).ToArray();
|
||||
|
||||
Assert.Equal(1, buffer.Length);
|
||||
Assert.Equal(new Point(3, 3), buffer[0]);
|
||||
Assert.Equal(new Vector2(3, 3), buffer[0]);
|
||||
}
|
||||
[Fact]
|
||||
public void Intersections_Diagonal_and_straight_NoHit()
|
||||
{
|
||||
var shape = new InternalPath(new LinearLineSegment(new Point(0, 0), new Point(4, 4)), false);
|
||||
var shape = new InternalPath(new LinearLineSegment(new Vector2(0, 0), new Vector2(4, 4)), false);
|
||||
|
||||
var buffer = shape.FindIntersections(new Point(3, 10), new Vector2(3, 3.5f)).ToArray();
|
||||
var buffer = shape.FindIntersections(new Vector2(3, 10), new Vector2(3, 3.5f)).ToArray();
|
||||
|
||||
Assert.Equal(0, buffer.Length);
|
||||
}
|
||||
|
|
|
@ -6,22 +6,24 @@ using Xunit;
|
|||
|
||||
namespace Shaper2D.Tests
|
||||
{
|
||||
using System.Numerics;
|
||||
|
||||
public class LinearLineSegmentTests
|
||||
{
|
||||
[Fact]
|
||||
public void SingleSegmentConstructor()
|
||||
{
|
||||
var segment = new LinearLineSegment(new Point(0, 0), new Point(10, 10));
|
||||
var segment = new LinearLineSegment(new Vector2(0, 0), new Vector2(10, 10));
|
||||
var flatPath = segment.Flatten();
|
||||
Assert.Equal(2, flatPath.Length);
|
||||
Assert.Equal(new Point(0, 0), flatPath[0]);
|
||||
Assert.Equal(new Point(10, 10), flatPath[1]);
|
||||
Assert.Equal(new Vector2(0, 0), flatPath[0]);
|
||||
Assert.Equal(new Vector2(10, 10), flatPath[1]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MustHaveAtleast2Points()
|
||||
{
|
||||
var error = Assert.Throws<ArgumentOutOfRangeException>(()=> new LinearLineSegment(new [] { new Point(0, 0) }));
|
||||
var error = Assert.Throws<ArgumentOutOfRangeException>(() => new LinearLineSegment(new[] { new Vector2(0, 0) }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Shaper2D.Tests
|
|||
[Fact]
|
||||
public void Length()
|
||||
{
|
||||
var seg1 = new LinearLineSegment(new Point(0, 0), new Point(0, 2));
|
||||
var seg1 = new LinearLineSegment(new Vector2(0, 0), new Vector2(0, 2));
|
||||
|
||||
var path = new Path(seg1);
|
||||
|
||||
|
@ -23,8 +23,8 @@ namespace Shaper2D.Tests
|
|||
[Fact]
|
||||
public void Bounds()
|
||||
{
|
||||
var seg1 = new LinearLineSegment(new Point(0, 0), new Point(2, 2));
|
||||
var seg2 = new LinearLineSegment(new Point(4, 4), new Point(5, 5));
|
||||
var seg1 = new LinearLineSegment(new Vector2(0, 0), new Vector2(2, 2));
|
||||
var seg2 = new LinearLineSegment(new Vector2(4, 4), new Vector2(5, 5));
|
||||
|
||||
var path = new Path(seg1, seg2);
|
||||
|
||||
|
@ -37,35 +37,35 @@ namespace Shaper2D.Tests
|
|||
public static TheoryData<TestPoint, float, float> PathDistanceTheoryData =
|
||||
new TheoryData<TestPoint, float, float>
|
||||
{
|
||||
{ new Point(0, 0), 0f, 0f },
|
||||
{ new Point(1, 0), 0f, 1f },
|
||||
{ new Point(9, 0), 0f, 9f },
|
||||
{ new Point(10, 0), 0f, 10f },
|
||||
{ new Point(10, 1), 0f, 11f },
|
||||
{ new Point(10, 9), 0f, 19f },
|
||||
{ new Point(10, 10), 0f, 20f },
|
||||
{ new Point(9, 10), 0f, 21f },
|
||||
{ new Point(1, 10), 0f, 29f },
|
||||
{ new Point(0, 10), 0f, 30f },
|
||||
{ new Point(0, 1), 1f, 0f },
|
||||
{ new Point(4, 3), 3f, 4f },
|
||||
{ new Point(3, 4), 4f, 3f },
|
||||
{ new Point(-1, 0), 1f, 0f },
|
||||
{ new Point(1, -1), 1f, 1f },
|
||||
{ new Point(9, -1), 1f, 9f },
|
||||
{ new Point(11, 0), 1f, 10f },
|
||||
{ new Point(11, 1), 1f, 11f },
|
||||
{ new Point(11, 9), 1f, 19f },
|
||||
{ new Point(11, 10), 1f, 20f },
|
||||
{ new Point(9, 11), 1f, 21f },
|
||||
{ new Point(1, 11), 1f, 29f }
|
||||
{ new Vector2(0, 0), 0f, 0f },
|
||||
{ new Vector2(1, 0), 0f, 1f },
|
||||
{ new Vector2(9, 0), 0f, 9f },
|
||||
{ new Vector2(10, 0), 0f, 10f },
|
||||
{ new Vector2(10, 1), 0f, 11f },
|
||||
{ new Vector2(10, 9), 0f, 19f },
|
||||
{ new Vector2(10, 10), 0f, 20f },
|
||||
{ new Vector2(9, 10), 0f, 21f },
|
||||
{ new Vector2(1, 10), 0f, 29f },
|
||||
{ new Vector2(0, 10), 0f, 30f },
|
||||
{ new Vector2(0, 1), 1f, 0f },
|
||||
{ new Vector2(4, 3), 3f, 4f },
|
||||
{ new Vector2(3, 4), 4f, 3f },
|
||||
{ new Vector2(-1, 0), 1f, 0f },
|
||||
{ new Vector2(1, -1), 1f, 1f },
|
||||
{ new Vector2(9, -1), 1f, 9f },
|
||||
{ new Vector2(11, 0), 1f, 10f },
|
||||
{ new Vector2(11, 1), 1f, 11f },
|
||||
{ new Vector2(11, 9), 1f, 19f },
|
||||
{ new Vector2(11, 10), 1f, 20f },
|
||||
{ new Vector2(9, 11), 1f, 21f },
|
||||
{ new Vector2(1, 11), 1f, 29f }
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(PathDistanceTheoryData))]
|
||||
public void DistanceFromPath_Path(TestPoint point, float expectedDistance, float alongPath)
|
||||
{
|
||||
var path = new Path(new LinearLineSegment(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10)));
|
||||
var path = new Path(new LinearLineSegment(new Vector2(0, 0), new Vector2(10, 0), new Vector2(10, 10), new Vector2(0, 10)));
|
||||
var info = path.Distance(point);
|
||||
Assert.Equal(expectedDistance, info.DistanceFromPath);
|
||||
Assert.Equal(alongPath, info.DistanceAlongPath);
|
||||
|
@ -74,14 +74,14 @@ namespace Shaper2D.Tests
|
|||
[Fact]
|
||||
public void SimplePath()
|
||||
{
|
||||
var path = new Path(new LinearLineSegment(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10)));
|
||||
var path = new Path(new LinearLineSegment(new Vector2(0, 0), new Vector2(10, 0), new Vector2(10, 10), new Vector2(0, 10)));
|
||||
var points = path.Flatten();
|
||||
|
||||
Assert.Equal(4, points.Length);
|
||||
Assert.Equal(new Point(0, 0), points[0]);
|
||||
Assert.Equal(new Point(10, 0), points[1]);
|
||||
Assert.Equal(new Point(10, 10), points[2]);
|
||||
Assert.Equal(new Point(0, 10), points[3]);
|
||||
Assert.Equal(new Vector2(0, 0), points[0]);
|
||||
Assert.Equal(new Vector2(10, 0), points[1]);
|
||||
Assert.Equal(new Vector2(10, 10), points[2]);
|
||||
Assert.Equal(new Vector2(0, 10), points[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,123 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Shaper2D.Tests
|
||||
{
|
||||
public class PointTests
|
||||
{
|
||||
[Fact]
|
||||
public void EmptyIsDefault()
|
||||
{
|
||||
Assert.Equal(true, Point.Empty.IsEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Addition()
|
||||
{
|
||||
var actual = new Point(12, 13) + new Point(8, 7);
|
||||
Assert.Equal(new Point(20, 20), actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Subtraction()
|
||||
{
|
||||
var actual = new Point(12, 13) - new Point(2, 2);
|
||||
Assert.Equal(new Point(10, 11), actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EqualOperator_True()
|
||||
{
|
||||
var actual = new Point(12, 13) == new Point(12, 13);
|
||||
Assert.True(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EqualOperator_False()
|
||||
{
|
||||
var actual = new Point(12, 13) == new Point(1, 3);
|
||||
Assert.False(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equal_True()
|
||||
{
|
||||
var actual = new Point(12, 13).Equals((object)new Point(12, 13));
|
||||
Assert.True(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equal_Empty()
|
||||
{
|
||||
var actual = default(Point) == Point.Empty;
|
||||
Assert.True(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NotEqual_Empty()
|
||||
{
|
||||
var actual = default(Point) != Point.Empty;
|
||||
Assert.False(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equal_False_SameType()
|
||||
{
|
||||
var actual = new Point(12, 13).Equals((object)new Point(1, 3));
|
||||
Assert.False(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equal_False_DiffType()
|
||||
{
|
||||
var actual = new Point(12, 13).Equals((object)new object());
|
||||
Assert.False(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NotEqualOperator_False()
|
||||
{
|
||||
var actual = new Point(12, 13) != new Point(12, 13);
|
||||
Assert.False(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NotEqualOperator_True()
|
||||
{
|
||||
var actual = new Point(2, 1) != new Point(12, 13);
|
||||
Assert.True(actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Offset_Size()
|
||||
{
|
||||
var actual = new Point(12, 13).Offset(new Size(3, 2));
|
||||
Assert.Equal(new Point(15, 15), actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetHashCodeTest()
|
||||
{
|
||||
var inst1 = new Point(10, 10);
|
||||
var inst2 = new Point(10, 10);
|
||||
|
||||
Assert.Equal(inst1.GetHashCode(), inst2.GetHashCode());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToString_Empty()
|
||||
{
|
||||
Assert.Equal("Point [ Empty ]", Point.Empty.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToString_Val()
|
||||
{
|
||||
var p = new Point(2,3);
|
||||
Assert.Equal("Point [ X=2, Y=3 ]", p.ToString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ using Moq;
|
|||
namespace Shaper2D.Tests.PolygonClipper
|
||||
{
|
||||
using System.Collections.Immutable;
|
||||
using System.Numerics;
|
||||
|
||||
using Shaper2D.PolygonClipper;
|
||||
|
||||
|
@ -68,7 +69,7 @@ namespace Shaper2D.Tests.PolygonClipper
|
|||
var clipper = new Clipper();
|
||||
var mockPath = new Mock<IPath>();
|
||||
mockPath.Setup(x => x.Flatten())
|
||||
.Returns(ImmutableArray.Create(new Point(0, 0), new Point(1, 1), new Point(0, 0)));
|
||||
.Returns(ImmutableArray.Create(new Vector2(0, 0), new Vector2(1, 1), new Vector2(0, 0)));
|
||||
|
||||
Assert.Throws<ClipperException>(() => { clipper.AddPath(mockPath.Object, ClippingType.Subject); });
|
||||
}
|
||||
|
@ -79,7 +80,7 @@ namespace Shaper2D.Tests.PolygonClipper
|
|||
var clipper = new Clipper();
|
||||
var mockPath = new Mock<IPath>();
|
||||
mockPath.Setup(x => x.Flatten())
|
||||
.Returns(ImmutableArray.Create(new Point(0, 0), new Point(1, 1), new Point(1, 1)));
|
||||
.Returns(ImmutableArray.Create(new Vector2(0, 0), new Vector2(1, 1), new Vector2(1, 1)));
|
||||
|
||||
Assert.Throws<ClipperException>(() => { clipper.AddPath(mockPath.Object, ClippingType.Subject); });
|
||||
}
|
||||
|
|
|
@ -6,27 +6,29 @@ using Xunit;
|
|||
|
||||
namespace Shaper2D.Tests
|
||||
{
|
||||
using System.Numerics;
|
||||
|
||||
public class PolygonTests
|
||||
{
|
||||
public static TheoryData<TestPoint[], TestPoint, bool> PointInPolygonTheoryData =
|
||||
new TheoryData<TestPoint[], TestPoint, bool>
|
||||
{
|
||||
{
|
||||
new TestPoint[] {new Point(10, 10), new Point(10, 100), new Point(100, 100), new Point(100, 10)},
|
||||
new TestPoint[] {new Vector2(10, 10), new Vector2(10, 100), new Vector2(100, 100), new Vector2(100, 10)},
|
||||
// loc
|
||||
new Point(10, 10), // test
|
||||
new Vector2(10, 10), // test
|
||||
true
|
||||
}, //corner is inside
|
||||
{
|
||||
new TestPoint[] {new Point(10, 10), new Point(10, 100), new Point(100, 100), new Point(100, 10)},
|
||||
new TestPoint[] {new Vector2(10, 10), new Vector2(10, 100), new Vector2(100, 100), new Vector2(100, 10)},
|
||||
// loc
|
||||
new Point(10, 11), // test
|
||||
new Vector2(10, 11), // test
|
||||
true
|
||||
}, //on line
|
||||
{
|
||||
new TestPoint[] {new Point(10, 10), new Point(10, 100), new Point(100, 100), new Point(100, 10)},
|
||||
new TestPoint[] {new Vector2(10, 10), new Vector2(10, 100), new Vector2(100, 100), new Vector2(100, 10)},
|
||||
// loc
|
||||
new Point(9, 9), // test
|
||||
new Vector2(9, 9), // test
|
||||
false
|
||||
}, //corner is inside
|
||||
};
|
||||
|
@ -35,7 +37,7 @@ namespace Shaper2D.Tests
|
|||
[MemberData(nameof(PointInPolygonTheoryData))]
|
||||
public void PointInPolygon(TestPoint[] controlPoints, TestPoint point, bool isInside)
|
||||
{
|
||||
var shape = new Polygon(new LinearLineSegment(controlPoints.Select(x => (Point)x).ToArray()));
|
||||
var shape = new Polygon(new LinearLineSegment(controlPoints.Select(x => (Vector2)x).ToArray()));
|
||||
Assert.Equal(isInside, shape.Contains(point));
|
||||
}
|
||||
|
||||
|
@ -43,22 +45,22 @@ namespace Shaper2D.Tests
|
|||
new TheoryData<TestPoint[], TestPoint, float>
|
||||
{
|
||||
{
|
||||
new TestPoint[] {new Point(10, 10), new Point(10, 100), new Point(100, 100), new Point(100, 10)},
|
||||
new Point(10, 10),
|
||||
new TestPoint[] {new Vector2(10, 10), new Vector2(10, 100), new Vector2(100, 100), new Vector2(100, 10)},
|
||||
new Vector2(10, 10),
|
||||
0
|
||||
|
||||
},
|
||||
{
|
||||
new TestPoint[] { new Point(10, 10), new Point(10, 100), new Point(100, 100), new Point(100, 10) },
|
||||
new Point(10, 11), 0
|
||||
new TestPoint[] { new Vector2(10, 10), new Vector2(10, 100), new Vector2(100, 100), new Vector2(100, 10) },
|
||||
new Vector2(10, 11), 0
|
||||
},
|
||||
{
|
||||
new TestPoint[] { new Point(10, 10), new Point(10, 100), new Point(100, 100), new Point(100, 10) },
|
||||
new Point(11, 11), 0
|
||||
new TestPoint[] { new Vector2(10, 10), new Vector2(10, 100), new Vector2(100, 100), new Vector2(100, 10) },
|
||||
new Vector2(11, 11), 0
|
||||
},
|
||||
{
|
||||
new TestPoint[] { new Point(10, 10), new Point(10, 100), new Point(100, 100), new Point(100, 10) },
|
||||
new Point(9, 10), 1
|
||||
new TestPoint[] { new Vector2(10, 10), new Vector2(10, 100), new Vector2(100, 100), new Vector2(100, 10) },
|
||||
new Vector2(9, 10), 1
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -66,42 +68,42 @@ namespace Shaper2D.Tests
|
|||
[MemberData(nameof(DistanceTheoryData))]
|
||||
public void Distance(TestPoint[] controlPoints, TestPoint point, float expected)
|
||||
{
|
||||
var shape = new Polygon(new LinearLineSegment(controlPoints.Select(x => (Point)x).ToArray()));
|
||||
var shape = new Polygon(new LinearLineSegment(controlPoints.Select(x => (Vector2)x).ToArray()));
|
||||
Assert.Equal(expected, shape.Distance(point));
|
||||
}
|
||||
|
||||
public static TheoryData<TestPoint, float, float> PathDistanceTheoryData =
|
||||
new TheoryData<TestPoint, float, float>
|
||||
{
|
||||
{ new Point(0, 0), 0f, 0f },
|
||||
{ new Point(1, 0), 0f, 1f },
|
||||
{ new Point(9, 0), 0f, 9f },
|
||||
{ new Point(10, 0), 0f, 10f },
|
||||
{ new Point(10, 1), 0f, 11f },
|
||||
{ new Point(10, 9), 0f, 19f },
|
||||
{ new Point(10, 10), 0f, 20f },
|
||||
{ new Point(9, 10), 0f, 21f },
|
||||
{ new Point(1, 10), 0f, 29f },
|
||||
{ new Point(0, 10), 0f, 30f },
|
||||
{ new Point(0, 1), 0f, 39f },
|
||||
{ new Point(4, 3), 3f, 4f },
|
||||
{ new Point(3, 4), 3f, 36f },
|
||||
{ new Point(-1, 0), 1f, 0f },
|
||||
{ new Point(1, -1), 1f, 1f },
|
||||
{ new Point(9, -1), 1f, 9f },
|
||||
{ new Point(11, 0), 1f, 10f },
|
||||
{ new Point(11, 1), 1f, 11f },
|
||||
{ new Point(11, 9), 1f, 19f },
|
||||
{ new Point(11, 10), 1f, 20f },
|
||||
{ new Point(9, 11), 1f, 21f },
|
||||
{ new Point(1, 11), 1f, 29f }
|
||||
{ new Vector2(0, 0), 0f, 0f },
|
||||
{ new Vector2(1, 0), 0f, 1f },
|
||||
{ new Vector2(9, 0), 0f, 9f },
|
||||
{ new Vector2(10, 0), 0f, 10f },
|
||||
{ new Vector2(10, 1), 0f, 11f },
|
||||
{ new Vector2(10, 9), 0f, 19f },
|
||||
{ new Vector2(10, 10), 0f, 20f },
|
||||
{ new Vector2(9, 10), 0f, 21f },
|
||||
{ new Vector2(1, 10), 0f, 29f },
|
||||
{ new Vector2(0, 10), 0f, 30f },
|
||||
{ new Vector2(0, 1), 0f, 39f },
|
||||
{ new Vector2(4, 3), 3f, 4f },
|
||||
{ new Vector2(3, 4), 3f, 36f },
|
||||
{ new Vector2(-1, 0), 1f, 0f },
|
||||
{ new Vector2(1, -1), 1f, 1f },
|
||||
{ new Vector2(9, -1), 1f, 9f },
|
||||
{ new Vector2(11, 0), 1f, 10f },
|
||||
{ new Vector2(11, 1), 1f, 11f },
|
||||
{ new Vector2(11, 9), 1f, 19f },
|
||||
{ new Vector2(11, 10), 1f, 20f },
|
||||
{ new Vector2(9, 11), 1f, 21f },
|
||||
{ new Vector2(1, 11), 1f, 29f }
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(PathDistanceTheoryData))]
|
||||
public void DistanceFromPath_Path(TestPoint point, float expectedDistance, float alongPath)
|
||||
{
|
||||
IPath path = new Polygon(new LinearLineSegment(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10)));
|
||||
IPath path = new Polygon(new LinearLineSegment(new Vector2(0, 0), new Vector2(10, 0), new Vector2(10, 10), new Vector2(0, 10)));
|
||||
var info = path.Distance(point);
|
||||
Assert.Equal(expectedDistance, info.DistanceFromPath);
|
||||
Assert.Equal(alongPath, info.DistanceAlongPath);
|
||||
|
@ -110,41 +112,41 @@ namespace Shaper2D.Tests
|
|||
[Fact]
|
||||
public void AsSimpleLinearPath()
|
||||
{
|
||||
var poly = new Polygon(new LinearLineSegment(new Point(0, 0), new Point(0, 10), new Point(5, 5)));
|
||||
var poly = new Polygon(new LinearLineSegment(new Vector2(0, 0), new Vector2(0, 10), new Vector2(5, 5)));
|
||||
var paths = poly.Flatten();
|
||||
Assert.Equal(3, paths.Length);
|
||||
Assert.Equal(new Point(0, 0), paths[0]);
|
||||
Assert.Equal(new Point(0, 10), paths[1]);
|
||||
Assert.Equal(new Point(5, 5), paths[2]);
|
||||
Assert.Equal(new Vector2(0, 0), paths[0]);
|
||||
Assert.Equal(new Vector2(0, 10), paths[1]);
|
||||
Assert.Equal(new Vector2(5, 5), paths[2]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FindIntersectionsBuffer()
|
||||
{
|
||||
var poly = new Polygon(new LinearLineSegment(new Point(0, 0), new Point(0, 10), new Point(10, 10), new Point(10, 0)));
|
||||
var buffer = new Point[2];
|
||||
var poly = new Polygon(new LinearLineSegment(new Vector2(0, 0), new Vector2(0, 10), new Vector2(10, 10), new Vector2(10, 0)));
|
||||
var buffer = new Vector2[2];
|
||||
|
||||
var hits = poly.FindIntersections(new Point(5, -5), new Point(5, 15), buffer, 2, 0);
|
||||
var hits = poly.FindIntersections(new Vector2(5, -5), new Vector2(5, 15), buffer, 2, 0);
|
||||
Assert.Equal(2, hits);
|
||||
Assert.Contains(new Point(5, 10), buffer);
|
||||
Assert.Contains(new Point(5, 0), buffer);
|
||||
Assert.Contains(new Vector2(5, 10), buffer);
|
||||
Assert.Contains(new Vector2(5, 0), buffer);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FindIntersectionsCollection()
|
||||
{
|
||||
var poly = new Polygon(new LinearLineSegment(new Point(0, 0), new Point(0, 10), new Point(10, 10), new Point(10, 0)));
|
||||
var poly = new Polygon(new LinearLineSegment(new Vector2(0, 0), new Vector2(0, 10), new Vector2(10, 10), new Vector2(10, 0)));
|
||||
|
||||
var buffer = poly.FindIntersections(new Point(5, -5), new Point(5, 15)).ToArray();
|
||||
var buffer = poly.FindIntersections(new Vector2(5, -5), new Vector2(5, 15)).ToArray();
|
||||
Assert.Equal(2, buffer.Length);
|
||||
Assert.Contains(new Point(5, 10), buffer);
|
||||
Assert.Contains(new Point(5, 0), buffer);
|
||||
Assert.Contains(new Vector2(5, 10), buffer);
|
||||
Assert.Contains(new Vector2(5, 0), buffer);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReturnsSelfASOwnPath_SingleSegment()
|
||||
{
|
||||
var poly = new Polygon(new LinearLineSegment(new Point(0, 0), new Point(0, 10), new Point(5, 5)));
|
||||
var poly = new Polygon(new LinearLineSegment(new Vector2(0, 0), new Vector2(0, 10), new Vector2(5, 5)));
|
||||
var paths = poly.Paths;
|
||||
Assert.Equal(1, paths.Length);
|
||||
Assert.Equal(poly, paths[0]);
|
||||
|
@ -153,7 +155,7 @@ namespace Shaper2D.Tests
|
|||
[Fact]
|
||||
public void ReturnsSelfASOwnPath_MultiSegment()
|
||||
{
|
||||
var poly = new Polygon(new LinearLineSegment(new Point(0, 0), new Point(0, 10)), new LinearLineSegment(new Point(2, 5), new Point(5, 5)));
|
||||
var poly = new Polygon(new LinearLineSegment(new Vector2(0, 0), new Vector2(0, 10)), new LinearLineSegment(new Vector2(2, 5), new Vector2(5, 5)));
|
||||
var paths = poly.Paths;
|
||||
Assert.Equal(1, paths.Length);
|
||||
Assert.Equal(poly, paths[0]);
|
||||
|
@ -162,7 +164,7 @@ namespace Shaper2D.Tests
|
|||
[Fact]
|
||||
public void Bounds()
|
||||
{
|
||||
var poly = new Polygon(new LinearLineSegment(new Point(0, 0), new Point(0, 10), new Point(5, 5)));
|
||||
var poly = new Polygon(new LinearLineSegment(new Vector2(0, 0), new Vector2(0, 10), new Vector2(5, 5)));
|
||||
var bounds = poly.Bounds;
|
||||
Assert.Equal(0, bounds.Left);
|
||||
Assert.Equal(0, bounds.Top);
|
||||
|
@ -173,14 +175,14 @@ namespace Shaper2D.Tests
|
|||
[Fact]
|
||||
public void Length()
|
||||
{
|
||||
var poly = new Polygon(new LinearLineSegment(new Point(0, 0), new Point(0, 10)));
|
||||
var poly = new Polygon(new LinearLineSegment(new Vector2(0, 0), new Vector2(0, 10)));
|
||||
Assert.Equal(20, poly.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MaxIntersections()
|
||||
{
|
||||
var poly = new Polygon(new LinearLineSegment(new Point(0, 0), new Point(0, 10)));
|
||||
var poly = new Polygon(new LinearLineSegment(new Vector2(0, 0), new Vector2(0, 10)));
|
||||
|
||||
// with linear polygons its the number of points the segments have
|
||||
Assert.Equal(2, poly.MaxIntersections);
|
||||
|
|
|
@ -13,15 +13,15 @@ namespace Shaper2D.Tests
|
|||
new TheoryData<TestPoint, TestSize, TestPoint, bool>
|
||||
{
|
||||
{
|
||||
new Point(10,10), // loc
|
||||
new Vector2(10,10), // loc
|
||||
new Size(100,100), // size
|
||||
new Point(10,10), // test
|
||||
new Vector2(10,10), // test
|
||||
true
|
||||
}, //corner is inside
|
||||
{
|
||||
new Point(10,10), // loc
|
||||
new Vector2(10,10), // loc
|
||||
new Size(100,100), // size
|
||||
new Point(9,9), // test
|
||||
new Vector2(9,9), // test
|
||||
false
|
||||
}, //corner is inside
|
||||
};
|
||||
|
@ -29,39 +29,39 @@ namespace Shaper2D.Tests
|
|||
new TheoryData<TestPoint, TestSize, TestPoint, float>
|
||||
{
|
||||
{
|
||||
new Point(10,10), // loc
|
||||
new Vector2(10,10), // loc
|
||||
new Size(100,100), // size
|
||||
new Point(10,10), // test
|
||||
new Vector2(10,10), // test
|
||||
0f
|
||||
}, //corner is inside
|
||||
{
|
||||
new Point(10,10), // loc
|
||||
new Vector2(10,10), // loc
|
||||
new Size(100,100), // size
|
||||
new Point(9,10), // test
|
||||
new Vector2(9,10), // test
|
||||
1f
|
||||
},
|
||||
{
|
||||
new Point(10,10), // loc
|
||||
new Vector2(10,10), // loc
|
||||
new Size(100,100), // size
|
||||
new Point(10,13), // test
|
||||
new Vector2(10,13), // test
|
||||
0f
|
||||
},
|
||||
{
|
||||
new Point(10,10), // loc
|
||||
new Vector2(10,10), // loc
|
||||
new Size(100,100), // size
|
||||
new Point(14,13), // test
|
||||
new Vector2(14,13), // test
|
||||
-3f
|
||||
},
|
||||
{
|
||||
new Point(10,10), // loc
|
||||
new Vector2(10,10), // loc
|
||||
new Size(100,100), // size
|
||||
new Point(13,14), // test
|
||||
new Vector2(13,14), // test
|
||||
-3f
|
||||
},
|
||||
{
|
||||
new Point(10,10), // loc
|
||||
new Vector2(10,10), // loc
|
||||
new Size(100,100), // size
|
||||
new Point(7,6), // test
|
||||
new Vector2(7,6), // test
|
||||
5f
|
||||
},
|
||||
};
|
||||
|
@ -69,34 +69,34 @@ namespace Shaper2D.Tests
|
|||
public static TheoryData<TestPoint, float, float> PathDistanceTheoryData =
|
||||
new TheoryData<TestPoint, float, float>
|
||||
{
|
||||
{ new Point(0,0), 0f, 0f },
|
||||
{ new Point(1,0), 0f, 1f },
|
||||
{ new Point(9,0), 0f, 9f },
|
||||
{ new Point(10,0), 0f, 10f },
|
||||
{ new Point(10, 1), 0f, 11f },
|
||||
{ new Point(10,9), 0f, 19f },
|
||||
{ new Point(10,10), 0f, 20f },
|
||||
{ new Point(9,10), 0f, 21f },
|
||||
{ new Point(1,10), 0f, 29f },
|
||||
{ new Point(0,10), 0f, 30f },
|
||||
{ new Point(0,9), 0f, 31f },
|
||||
{ new Point(0,1), 0f, 39f },
|
||||
{ new Vector2(0,0), 0f, 0f },
|
||||
{ new Vector2(1,0), 0f, 1f },
|
||||
{ new Vector2(9,0), 0f, 9f },
|
||||
{ new Vector2(10,0), 0f, 10f },
|
||||
{ new Vector2(10, 1), 0f, 11f },
|
||||
{ new Vector2(10,9), 0f, 19f },
|
||||
{ new Vector2(10,10), 0f, 20f },
|
||||
{ new Vector2(9,10), 0f, 21f },
|
||||
{ new Vector2(1,10), 0f, 29f },
|
||||
{ new Vector2(0,10), 0f, 30f },
|
||||
{ new Vector2(0,9), 0f, 31f },
|
||||
{ new Vector2(0,1), 0f, 39f },
|
||||
|
||||
{ new Point(4,3), 3f, 4f },
|
||||
{ new Point(3, 4), 3f, 36f },
|
||||
{ new Vector2(4,3), 3f, 4f },
|
||||
{ new Vector2(3, 4), 3f, 36f },
|
||||
|
||||
{ new Point(-1,0), 1f, 0f },
|
||||
{ new Point(1,-1), 1f, 1f },
|
||||
{ new Point(9,-1), 1f, 9f },
|
||||
{ new Point(11,0), 1f, 10f },
|
||||
{ new Point(11, 1), 1f, 11f },
|
||||
{ new Point(11,9), 1f, 19f },
|
||||
{ new Point(11,10), 1f, 20f },
|
||||
{ new Point(9,11), 1f, 21f },
|
||||
{ new Point(1,11), 1f, 29f },
|
||||
{ new Point(-1,10), 1f, 30f },
|
||||
{ new Point(-1,9), 1f, 31f },
|
||||
{ new Point(-1,1), 1f, 39f },
|
||||
{ new Vector2(-1,0), 1f, 0f },
|
||||
{ new Vector2(1,-1), 1f, 1f },
|
||||
{ new Vector2(9,-1), 1f, 9f },
|
||||
{ new Vector2(11,0), 1f, 10f },
|
||||
{ new Vector2(11, 1), 1f, 11f },
|
||||
{ new Vector2(11,9), 1f, 19f },
|
||||
{ new Vector2(11,10), 1f, 20f },
|
||||
{ new Vector2(9,11), 1f, 21f },
|
||||
{ new Vector2(1,11), 1f, 29f },
|
||||
{ new Vector2(-1,10), 1f, 30f },
|
||||
{ new Vector2(-1,9), 1f, 31f },
|
||||
{ new Vector2(-1,1), 1f, 39f },
|
||||
};
|
||||
|
||||
[Theory]
|
||||
|
@ -177,38 +177,38 @@ namespace Shaper2D.Tests
|
|||
{
|
||||
IPath shape = new Rectangle(10, 11, 12, 13);
|
||||
var segemnts = shape.Flatten();
|
||||
Assert.Equal(new Point(10, 11), segemnts[0]);
|
||||
Assert.Equal(new Point(22, 11), segemnts[1]);
|
||||
Assert.Equal(new Point(22, 24), segemnts[2]);
|
||||
Assert.Equal(new Point(10, 24), segemnts[3]);
|
||||
Assert.Equal(new Vector2(10, 11), segemnts[0]);
|
||||
Assert.Equal(new Vector2(22, 11), segemnts[1]);
|
||||
Assert.Equal(new Vector2(22, 24), segemnts[2]);
|
||||
Assert.Equal(new Vector2(10, 24), segemnts[3]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Intersections_2()
|
||||
{
|
||||
IShape shape = new Rectangle(1, 1, 10, 10);
|
||||
var intersections = shape.FindIntersections(new Point(0, 5), new Point(20, 5));
|
||||
var intersections = shape.FindIntersections(new Vector2(0, 5), new Vector2(20, 5));
|
||||
|
||||
Assert.Equal(2, intersections.Count());
|
||||
Assert.Equal(new Point(1, 5), intersections.First());
|
||||
Assert.Equal(new Point(11, 5), intersections.Last());
|
||||
Assert.Equal(new Vector2(1, 5), intersections.First());
|
||||
Assert.Equal(new Vector2(11, 5), intersections.Last());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Intersections_1()
|
||||
{
|
||||
IShape shape = new Rectangle(1, 1, 10, 10);
|
||||
var intersections = shape.FindIntersections(new Point(0, 5), new Point(5, 5));
|
||||
var intersections = shape.FindIntersections(new Vector2(0, 5), new Vector2(5, 5));
|
||||
|
||||
Assert.Equal(1, intersections.Count());
|
||||
Assert.Equal(new Point(1, 5), intersections.First());
|
||||
Assert.Equal(new Vector2(1, 5), intersections.First());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Intersections_0()
|
||||
{
|
||||
IShape shape = new Rectangle(1, 1, 10, 10);
|
||||
var intersections = shape.FindIntersections(new Point(0, 5), new Point(-5, 5));
|
||||
var intersections = shape.FindIntersections(new Vector2(0, 5), new Vector2(-5, 5));
|
||||
|
||||
Assert.Equal(0, intersections.Count());
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ namespace Shaper2D.Tests
|
|||
|
||||
var newShape = (Rectangle)shape.Transform(new Matrix3x2(0, 1, 1, 0, 20, 2));
|
||||
|
||||
Assert.Equal(new Point(20, 2), newShape.Location);
|
||||
Assert.Equal(new Vector2(20, 2), newShape.Location);
|
||||
Assert.Equal(new Size(60, 200), newShape.Size);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,11 +42,7 @@ namespace Shaper2D.Tests
|
|||
{
|
||||
return new Vector2(p.X, p.Y);
|
||||
}
|
||||
public static implicit operator Point(TestPoint p)
|
||||
{
|
||||
return new Point(p.X, p.Y);
|
||||
}
|
||||
public static implicit operator TestPoint(Point p)
|
||||
public static implicit operator TestPoint(Vector2 p)
|
||||
{
|
||||
return new TestPoint(p.X, p.Y);
|
||||
}
|
||||
|
|
|
@ -14,12 +14,12 @@
|
|||
},
|
||||
"xunit": "2.2.0-*",
|
||||
"dotnet-test-xunit": "2.2.0-*",
|
||||
"System.Linq": "4.3.0",
|
||||
"Moq": "4.6.38-alpha"
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.1": {
|
||||
"dependencies": {
|
||||
"System.Linq": "4.3.0",
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.0-*"
|
||||
|
@ -29,6 +29,7 @@
|
|||
},
|
||||
"net451": {
|
||||
"dependencies": {
|
||||
"System.Linq": "4.0.0"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче