A game framework written with osu! in mind.
at master 36 lines 1.3 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using osuTK; 5 6namespace osu.Framework.Graphics.Shapes 7{ 8 /// <summary> 9 /// A triangle which has all side lengths and angles equal. 10 /// </summary> 11 public class EquilateralTriangle : Triangle 12 { 13 /// <summary> 14 /// For equilateral triangles, height = cos(30) * sidelength = ~0.866 * sidelength. 15 /// This is applied to the side length of the triangle to determine the height. 16 /// </summary> 17 private const float sidelength_to_height_factor = 0.866f; 18 19 /// <summary> 20 /// The size of this triangle. 21 /// <para> 22 /// When setting the size, the Y-value is ignored (use <see cref="Height"/> if you desire a specific height instead). 23 /// </para> 24 /// </summary> 25 public override Vector2 Size => new Vector2(base.Size.X, base.Size.X * sidelength_to_height_factor); 26 27 /// <summary> 28 /// Sets the height of the triangle, adjusting the width as appropriate. 29 /// </summary> 30 public override float Height 31 { 32 get => Width * sidelength_to_height_factor; 33 set => Size = new Vector2(value / sidelength_to_height_factor); 34 } 35 } 36}