-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathtrigonometry.dm
70 lines (57 loc) · 2.06 KB
/
trigonometry.dm
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
#define COMP_TRIGONOMETRY_SINE "Sine"
#define COMP_TRIGONOMETRY_COSINE "Cosine"
#define COMP_TRIGONOMETRY_TANGENT "Tangent"
#define COMP_TRIGONOMETRY_ARCSINE "Arcsine"
#define COMP_TRIGONOMETRY_ARCCOSINE "Arccosine"
#define COMP_TRIGONOMETRY_ARCTANGENT "Arctangent"
/**
* # Trigonometric Component
*
* General trigonometric unit with sine, cosine, tangent and their inverse functions.
* This one only works with numbers.
*/
/obj/item/circuit_component/trigonometry
display_name = "Trigonometry"
desc = "General trigonometry component with main and inverse trigonometry functions."
category = "Math"
var/datum/port/input/option/trigonometric_function
/// The input port
var/datum/port/input/input_port
/// The result from the output
var/datum/port/output/output
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
/obj/item/circuit_component/trigonometry/populate_options()
var/static/component_functions = list(
COMP_TRIGONOMETRY_SINE,
COMP_TRIGONOMETRY_COSINE,
COMP_TRIGONOMETRY_TANGENT,
COMP_TRIGONOMETRY_ARCSINE,
COMP_TRIGONOMETRY_ARCCOSINE,
COMP_TRIGONOMETRY_ARCTANGENT,
)
trigonometric_function = add_option_port("Trigonometric Function", component_functions)
/obj/item/circuit_component/trigonometry/populate_ports()
input_port = add_input_port("Input", PORT_TYPE_NUMBER)
output = add_output_port("Output", PORT_TYPE_NUMBER)
/obj/item/circuit_component/trigonometry/input_received(datum/port/input/port)
var/result = input_port.value
switch(trigonometric_function.value)
if(COMP_TRIGONOMETRY_SINE)
result = sin(result)
if(COMP_TRIGONOMETRY_COSINE)
result = cos(result)
if(COMP_TRIGONOMETRY_TANGENT)
result = tan(result)
if(COMP_TRIGONOMETRY_ARCSINE)
result = arcsin(result)
if(COMP_TRIGONOMETRY_ARCCOSINE)
result = arccos(result)
if(COMP_TRIGONOMETRY_ARCTANGENT)
result = arctan(result)
output.set_output(result)
#undef COMP_TRIGONOMETRY_SINE
#undef COMP_TRIGONOMETRY_COSINE
#undef COMP_TRIGONOMETRY_TANGENT
#undef COMP_TRIGONOMETRY_ARCSINE
#undef COMP_TRIGONOMETRY_ARCCOSINE
#undef COMP_TRIGONOMETRY_ARCTANGENT