/
EugenyCh7
/
Puppet2D.Net
Обзор
Документация
Войти
/
EugenyCh7
/
Puppet2D.Net
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Puppet2D.Graphics/RegularPolygonShape.cs
120 строк
3 KB
EugenyCh7
++ Shapes
21 июл 2025, 22:44
21 июл 2025, 22:44
eab4816
Код
Авторство
О чём код?
using Puppet2D.System; namespace Puppet2D.Graphics { public class RegularPolygonShape : Shape { private const uint defaultCornerPoints = 8; private const float pi = 3.141592654f; private const float twoPi = 3.141592654f * 2; protected const float radiansInDegrees = pi / 180f; private uint cornerNumber; private float radius; private float cornerRadius; private uint cornerPoints; private float angle; public RegularPolygonShape(uint cornerNumber, float radius, float cornerRadius = 0.0f, float angle = 0.0f, uint cornerPoints = defaultCornerPoints) : base() { this.cornerNumber = cornerNumber; this.radius = radius; this.cornerRadius = cornerRadius; this.angle = angle; this.cornerPoints = cornerPoints; Update(); } public RegularPolygonShape(RegularPolygonShape copy) : base(copy) { cornerNumber = copy.cornerNumber; radius = copy.radius; cornerRadius = copy.cornerRadius; angle = copy.angle; cornerPoints = copy.cornerPoints; Update(); } /// <summary> /// The slope of the figure in degrees. /// </summary> public float Angle { get => angle; set { angle = value; Update(); } } /// <summary> /// The number of vertices of a regular polygon. /// </summary> public uint CornerNumber { get => cornerNumber; set { cornerNumber = value; Update(); } } /// <summary> /// The radius of a regular polygon. /// </summary> public float Radius { get => radius; set { radius = value; Update(); } } /// <summary> /// The radius of smoothing the corners. /// </summary> public float CornerRadius { get => cornerRadius; set { cornerRadius = value; Update(); } } /// <summary> /// The number of vertices to smooth each corner. /// </summary> public uint CornerPoints { get => cornerPoints; set { cornerPoints = value; Update(); } } public override Vector2 GetPoint(uint index) { float pa = twoPi / cornerNumber; float da = twoPi / (cornerNumber * (cornerPoints - 1)); uint cornerIndex = index / cornerPoints; Vector2 p = new Vector2(radius - cornerRadius, 0); Vector2 v = new Vector2(cornerRadius, 0).Rotate(-pi / cornerNumber); Vector2 r = p.Rotate(pa * cornerIndex) + v.Rotate(da * (index - cornerIndex)); return r.Rotate(angle * radiansInDegrees); } public override uint GetPointCount() { return cornerNumber * cornerPoints; } } }