зеркало из https://github.com/SixLabors/Shapes.git
make vector comparison looser for duplicate matching
This commit is contained in:
Родитель
85a44eb124
Коммит
94c2a84d0f
|
@ -0,0 +1,35 @@
|
|||
// <copyright file="ArrayExtensions.cs" company="Scott Williams">
|
||||
// Copyright (c) Scott Williams and contributors.
|
||||
// Licensed under the Apache License, Version 2.0.
|
||||
// </copyright>
|
||||
|
||||
namespace SixLabors.Shapes
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
/// Extensions on arrays.
|
||||
/// </summary>
|
||||
internal static class VectorExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Merges the specified source2.
|
||||
/// </summary>
|
||||
/// <param name="source1">The source1.</param>
|
||||
/// <param name="source2">The source2.</param>
|
||||
/// <param name="threshold">The threshold.</param>
|
||||
/// <returns>
|
||||
/// the Merged arrays
|
||||
/// </returns>
|
||||
public static bool Equivelent(this Vector2 source1, Vector2 source2, float threshold)
|
||||
{
|
||||
var abs = Vector2.Abs(source1 - source2);
|
||||
|
||||
return abs.X < threshold && abs.Y < threshold;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -225,7 +225,7 @@ namespace SixLabors.Shapes
|
|||
Vector2 point = FindIntersection(this.points[i], this.points[next], start, end);
|
||||
if (point != MaxVector)
|
||||
{
|
||||
if (lastPoint == point)
|
||||
if (lastPoint.Equivelent(point, Epsilon))
|
||||
{
|
||||
// hit the same point a second time do we need to remove the old one if just clipping
|
||||
var side = SideOfLine(this.points[last], start, end);
|
||||
|
|
|
@ -283,5 +283,26 @@ namespace SixLabors.Shapes.Tests
|
|||
Assert.Equal(0, intersections.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MissingIntersection()
|
||||
{
|
||||
var simplePath = new Polygon(new LinearLineSegment(
|
||||
new Vector2(10, 10),
|
||||
new Vector2(200, 150),
|
||||
new Vector2(50, 300)));
|
||||
|
||||
var hole1 = new Polygon(new LinearLineSegment(
|
||||
new Vector2(37, 85),
|
||||
new Vector2(130, 40),
|
||||
new Vector2(65, 137)));
|
||||
|
||||
var poly = simplePath.Clip(hole1);
|
||||
|
||||
var intersections = poly.FindIntersections(new Vector2(float.MinValue, 85), new Vector2(float.MaxValue, 85));
|
||||
|
||||
// returns an even number of points
|
||||
Assert.Equal(4, intersections.Count());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче