public void AutoOrient() { Vector2 searchPosLeft = new Vector2(rect.X, rect.Y - rect.Height / 2); Hull hullLeft = Hull.FindHullUnoptimized(searchPosLeft, null, false); Vector2 searchPosRight = new Vector2(rect.Right, rect.Y - rect.Height / 2); Hull hullRight = Hull.FindHullUnoptimized(searchPosRight, null, false); if (hullLeft != null && hullRight != null && hullLeft != hullRight) { IsHorizontal = true; return; } Vector2 searchPosTop = new Vector2(rect.Center.X, rect.Y); Hull hullTop = Hull.FindHullUnoptimized(searchPosTop, null, false); Vector2 searchPosBottom = new Vector2(rect.Center.X, rect.Y - rect.Height); Hull hullBottom = Hull.FindHullUnoptimized(searchPosBottom, null, false); if (hullTop != null && hullBottom != null && hullTop != hullBottom) { IsHorizontal = false; return; } if ((hullLeft == null) != (hullRight == null)) { IsHorizontal = true; } else if ((hullTop == null) != (hullBottom == null)) { IsHorizontal = false; } }
public void FindHull() { CurrentHull = Hull.FindHull(WorldPosition, CurrentHull); #if CLIENT //we may not be able to find the hull with the optimized method in the sub editor if new hulls have been added, use the unoptimized method if (Screen.Selected == GameMain.SubEditorScreen) { CurrentHull ??= Hull.FindHullUnoptimized(WorldPosition); } #endif }
private void FindHulls() { Hull[] hulls = new Hull[2]; foreach (var linked in linkedTo) { if (linked is Hull hull) { hull.ConnectedGaps.Remove(this); } } linkedTo.Clear(); Vector2[] searchPos = new Vector2[2]; if (IsHorizontal) { searchPos[0] = new Vector2(rect.X, rect.Y - rect.Height / 2); searchPos[1] = new Vector2(rect.Right, rect.Y - rect.Height / 2); } else { searchPos[0] = new Vector2(rect.Center.X, rect.Y); searchPos[1] = new Vector2(rect.Center.X, rect.Y - rect.Height); } for (int i = 0; i < 2; i++) { hulls[i] = Hull.FindHullUnoptimized(searchPos[i], null, false); if (hulls[i] == null) { hulls[i] = Hull.FindHullUnoptimized(searchPos[i], null, false, true); } } if (hulls[0] == null && hulls[1] == null) { return; } if (hulls[0] == null && hulls[1] != null) { Hull temp = hulls[0]; hulls[0] = hulls[1]; hulls[1] = temp; } flowTargetHull = hulls[0]; for (int i = 0; i < 2; i++) { if (hulls[i] == null) { continue; } linkedTo.Add(hulls[i]); if (!hulls[i].ConnectedGaps.Contains(this)) { hulls[i].ConnectedGaps.Add(this); } } }