Advertisement
Guest User

Untitled

a guest
Sep 28th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. /** A rect with all nodes that the bounds could touch.
  2. * This correctly handles rotated graphs and other transformations.
  3. * The returned rect is guaranteed to not extend outside the graph bounds.
  4. */
  5. protected IntRect GetRectFromBounds (Bounds bounds) {
  6. // Take the bounds and transform it using the matrix
  7. // Then convert that to a rectangle which contains
  8. // all nodes that might be inside the bounds
  9.  
  10. bounds = transform.InverseTransform(bounds);
  11. Vector3 min = bounds.min;
  12. Vector3 max = bounds.max;
  13.  
  14. int minX = Mathf.RoundToInt(min.x-0.5F);
  15. int maxX = Mathf.RoundToInt(max.x-0.5F);
  16.  
  17. int minZ = Mathf.RoundToInt(min.z-0.5F);
  18. int maxZ = Mathf.RoundToInt(max.z-0.5F);
  19.  
  20. var originalRect = new IntRect(minX, minZ, maxX, maxZ);
  21.  
  22. // Rect which covers the whole grid
  23. var gridRect = new IntRect(0, 0, width-1, depth-1);
  24.  
  25. // Clamp the rect to the grid
  26. return IntRect.Intersection(originalRect, gridRect);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement