/
EugenyCh7
/
Puppet2D.Net
Обзор
Документация
Войти
/
EugenyCh7
/
Puppet2D.Net
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Puppet2D.Graphics/RoundedRectangleShape.cs
149 строк
4 KB
EugenyCh7
++ Shapes
21 июл 2025, 22:44
21 июл 2025, 22:44
eab4816
Код
Авторство
О чём код?
using Puppet2D.System; using System; namespace Puppet2D.Graphics { public class RoundedRectangleShape : Shape { private const uint defaultCornerPoints = 6; private const float pi_2 = 3.141592654f / 2; private uint cornerPoints; private float cornerRadius; private float width; private float height; public RoundedRectangleShape( float cornerRadius = 0.0f, uint cornerPoints = defaultCornerPoints) : this(0, 0, cornerRadius, cornerPoints) { } public RoundedRectangleShape( Vector2 size, float cornerRadius = 0.0f, uint cornerPoints = defaultCornerPoints) : this(size.X, size.Y, cornerRadius, cornerPoints) { } public RoundedRectangleShape( float width, float height, float cornerRadius = 0.0f, uint cornerPoints = defaultCornerPoints) : base() { this.width = width; this.height = height; this.cornerRadius = cornerRadius; this.cornerPoints = cornerPoints; Update(); } public RoundedRectangleShape(RoundedRectangleShape copy) : base(copy) { width = copy.width; height = copy.height; cornerRadius = copy.cornerRadius; cornerPoints = copy.cornerPoints; Update(); } /// <summary> /// The number of vertices to smooth each corner. /// </summary> public uint CornerPoints { get { return cornerPoints; } set { cornerPoints = value; Update(); } } /// <summary> /// The radius of the rounded corners. /// </summary> public float CornerRadius { get { return cornerRadius; } set { cornerRadius = value; Update(); } } /// <summary> /// The width of the rounded rectangle. /// </summary> public float Width { get { return width; } set { width = value; Update(); } } /// <summary> /// The height of the rounded rectangle. /// </summary> public float Height { get { return height; } set { height = value; Update(); } } /// <summary> /// The size of the rounded rectangle. /// </summary> public Vector2 Size { get => new Vector2(width, height); set { width = value.X; height = value.Y; Update(); } } public override Vector2 GetPoint(uint index) { float da = pi_2 / (cornerPoints - 1); uint cornerIndex = index / cornerPoints; Vector2 center = new Vector2( cornerIndex == 1 || cornerIndex == 2 ? cornerRadius : width - cornerRadius, cornerIndex == 0 || cornerIndex == 1 ? cornerRadius : height - cornerRadius); return new Vector2( (cornerRadius * MathF.Cos(da * (index - cornerIndex)) + center.X), (-cornerRadius * MathF.Sin(da * (index - cornerIndex)) + center.Y)); } public override uint GetPointCount() { return cornerPoints * 4; } } }