1 module rip.draw.additional;
2 
3 private
4 {
5 	import std.algorithm;
6 	import std.math;
7 	
8 	import rip.concepts.color;
9 	import rip.concepts.mathematics;
10 	import rip.concepts.surface;
11 	import rip.concepts.templates;
12 	
13 	import rip.draw.primitives;
14 }
15 
16 // Рисование точки в полярных координатах (угол в радианах !)
17 auto drawPolarPoint(T, S)(Surface surface, RGBColor rgbColor, T r, S phi)
18 	if (allArithmetic!(T, S))
19 {
20 	auto R = cast(float) r;
21 	auto P = cast(float) phi;
22 	
23 	auto X = R * cos(P);
24 	auto Y = R * sin(P);
25 	
26 	surface.drawPoint(color, X, Y);
27 }
28 
29 auto drawPolarPoint(T, S, U, V)(Surface surface, RGBColor rgbColor, T r, S phi, U x, V y)
30 	if (allArithmetic!(T, S, U, V))
31 {
32 	auto R = cast(float) r;
33 	auto P = cast(float) phi;
34 	
35 	auto X = R * cos(P);
36 	auto Y = R * sin(P);
37 	
38 	surface.drawPoint(color, X + cast(float) x, Y + cast(float) y);
39 }
40 
41 // Рисование линии в полярных координатах (угол в радианах !)
42 auto drawRadiusOf(T, S, U, V)(Surface surface, RGBColor rgbColor, T r, S phi, U x, V y)
43 	if (allArithmetic!(T, S, U, V))
44 {
45 	auto R = cast(float) r;
46 	auto P = cast(float) phi;
47 	
48 	auto X = R * cos(P);
49 	auto Y = R * sin(P);
50 	
51 	surface.drawDDALine(color, X, Y, X + cast(float) x, Y + cast(float) y);
52 }
53 
54 auto drawRadiusOf(T, S, U)(Surface surface, RGBColor rgbColor, T r, S phi, U x)
55 	if (allArithmetic!(T, S, U, V))
56 {
57 	auto R = cast(float) r;
58 	auto P = cast(float) phi;
59 	auto radius = cast(float) x;
60 	
61 	auto X = R * cos(P);
62 	auto Y = R * sin(P);
63 	
64 	surface.drawDDALine(color, X, Y, X + radius, Y + radius);
65 }
66 
67 auto drawPolarLine(T, S, U, V)(Surface surface, RGBColor rgbColor, T r1, S phi1, U r2, V phi2)
68 	if (allArithmetic!(T, S, U, V))
69 {
70 	auto R1 = cast(float) r1;
71 	auto P1 = cast(float) phi2;
72 	auto R2 = cast(float) r1;
73 	auto P2 = cast(float) phi2;
74 	
75 	auto X1 = R1 * cos(P1);
76 	auto Y1 = R1 * sin(P1);
77 	auto X2 = R2 * cos(P2);
78 	auto Y2 = R2 * sin(P2);
79 	
80 	surface.drawDDALine(color, X1, Y1, X2, Y2);
81 }
82 
83 auto drawPolarLine(T, S, U, V, W, Y)(Surface surface, RGBColor rgbColor, T r1, S phi1, U r2, V phi2, W x, Y y)
84 	if (allArithmetic!(T, S, U, V, W, Y))
85 {
86 	auto R1 = cast(float) r1;
87 	auto P1 = cast(float) phi2;
88 	auto R2 = cast(float) r1;
89 	auto P2 = cast(float) phi2;
90 	
91 	auto X1 = R1 * cos(P1);
92 	auto Y1 = R1 * sin(P1);
93 	auto X2 = R2 * cos(P2);
94 	auto Y2 = R2 * sin(P2);
95 	
96 	surface.drawDDALine(color, X1 + cast(float) x, Y2 + cast(float) y, X2 + cast(float) x, Y2 + cast(float) y);
97 }
98 
99 // Полярная роза
100 auto drawPolarRose(T, U, V, W, Y)(Surface surface, RGBColor rgbColor, U x, V y, V m, W n, Y length)
101 	if (allArithmetic!(T, U, V, W, Y))
102 {
103 	auto M = cast(float) m;
104 	auto N = cast(float) n;
105 	auto L = cast(float) L;
106 	
107 	for (float i = 0.0; i < 360.0; i += 0.01)
108 	{
109 		auto R = M * sin(N * degreesInRadians(i));
110 		surface.drawPolarPoint(color, L * i, L * R, x, y);
111 	}
112 }
113 
114 // Закрашенная полярная роза
115 auto drawFilledPolarRose(T, U, V, W, Y)(Surface surface, RGBColor rgbColor, U x, V y, V m, W n, Y length)
116 	if (allArithmetic!(T, U, V, W, Y))
117 {
118 	auto M = cast(float) m;
119 	auto N = cast(float) n;
120 	auto L = cast(float) L;
121 	
122 	for (float i = 0.0; i < 360.0; i += 0.01)
123 	{
124 		auto R = M * sin(N * degreesInRadians(i));
125 		surface.drawRadiusOf(color, L * i, L * R, x, y);
126 	}
127 }
128 
129 // Лево-закрученная спираль Архимеда
130 auto drawLeftSpiralOfArchimedes(T, U, V, W)(Surface surface, RGBColor rgbColor, U x, V y, V m, W n)
131 	if (allArithmetic!(T, U, V, W))
132 {
133 	auto M = cast(float) m;
134 	auto N = cast(float) n;
135 	auto L = cast(float) L;
136 	
137 	for (float i = -360.0 * N; i < 0.0; i += 0.01)
138 	{
139 		auto R = M + N * i;
140 		surface.drawPolarPoint(color, i, R, x, y);
141 	}
142 }
143 
144 // Право-закрученная спираль Архимеда
145 auto drawLeftSpiralOfArchimedes(T, U, V, W)(Surface surface, RGBColor rgbColor, U x, V y, V m, W n)
146 	if (allArithmetic!(T, U, V, W))
147 {
148 	auto M = cast(float) m;
149 	auto N = cast(float) n;
150 	auto L = cast(float) L;
151 	
152 	for (float i = 0.0; i < 360.0 * N; i += 0.01)
153 	{
154 		auto R = M + N * i;
155 		surface.drawPolarPoint(color, i, R, x, y);
156 	}
157 }