Skip to content

Commit f5dfa51

Browse files
committed
Contour Engine v3
WIP still, but promising.
1 parent 9b374be commit f5dfa51

File tree

3 files changed

+1011
-0
lines changed

3 files changed

+1011
-0
lines changed

Common/clipper/Clipper.Helper.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
namespace Clipper2Lib;
24

35
public static class Helper
@@ -45,4 +47,25 @@ public static PathsD initedPathsD(int count)
4547

4648
return ret;
4749
}
50+
51+
public static bool PointsEqual(PointD a, PointD b)
52+
{
53+
return Math.Abs(a.x - b.x) < 1e-9 && Math.Abs(a.y - b.y) < 1e-9;
54+
}
55+
56+
public static PointD Add(PointD a, PointD b) => new PointD(a.x + b.x, a.y + b.y);
57+
public static PointD Minus(PointD a, PointD b) => new PointD(a.x - b.x, a.y - b.y);
58+
public static PointD Mult(PointD a, double s) => new PointD(a.x * s, a.y * s);
59+
public static double Length(PointD p) => Math.Sqrt(p.x * p.x + p.y * p.y);
60+
public static PointD Mul(PointD a, double s) => new PointD(a.x * s, a.y * s);
61+
62+
public static PointD Neg(PointD a) => new PointD(-a.x, -a.y);
63+
public static double Dot(PointD a, PointD b) => a.x * b.x + a.y * b.y;
64+
public static PointD Mid(PointD a, PointD b) => new PointD((a.x + b.x) / 2.0, (a.y + b.y) / 2.0);
65+
66+
public static PointD Normalized(PointD p)
67+
{
68+
double len = Length(p);
69+
return len > 0 ? new PointD(p.x / len, p.y / len) : new PointD(0, 0);
70+
}
4871
}

0 commit comments

Comments
 (0)