/
GeekNerd
/
ServerModelingProject
Обзор
Документация
Войти
/
GeekNerd
/
ServerModelingProject
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Assets/Scripts/OptimizationLogic/Core/OrientedRect.cs
74 строки
2 KB
Gorney-Alex
Init
30 май 2026, 19:05
30 май 2026, 19:05
3cdcc49
Код
Авторство
О чём код?
using UnityEngine; namespace OptimizationLogic.Core { /// <summary> /// 2D oriented rectangle (center, size in meters, rotation in degrees around +Z). /// Size.x is width along local X, Size.y is height along local Y. /// </summary> public readonly struct OrientedRect { public readonly Vector2 Center; public readonly Vector2 Size; public readonly float RotationDeg; public OrientedRect(Vector2 center, Vector2 size, float rotationDeg) { Center = center; Size = size; RotationDeg = rotationDeg; } public Vector2 Extents => Size * 0.5f; public Vector2 Right { get { float rad = RotationDeg * Mathf.Deg2Rad; return new Vector2(Mathf.Cos(rad), Mathf.Sin(rad)); } } public Vector2 Up { get { float rad = RotationDeg * Mathf.Deg2Rad; return new Vector2(-Mathf.Sin(rad), Mathf.Cos(rad)); } } public Vector2[] GetCorners() { Vector2 ex = Right * Extents.x; Vector2 ey = Up * Extents.y; return new[] { Center - ex - ey, Center + ex - ey, Center + ex + ey, Center - ex + ey, }; } public Rect GetAabb() { Vector2[] corners = GetCorners(); float minX = corners[0].x, maxX = corners[0].x; float minY = corners[0].y, maxY = corners[0].y; for (int i = 1; i < corners.Length; i++) { Vector2 c = corners[i]; if (c.x < minX) minX = c.x; if (c.x > maxX) maxX = c.x; if (c.y < minY) minY = c.y; if (c.y > maxY) maxY = c.y; } return Rect.MinMaxRect(minX, minY, maxX, maxY); } } }