1
1
# frozen_string_literal: false
2
+
2
3
# processing module wrapper
3
4
require_relative 'helpers/numeric'
4
5
module Processing
@@ -52,6 +53,7 @@ def hsb_color(hue, sat, brightness)
52
53
53
54
def color ( *args )
54
55
return super ( *args ) unless args . length == 1
56
+
55
57
super ( hex_color ( args [ 0 ] ) )
56
58
end
57
59
@@ -66,11 +68,8 @@ def int_to_ruby_colors(hex)
66
68
# Overrides Processing convenience function thread, which takes a String
67
69
# arg (for a function) to more rubylike version, takes a block...
68
70
def thread ( &block )
69
- if block_given?
70
- Thread . new ( &block )
71
- else
72
- raise ArgumentError , 'thread must be called with a block' , caller
73
- end
71
+ warn 'you must provide a block' unless block_given?
72
+ Java ::JavaLang ::Thread . new ( &block ) . start
74
73
end
75
74
76
75
# explicitly provide 'processing.org' min instance method
@@ -94,9 +93,9 @@ def max(*args)
94
93
def dist ( *args )
95
94
case args . length
96
95
when 4
97
- return dist2d ( *args )
96
+ dist2d ( *args )
98
97
when 6
99
- return dist3d ( *args )
98
+ dist3d ( *args )
100
99
else
101
100
raise ArgumentError , 'takes 4 or 6 parameters'
102
101
end
@@ -117,7 +116,7 @@ def find_method(method_name)
117
116
# Proxy over a list of Java declared fields that have the same name as
118
117
# some methods. Add to this list as needed.
119
118
def proxy_java_fields
120
- fields = %w( key frameRate mousePressed keyPressed )
119
+ fields = %w[ key frameRate mousePressed keyPressed ]
121
120
methods = fields . map { |field | java_class . declared_field ( field ) }
122
121
@declared_fields = Hash [ fields . zip ( methods ) ]
123
122
end
@@ -163,6 +162,7 @@ def save_strings(filename, strings)
163
162
# frame_rate needs to support reading and writing
164
163
def frame_rate ( fps = nil )
165
164
return @declared_fields [ 'frameRate' ] . value ( java_self ) unless fps
165
+
166
166
super ( fps )
167
167
end
168
168
@@ -178,19 +178,17 @@ def key_pressed?
178
178
179
179
private
180
180
181
- INTEGER_COL = -> ( x ) { x . is_a? ( Integer ) }
182
- STRING_COL = -> ( x ) { x . is_a? ( String ) }
183
- FLOAT_COL = -> ( x ) { x . is_a? ( Float ) }
184
181
# parse single argument color int/double/String
185
- def hex_color ( a )
186
- case a
187
- when INTEGER_COL
188
- Java ::Monkstone ::ColorUtil . colorLong ( a )
189
- when STRING_COL
190
- return Java ::Monkstone ::ColorUtil . colorString ( a ) if a =~ /#\h +/
191
- raise StandardError , 'Dodgy Hexstring'
192
- when FLOAT_COL
193
- Java ::Monkstone ::ColorUtil . colorDouble ( a )
182
+ def hex_color ( arg )
183
+ case arg
184
+ when Integer
185
+ Java ::Monkstone ::ColorUtil . colorLong ( arg )
186
+ when String
187
+ raise StandardError , 'Dodgy Hexstring' unless arg . match ( /#\h {6}$/ )
188
+
189
+ Java ::Monkstone ::ColorUtil . colorString ( arg )
190
+ when Float
191
+ Java ::Monkstone ::ColorUtil . colorDouble ( arg )
194
192
else
195
193
raise StandardError , 'Dodgy Color Conversion'
196
194
end
@@ -200,6 +198,7 @@ def dist2d(*args)
200
198
dx = args [ 0 ] - args [ 2 ]
201
199
dy = args [ 1 ] - args [ 3 ]
202
200
return 0 if dx . abs < EPSILON && dy . abs < EPSILON
201
+
203
202
Math . hypot ( dx , dy )
204
203
end
205
204
@@ -208,6 +207,7 @@ def dist3d(*args)
208
207
dy = args [ 1 ] - args [ 4 ]
209
208
dz = args [ 2 ] - args [ 5 ]
210
209
return 0 if dx . abs < EPSILON && dy . abs < EPSILON && dz . abs < EPSILON
210
+
211
211
Math . sqrt ( dx * dx + dy * dy + dz * dz )
212
212
end
213
213
end
0 commit comments