/
EugenyCh7
/
Puppet2D.Net
Обзор
Документация
Войти
/
EugenyCh7
/
Puppet2D.Net
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Puppet2D.Engine/Geometry/Polygon.cs
74 строки
2 KB
Eugeny Chekmarev
exceptions fix
25 авг 2025, 12:46
25 авг 2025, 12:46
35e565f
Код
Авторство
О чём код?
using Puppet2D.System; using System; using System.IO; namespace Puppet2D.Engine.Geometry { /// <summary> /// A solid convex polygon. /// </summary> public struct Polygon { public float Angle; public float OuterRadius; public Vector2[] Points; internal Polygon(B2.ShapeProxy shapeProxy) { OuterRadius = shapeProxy.radius; Points = new Vector2[shapeProxy.count]; for (int i = 0; i < shapeProxy.count; i++) { Points[i] = shapeProxy.points[i]; } } internal Polygon(B2.Polygon polygon) { OuterRadius = polygon.radius; Points = new Vector2[polygon.count]; for (int i = 0; i < polygon.count; i++) { Points[i] = polygon.vertices[i]; } } internal B2.ShapeProxy CastToShapeProxy() { if (Points == null) throw new NullReferenceException($"The {nameof(Points)} is null."); if (Points.Length > 8 || Points.Length < 3) throw new InvalidDataException($"The number of {nameof(Points)} should be from 3 to 8."); B2.ShapeProxy shapeProxy = new B2.ShapeProxy { count = Points.Length, radius = OuterRadius }; for (int i = 0; i < Points.Length; i++) { shapeProxy.points[i] = Points[i].Rotate(Angle); } return shapeProxy; } internal B2.Polygon CastToPolygon() { unsafe { if (Points == null) throw new NullReferenceException($"The {nameof(Points)} is null."); if (Points.Length > 8 || Points.Length < 3) throw new InvalidDataException($"The number of {nameof(Points)} should be from 3 to 8."); B2.Hull hull = new B2.Hull() { count = Points.Length }; for (int i = 0; i < Points.Length; i++) { hull.points[i] = Points[i].Rotate(Angle); } return B2.MakePolygon(&hull, OuterRadius); } } } }