private string CalculateMidPoint(string sourceBlockName, string destinationBlockName) { string @default = "[0, 0]"; Block srcBlock = this.model.System.Block.FirstOrDefault(b => b.BlockName == sourceBlockName); if (srcBlock != null) { Block destBlock = this.model.System.Block.FirstOrDefault(b => b.BlockName == destinationBlockName); if (destBlock != null) { int distance = BlockExtensions.GetHorizontalDistance(srcBlock, destBlock) / 2; @default = $"[{distance}, 0]"; } } return(@default); }
internal Parameter CalculateBranchPoint(string sourceBlockName, string destinationBlockName, Action <IPathDirection> action = null) { Parameter @default = new Parameter() { Name = "Points", Text = "[0, 0]" }; action?.Invoke(this); if (Path.Type != LinePath.DirectionType.Straight) { Block srcBlock = this.model.System.Block.FirstOrDefault(b => b.BlockName == sourceBlockName); if (srcBlock != null) { Block destBlock = this.model.System.Block.FirstOrDefault(b => b.BlockName == destinationBlockName); if (destBlock != null) { int horizontalDiff = BlockExtensions.GetHorizontalDistance(srcBlock, destBlock); int verticalDiff = BlockExtensions.GetVerticalDistance(srcBlock, destBlock); switch (Path.Type) { case LinePath.DirectionType.Up: { @default = new Parameter() { Name = "Points", Text = $"[0, {-1 * (verticalDiff + Path.AppendedDistance)}]" }; } break; case LinePath.DirectionType.Down: { @default = new Parameter() { Name = "Points", Text = $"[0, {verticalDiff + Path.AppendedDistance}]" }; } break; case LinePath.DirectionType.Left: { @default = new Parameter() { Name = "Points", Text = $"[{-1 * (horizontalDiff + Path.AppendedDistance)}, 0]" }; } break; case LinePath.DirectionType.Right: { @default = new Parameter() { Name = "Points", Text = $"[{horizontalDiff + Path.AppendedDistance}, 0]" }; } break; } } } } return(@default); }