-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerminalCircle.cs
41 lines (35 loc) · 1.07 KB
/
TerminalCircle.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Drawing;
using System.Numerics;
namespace TerminalRenderer;
public class TerminalCircle : ITerminalRenderable
{
public Point Origin = default;
public int Radius = 0;
public TerminalPixel PixelType = default;
public TerminalCircle(Point origin, int radius, TerminalPixel pixels)
{
Origin = origin;
Radius = radius;
PixelType = pixels;
}
public bool Contains(Point point)
{
return Vector2.Distance(new Vector2(Origin.X, Origin.Y), new Vector2(point.X, point.Y)) <= Radius;
}
public IEnumerable<TerminalPixel> Render()
{
int lMost = Origin.X - Radius;
int rMost = Origin.X + Radius;
int tMost = Origin.Y - Radius;
int bMost = Origin.Y + Radius;
for (int y = tMost; y < bMost - tMost; y++)
{
for (int x = lMost; x < rMost - lMost; x++)
{
var p = new Point(lMost + x, tMost + y);
if (Contains(p))
yield return PixelType with { Position = p };
}
}
}
}