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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
use math::*;

use std::rc::Rc;
use std::sync::Arc;
use std::cell::RefCell;

use crate::core::geometry::*;
use crate::core::resource::*;
use util::uuid::OsRandNewV4;

#[derive(Debug)]
pub struct CircleGeometry
{
	uuid: uuid::Uuid,
	radius:f32,
	segments:u32,
	theta_start:f32,
	theta_length:f32,
	vertices:float3s,
	normals:float3s,
	texcoords:float2s,
	indices:Vec<u16>,
}

impl CircleGeometry 
{
	pub fn new(radius:f32, segments:u32, theta_start:f32, theta_length:f32) -> Self 
	{
		let mut _vertices = Vec::new();
		let mut _indices = Vec::new();
		let mut _normals = Vec::new();
		let mut _texcoords = Vec::new();

		for i in 0..segments
		{
			let segment = theta_start + i as f32 / segments as f32 * theta_length;

			let v = float3
			{
				x:radius * f32::cos(segment),
				y:radius * f32::sin(segment),
				z:0.0,
			};

			_vertices.push(v);
			_texcoords.push(float!(v.x / radius + 1.0, (v.y / radius + 1.0) * 0.5));
		}

		let normal = float!(0.0,0.0,1.0);

		for i in 1..segments
		{
			let v1 = i;
			let v2 = i + 1;
			let v3 = 0;

			_indices.push(v1 as u16);
			_indices.push(v2 as u16);
			_indices.push(v3 as u16);

			_normals.push(normal);
			_normals.push(normal);
			_normals.push(normal);
		}

		Self
		{
			uuid:uuid::Uuid::new_v4_osrng(),
			radius:radius,
			segments:segments,
			theta_start:theta_start,
			theta_length:theta_length,
			vertices:_vertices,
			normals:_normals,
			texcoords:_texcoords,
			indices:_indices,
		}
	}

	pub fn new_1(radius:f32, segments:u32) -> Self
	{
		CircleGeometry::new(radius, segments, 0., f32::pi())
	}

	pub fn radius(&self) -> f32
	{
		self.radius
	}

	pub fn segments(&self) -> u32
	{
		self.segments
	}

	pub fn theta_start(&self) -> f32
	{
		self.theta_start
	}

	pub fn theta_length(&self) -> f32
	{
		self.theta_length
	}
}

impl Geometry for CircleGeometry
{
	fn vertices(&self) -> &[float3]
	{
		&self.vertices[..]
	}

	fn normals(&self) -> &[float3]
	{
		&self.normals[..]
	}

	fn texcoords(&self) -> &[float2]
	{
		&self.texcoords[..]
	}

	fn indices(&self) -> &[u16]
	{
		&self.indices[..]
	}
}

impl Resource for CircleGeometry
{
	#[inline]
	fn uuid(&self) -> &uuid::Uuid
	{
		&self.uuid
	}
}

impl From<CircleGeometry> for Rc<Geometry + 'static>
{
	fn from(shape:CircleGeometry) -> Self
	{
		Rc::new(shape)
	}
}

impl From<CircleGeometry> for Arc<Geometry + 'static>
{
	fn from(shape:CircleGeometry) -> Self
	{
		Arc::new(shape)
	}
}

impl From<CircleGeometry> for Rc<RefCell<Geometry + 'static>>
{
	fn from(shape:CircleGeometry) -> Self
	{
		Rc::new(RefCell::new(shape))
	}
}

impl From<CircleGeometry> for Arc<RefCell<Geometry + 'static>>
{
	fn from(shape:CircleGeometry) -> Self
	{
		Arc::new(RefCell::new(shape))
	}
}