private static bool FlatWithAccuracy(IRenderVertex v1, IRenderVertex v2, IRenderVertex vMid, float accuracy) { switch (v1) { case RenderVertex3D v31 when v2 is RenderVertex3D v32 && vMid is RenderVertex3D vMid3: return(FlatWithAccuracy3(v31, v32, vMid3, accuracy)); case RenderVertex2D v21 when v2 is RenderVertex2D v22 && vMid is RenderVertex2D vMid2: return(FlatWithAccuracy2(v21, v22, vMid2, accuracy)); default: throw new InvalidOperationException("Vertices must be either 2- or 3-dimensional."); } }
private static bool LinesIntersect(IRenderVertex start1, IRenderVertex start2, IRenderVertex end1, IRenderVertex end2) { var x1 = start1.X; var y1 = start1.Y; var x2 = start2.X; var y2 = start2.Y; var x3 = end1.X; var y3 = end1.Y; var x4 = end2.X; var y4 = end2.Y; var d123 = (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1); if (d123 == 0.0) // p3 lies on the same line as p1 and p2 { return(x3 >= MathF.Min(x1, x2) && x3 <= MathF.Max(x2, x1)); } var d124 = (x2 - x1) * (y4 - y1) - (x4 - x1) * (y2 - y1); if (d124 == 0.0) // p4 lies on the same line as p1 and p2 { return(x4 >= MathF.Min(x1, x2) && x4 <= MathF.Max(x2, x1)); } if (d123 * d124 >= 0.0) { return(false); } var d341 = (x3 - x1) * (y4 - y1) - (x4 - x1) * (y3 - y1); if (d341 == 0.0) // p1 lies on the same line as p3 and p4 { return(x1 >= MathF.Min(x3, x4) && x1 <= MathF.Max(x3, x4)); } var d342 = d123 - d124 + d341; if (d342 == 0.0) // p1 lies on the same line as p3 and p4 { return(x2 >= MathF.Min(x3, x4) && x2 <= MathF.Max(x3, x4)); } return(d341 * d342 < 0.0); }
private static float GetDot(IRenderVertex pvEnd1, IRenderVertex pvJoint, IRenderVertex pvEnd2) { return((pvJoint.X - pvEnd1.X) * (pvJoint.Y - pvEnd2.Y) - (pvJoint.Y - pvEnd1.Y) * (pvJoint.X - pvEnd2.X)); }
private static float GetDot(IRenderVertex pvEnd1, IRenderVertex pvJoint, IRenderVertex pvEnd2) { return((pvJoint.GetX() - pvEnd1.GetX()) * (pvJoint.GetY() - pvEnd2.GetY()) - (pvJoint.GetY() - pvEnd1.GetY()) * (pvJoint.GetX() - pvEnd2.GetX())); }