public static void SetPerpednicular(Edge siblingEdge, Edge currentEdge, Edge nextEdge) { Vertice start = currentEdge.Start; Vertice middle = currentEdge.End; Vertice end = nextEdge.End; double d = DistanceHelpers.GetEdgeLength(siblingEdge); (double, double)line = Line.GetStraightLine(siblingEdge.Start, siblingEdge.End); (Vertice, Vertice)vertices; if (line.Item1 == 0) { vertices = (new Vertice(start.x, start.y - (int)d), new Vertice(start.x, start.y + (int)d)); } else if (line.Item1 > int.MaxValue - 100 || line.Item1 < int.MinValue + 100) { vertices = (new Vertice(start.x - (int)d, start.y), new Vertice(start.x + (int)d, start.y)); } else { (double, double)perpendicularLine = Line.GetPerpendicularThroughPoint(line, start); vertices = PointHelpers.GetPointFromLineDistanceAndPoint(perpendicularLine, d, start); } Vertice resultVertice = DistanceHelpers.GetCloserVerticeFromVertice(vertices, middle); PointHelpers.SetPointXY(middle, resultVertice.x, resultVertice.y); }
public static void SetAsTriangleLength(double d, Edge currentEdge, Edge nextEdge) { Vertice start = currentEdge.Start; Vertice middle = currentEdge.End; Vertice end = nextEdge.End; double d2 = DistanceHelpers.GetEdgeLength(nextEdge); double distance = DistanceHelpers.DistanceBetween(start, end); double triangleArea = Triangle.TriangleArea(d, d2, distance); Vertice missingPoint = Triangle.GetPointFromTriangleArea(triangleArea, start, end, d, d2); if (missingPoint.x < int.MinValue + 100 || missingPoint.y > int.MaxValue - 100 || missingPoint.y < int.MinValue + 100 || missingPoint.y > int.MaxValue - 100) { int xdddd = 2; } PointHelpers.SetPointXY(middle, missingPoint.x, missingPoint.y); }
public bool IsEqualRelation(Edge e1, Edge e2) { //Because of unencountered exceptions sometimes xD if ((int)DistanceHelpers.GetEdgeLength(e1) - (int)DistanceHelpers.GetEdgeLength(e2) == int.MinValue) { return(false); } int dist = Math.Abs((int)DistanceHelpers.GetEdgeLength(e1) - (int)DistanceHelpers.GetEdgeLength(e2)); if (dist < CONST.differenceToMakeEdgesEqual) { return(true); } else { return(false); } }
public static void SetPerpednicularNextEqual(Edge siblingEdge, Edge currentEdge, Edge nextEdge) { Vertice start = currentEdge.Start; Vertice middle = currentEdge.End; Vertice end = nextEdge.End; double d = DistanceHelpers.GetEdgeLength(siblingEdge); double d2 = DistanceHelpers.GetEdgeLength(nextEdge); (double, double)line = Line.GetStraightLine(siblingEdge.Start, siblingEdge.End); (double, double)distanceLine = Line.GetStraightLine(start, end); (Vertice, Vertice)vertices = (null, null); if (line.Item1 != 0 && line.Item1 < int.MaxValue - 100 && line.Item1 > int.MinValue + 100) { (double, double)perpendicularLine = Line.GetPerpendicularThroughPoint(line, start); if (d2 < Line.DistanceVerticeFromLine(perpendicularLine, end)) { d2 = Line.DistanceVerticeFromLine(perpendicularLine, end) + 1; } double cos = Angle.GetCosinusFromBetween(perpendicularLine, distanceLine); double sqrtDelta = Math.Sqrt(Math.Pow(2 * d * cos, 2) - 4 * (d * d - d2 * d2)); double x1 = (2 * d * cos - sqrtDelta) / 2; double x2 = (2 * d * cos + sqrtDelta) / 2; double x = Math.Min(x1, x2); if (x < 0) { x = Math.Max(x1, x2); } vertices = PointHelpers.GetPointFromLineDistanceAndPoint(perpendicularLine, x, start); Vertice resultVertice = DistanceHelpers.GetCloserVerticeFromVertice(vertices, end); PointHelpers.SetPointXY(middle, resultVertice.x, resultVertice.y); } else { SetPerpednicularNextPerpendicular(siblingEdge, currentEdge, nextEdge); } }