public bool Contains(f2 p) { var d0 = b - GetClosestPoint(p); var d1 = b - a; return((dot(d0, d1) >= 0f) && (lengthsq(d0) <= lengthsq(d1))); }
public bool Includes(f2 p, bool close) { CrossForEachEdge(p, out float c1, out float c2, out float c3); bool f1 = (c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0); bool f2 = c1 * c2 * c3 == 0; return(close ? f1 || f2 : f1); }
bool Contains(f2 p) { foreach (var s in segments) { if (cross(new f3(s.b - s.a, 0), new f3(p - s.a, 0)).z < 0) { return(false); } } return(true); }
void Split(f2 p) { var n = nodes.Find(_t => _t.triangle.Includes(p, true)); var o = DN.Split(n, p); nodes.Remove(n); nodes.Add(o.n1); nodes.Add(o.n2); nodes.Add(o.n3); stack.Push(o.s1); stack.Push(o.s2); stack.Push(o.s3); }
public Circle GetCircumscribledCircle() { float xa2 = a.x * a.x, ya2 = a.y * a.y; float xb2 = b.x * b.x, yb2 = b.y * b.y; float xc2 = c.x * c.x, yc2 = c.y * c.y; float k = 2 * ((b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)); var ctr = new f2( ((c.y - a.y) * (xb2 - xa2 + yb2 - ya2) + (a.y - b.y) * (xc2 - xa2 + yc2 - ya2)) / k, ((a.x - c.x) * (xb2 - xa2 + yb2 - ya2) + (b.x - a.x) * (xc2 - xa2 + yc2 - ya2)) / k ); return(new Circle(ctr, distance(a, ctr))); }
public f2 GetClosestPoint(f2 p) { float a1 = b.y - a.y, b1 = a.x - b.x, c1 = a1 * a.x + b1 * a.y, c2 = -b1 * p.x + a1 * p.y, dt = a1 * a1 - -b1 * b1; if (Mathf.Approximately(dt, 0f)) { return(p); } return(float2(a1 * c1 - b1 * c2, a1 * c2 - -b1 * c1) / dt); }
public Triangle(f2 a, f2 b, f2 c) // counterclockwise { if (Equals(a, b) || Equals(b, c) || Equals(c, a)) { throw new Exception(); } bool f = cross(float3(b - a, 0), float3(c - b, 0)).z > 0; this.a = a; this.b = f ? b : c; this.c = f ? c : b; this.sgms = new SG[] { new SG(this.a, this.b), new SG(this.b, this.c), new SG(this.c, this.a) }; }
public void SBO_MenuEvent(ref SAPbouiCOM.MenuEvent pVal, out bool BubbleEvent) { BubbleEvent = true; if (pVal.BeforeAction == false) { return; } else if (pVal.BeforeAction) { switch (pVal.MenuUID) { case "M_testSDK": f2 f1 = new f2(); break; } } }
public void EquatableTest() { var ps = Enumerable.Repeat(0, 10).Select(_ => new f2(UR.value, UR.value)).ToArray(); var a = new f2(0, 0); var b = new f2(1, 0); var c = new f2(0, 1); var d = new f2(1, 1); var e = new f2(2, 0); var f = new f2(0, 2); var g = new f2(2, 2); Debug.Log("f2: " + Marshal.SizeOf(a)); Debug.Log("sg: " + Marshal.SizeOf(new SG(a, b))); Debug.Log("tr: " + Marshal.SizeOf(new TR(a, b, c))); // primitive Assert.IsFalse(a.Equals(b)); Assert.IsFalse(a.Equals(c)); Assert.IsTrue(a.Equals(a)); // circle var c1 = new Circle(d, 1); var c2 = new Circle(d, 1); var c3 = new Circle(d, 2); Assert.IsTrue(c1 == c2); Assert.IsTrue(c1 != c3); // segment var s1 = new SG(a, b); var s2 = new SG(b, a); var s3 = new SG(c, a); Assert.IsTrue(s1 == s2); Assert.IsTrue(s1 != s3); // triangle var t1 = new TR(a, b, c); var t2 = new TR(a, c, b); var t3 = new TR(b, c, a); Assert.IsTrue(t1 == t2); Assert.IsTrue(t1 == t3); }
AddElementNonTransitive(f2, f1);
public Circle(f2 c, float r) { center = c; radius = r; }
public bool Contains(f2 p) => lengthsq(p - center) < radius * radius;
float DistFactor(SG s, f2 p) => cross(new f3(s.b - s.a, 0), new f3(p - s.a, 0)).z;
//public float GetDistance(f2 p) => distance(GetClosestPoint(p), p); public float GetDistance(f2 p) => abs(cross(new f3(p - a, 0), new f3(normalize(b - a), 0)).z);
public VoronoiGraphNode2D(f2 c) { this.center = c; this.segments = new List <SG>(); }
public Triangle(SG e, f2 c) : this(e.a, e.b, c) { }
public bool OnEdge(f2 p) { CrossForEachEdge(p, out float c1, out float c2, out float c3); return(c1 * c2 * c3 == 0); }
public bool Contains(f2 p, float offset = 0f) { return (min.x + offset <= p.x && p.x <= max.x - offset && min.y + offset <= p.y && p.y <= max.y - offset); }
public AABB(f2 _min, f2 _max) { this.min = new f2(min(_min.x, _max.x), min(_min.y, _max.y)); this.max = new f2(max(_min.x, _max.x), max(_min.y, _max.y)); this.center = (this.min + this.max) * 0.5f; }
public Segment(f2 a, f2 b) { this.a = a; this.b = b; this.line = new Line(a, b - a); }
void CrossForEachEdge(f2 p, out float ca, out float cb, out float cc) { ca = cross(new f3(b - a, 0), new f3(p - b, 0)).z; cb = cross(new f3(c - b, 0), new f3(p - c, 0)).z; cc = cross(new f3(a - c, 0), new f3(p - a, 0)).z; }