propane 3.4.1-java → 3.7.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -1
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +2 -2
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -2
  5. data/.travis.yml +1 -1
  6. data/CHANGELOG.md +9 -1
  7. data/Gemfile +2 -0
  8. data/README.md +9 -5
  9. data/Rakefile +10 -11
  10. data/bin/propane +3 -1
  11. data/lib/propane.rb +4 -2
  12. data/lib/propane/app.rb +2 -1
  13. data/lib/propane/creators/sketch_class.rb +7 -1
  14. data/lib/propane/creators/sketch_factory.rb +4 -2
  15. data/lib/propane/creators/sketch_writer.rb +1 -0
  16. data/lib/propane/helper_methods.rb +22 -23
  17. data/lib/propane/helpers/numeric.rb +2 -0
  18. data/lib/propane/helpers/version_error.rb +1 -0
  19. data/lib/propane/library.rb +5 -1
  20. data/lib/propane/library_loader.rb +2 -0
  21. data/lib/propane/native_folder.rb +10 -9
  22. data/lib/propane/native_loader.rb +3 -0
  23. data/lib/propane/runner.rb +20 -14
  24. data/lib/propane/version.rb +2 -1
  25. data/library/boids/boids.rb +21 -11
  26. data/library/color_group/color_group.rb +2 -0
  27. data/library/control_panel/control_panel.rb +8 -5
  28. data/library/dxf/dxf.rb +2 -0
  29. data/library/file_chooser/chooser.rb +10 -9
  30. data/library/file_chooser/file_chooser.rb +10 -9
  31. data/library/library_proxy/library_proxy.rb +2 -0
  32. data/library/net/net.rb +2 -0
  33. data/library/simplex_noise/simplex_noise.rb +2 -0
  34. data/library/slider/slider.rb +23 -22
  35. data/library/vector_utils/vector_utils.rb +4 -0
  36. data/library/video_event/video_event.rb +2 -0
  37. data/pom.rb +37 -36
  38. data/pom.xml +6 -6
  39. data/propane.gemspec +12 -10
  40. data/src/main/java/japplemenubar/JAppleMenuBar.java +3 -3
  41. data/src/main/java/monkstone/ColorUtil.java +1 -3
  42. data/src/main/java/monkstone/MathToolModule.java +10 -9
  43. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  44. data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
  45. data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
  46. data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
  47. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  48. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  49. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  50. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  51. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  52. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  53. data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
  54. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  55. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
  56. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -2
  57. data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
  58. data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
  59. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  60. data/src/main/java/processing/awt/PGraphicsJava2D.java +781 -285
  61. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  62. data/src/main/java/processing/awt/PShapeJava2D.java +56 -52
  63. data/src/main/java/processing/awt/PSurfaceAWT.java +308 -208
  64. data/src/main/java/processing/awt/ShimAWT.java +581 -0
  65. data/src/main/java/processing/core/PApplet.java +4225 -4855
  66. data/src/main/java/processing/core/PConstants.java +477 -447
  67. data/src/main/java/processing/core/PFont.java +914 -880
  68. data/src/main/java/processing/core/PGraphics.java +150 -134
  69. data/src/main/java/processing/core/PImage.java +275 -372
  70. data/src/main/java/processing/core/PMatrix.java +172 -159
  71. data/src/main/java/processing/core/PMatrix2D.java +478 -415
  72. data/src/main/java/processing/core/PMatrix3D.java +762 -735
  73. data/src/main/java/processing/core/PShape.java +2887 -2651
  74. data/src/main/java/processing/core/PShapeOBJ.java +97 -92
  75. data/src/main/java/processing/core/PShapeSVG.java +1705 -1490
  76. data/src/main/java/processing/core/PStyle.java +40 -37
  77. data/src/main/java/processing/core/PSurface.java +139 -97
  78. data/src/main/java/processing/core/PSurfaceNone.java +296 -218
  79. data/src/main/java/processing/core/PVector.java +995 -963
  80. data/src/main/java/processing/core/ThinkDifferent.java +12 -8
  81. data/src/main/java/processing/data/DoubleDict.java +756 -710
  82. data/src/main/java/processing/data/DoubleList.java +749 -696
  83. data/src/main/java/processing/data/FloatDict.java +748 -702
  84. data/src/main/java/processing/data/FloatList.java +751 -697
  85. data/src/main/java/processing/data/IntDict.java +720 -673
  86. data/src/main/java/processing/data/IntList.java +699 -633
  87. data/src/main/java/processing/data/JSONArray.java +931 -873
  88. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  89. data/src/main/java/processing/data/JSONTokener.java +351 -341
  90. data/src/main/java/processing/data/LongDict.java +710 -663
  91. data/src/main/java/processing/data/LongList.java +701 -635
  92. data/src/main/java/processing/data/Sort.java +37 -41
  93. data/src/main/java/processing/data/StringDict.java +525 -486
  94. data/src/main/java/processing/data/StringList.java +626 -580
  95. data/src/main/java/processing/data/Table.java +3690 -3510
  96. data/src/main/java/processing/data/TableRow.java +182 -183
  97. data/src/main/java/processing/data/XML.java +957 -883
  98. data/src/main/java/processing/event/Event.java +87 -67
  99. data/src/main/java/processing/event/KeyEvent.java +48 -41
  100. data/src/main/java/processing/event/MouseEvent.java +88 -113
  101. data/src/main/java/processing/event/TouchEvent.java +10 -6
  102. data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
  103. data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
  104. data/src/main/java/processing/net/Client.java +20 -20
  105. data/src/main/java/processing/net/Server.java +9 -9
  106. data/src/main/java/processing/opengl/FontTexture.java +286 -266
  107. data/src/main/java/processing/opengl/FrameBuffer.java +389 -377
  108. data/src/main/java/processing/opengl/LinePath.java +132 -89
  109. data/src/main/java/processing/opengl/LineStroker.java +588 -581
  110. data/src/main/java/processing/opengl/PGL.java +660 -567
  111. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  112. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  113. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
  114. data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
  115. data/src/main/java/processing/opengl/PShader.java +369 -461
  116. data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
  117. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
  118. data/src/main/java/processing/opengl/Texture.java +1492 -1401
  119. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  120. data/test/create_test.rb +21 -20
  121. data/test/deglut_spec_test.rb +4 -2
  122. data/test/helper_methods_test.rb +49 -20
  123. data/test/math_tool_test.rb +39 -32
  124. data/test/native_folder.rb +47 -0
  125. data/test/respond_to_test.rb +3 -2
  126. data/test/sketches/key_event.rb +2 -2
  127. data/test/sketches/library/my_library/my_library.rb +3 -0
  128. data/test/test_helper.rb +2 -0
  129. data/test/vecmath_spec_test.rb +35 -22
  130. data/vendors/Rakefile +35 -40
  131. metadata +42 -22
  132. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  133. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  134. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  135. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -1,3 +1,5 @@
1
+ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
+
1
3
  /*
2
4
  Part of the Processing project - http://processing.org
3
5
 
@@ -18,69 +20,69 @@
18
20
  Public License along with this library; if not, write to the
19
21
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
22
  Boston, MA 02111-1307 USA
21
- */
23
+ */
24
+
22
25
  package processing.opengl;
23
26
 
24
27
  import processing.opengl.PGraphicsOpenGL.GLResourceVertexBuffer;
25
28
 
26
29
  // TODO: need to combine with PGraphicsOpenGL.VertexAttribute
27
30
  public class VertexBuffer {
28
-
29
- static protected final int INIT_VERTEX_BUFFER_SIZE = 256;
30
- static protected final int INIT_INDEX_BUFFER_SIZE = 512;
31
-
32
- public int glId;
33
- int target;
34
- int elementSize;
35
- int ncoords;
36
- boolean index;
37
-
38
- protected PGL pgl; // The interface between Processing and OpenGL.
39
- protected int context; // The context that created this texture.
40
- private GLResourceVertexBuffer glres;
41
-
42
- VertexBuffer(PGraphicsOpenGL pg, int target, int ncoords, int esize) {
43
- this(pg, target, ncoords, esize, false);
44
- }
45
-
46
- VertexBuffer(PGraphicsOpenGL pg, int target, int ncoords, int esize, boolean index) {
47
- pgl = pg.pgl;
48
- context = pgl.createEmptyContext();
49
-
50
- this.target = target;
51
- this.ncoords = ncoords;
52
- this.elementSize = esize;
53
- this.index = index;
54
- create();
55
- init();
56
- }
57
-
58
- protected void create() {
59
- context = pgl.getCurrentContext();
60
- glres = new GLResourceVertexBuffer(this);
61
- }
62
-
63
- protected void init() {
64
- int size = index ? ncoords * INIT_INDEX_BUFFER_SIZE * elementSize
65
- : ncoords * INIT_VERTEX_BUFFER_SIZE * elementSize;
66
- pgl.bindBuffer(target, glId);
67
- pgl.bufferData(target, size, null, PGL.STATIC_DRAW);
68
- }
69
-
70
- protected void dispose() {
71
- if (glres != null) {
72
- glres.dispose();
73
- glId = 0;
74
- glres = null;
75
- }
31
+ static protected final int INIT_VERTEX_BUFFER_SIZE = 256;
32
+ static protected final int INIT_INDEX_BUFFER_SIZE = 512;
33
+
34
+ public int glId;
35
+ int target;
36
+ int elementSize;
37
+ int ncoords;
38
+ boolean index;
39
+
40
+ protected PGL pgl; // The interface between Processing and OpenGL.
41
+ protected int context; // The context that created this texture.
42
+ private GLResourceVertexBuffer glres;
43
+
44
+ VertexBuffer(PGraphicsOpenGL pg, int target, int ncoords, int esize) {
45
+ this(pg, target, ncoords, esize, false);
46
+ }
47
+
48
+ VertexBuffer(PGraphicsOpenGL pg, int target, int ncoords, int esize, boolean index) {
49
+ pgl = pg.pgl;
50
+ context = pgl.createEmptyContext();
51
+
52
+ this.target = target;
53
+ this.ncoords = ncoords;
54
+ this.elementSize = esize;
55
+ this.index = index;
56
+ create();
57
+ init();
58
+ }
59
+
60
+ protected final void create() {
61
+ context = pgl.getCurrentContext();
62
+ glres = new GLResourceVertexBuffer(this);
63
+ }
64
+
65
+ protected final void init() {
66
+ int size = index ? ncoords * INIT_INDEX_BUFFER_SIZE * elementSize :
67
+ ncoords * INIT_VERTEX_BUFFER_SIZE * elementSize;
68
+ pgl.bindBuffer(target, glId);
69
+ pgl.bufferData(target, size, null, PGL.STATIC_DRAW);
70
+ }
71
+
72
+ protected void dispose() {
73
+ if (glres != null) {
74
+ glres.dispose();
75
+ glId = 0;
76
+ glres = null;
76
77
  }
78
+ }
77
79
 
78
- protected boolean contextIsOutdated() {
79
- boolean outdated = !pgl.contextIsCurrent(context);
80
- if (outdated) {
81
- dispose();
82
- }
83
- return outdated;
80
+ protected boolean contextIsOutdated() {
81
+ boolean outdated = !pgl.contextIsCurrent(context);
82
+ if (outdated) {
83
+ dispose();
84
84
  }
85
+ return outdated;
86
+ }
85
87
 
86
88
  }
data/test/create_test.rb CHANGED
@@ -1,33 +1,34 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'test_helper'
2
4
  require_relative '../lib/propane/creators/sketch_class'
3
5
  require_relative '../lib/propane/creators/sketch_writer'
4
6
 
5
7
  CLASS_SKETCH = <<~CODE
8
+ #!/usr/bin/env jruby
9
+ # frozen_string_literal: false
6
10
 
7
- #!/usr/bin/env jruby
8
- # frozen_string_literal: false
9
- require 'propane'
11
+ require 'propane'
10
12
 
11
- class FredSketch < Propane::App
12
- def settings
13
- size 200, 200
14
- end
13
+ class FredSketch < Propane::App
14
+ def settings
15
+ size 200, 200
16
+ end
15
17
 
16
- def setup
17
- sketch_title 'Fred Sketch'
18
- end
18
+ def setup
19
+ sketch_title 'Fred Sketch'
20
+ end
19
21
 
20
- def draw
22
+ def draw
21
23
 
24
+ end
22
25
  end
23
- end
24
26
 
25
- FredSketch.new
27
+ FredSketch.new
26
28
 
27
29
  CODE
28
-
30
+ # Create sketch test
29
31
  class SketchClassTest < Minitest::Test
30
-
31
32
  def setup
32
33
  @basic = SketchClass.new(name: 'fred_sketch', width: 200, height: 200)
33
34
  @sketch = SketchClass.new(name: 'fred_sketch', width: 200, height: 200, mode: 'p2d')
@@ -35,7 +36,7 @@ class SketchClassTest < Minitest::Test
35
36
 
36
37
  def test_class
37
38
  result = CLASS_SKETCH.split(/\n/, -1)
38
- class_lines = @sketch.lines
39
+ class_lines = @basic.lines
39
40
  class_lines.each_with_index do |line, i|
40
41
  assert_equal result[i], line
41
42
  end
@@ -54,15 +55,15 @@ class SketchClassTest < Minitest::Test
54
55
  assert_equal " sketch_title 'Fred Sketch'", @sketch.sketch_title
55
56
  end
56
57
 
57
- def test_class
58
- assert_equal "FredSketch", @sketch.sketch_class
58
+ def test_class_class
59
+ assert_equal 'FredSketch', @sketch.sketch_class
59
60
  end
60
61
 
61
62
  def test_class_new
62
- assert_equal "FredSketch.new", @sketch.sketch_new
63
+ assert_equal 'FredSketch.new', @sketch.sketch_new
63
64
  end
64
65
 
65
66
  def test_sketch_class
66
- assert_equal "class FredSketch < Propane::App", @basic.class_sketch
67
+ assert_equal 'class FredSketch < Propane::App', @basic.class_sketch
67
68
  end
68
69
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'test_helper'
2
4
  require 'java'
3
5
  require_relative '../lib/propane'
@@ -15,10 +17,10 @@ class DeglutTest < Minitest::Test
15
17
  (-720..720).step(1) do |deg|
16
18
  sine = DegLut.sin(deg)
17
19
  deg_sin = Math.sin(deg * to_radian)
18
- assert_in_delta(sine, deg_sin, delta = 0.000001)
20
+ assert_in_delta(sine, deg_sin, 0.000001)
19
21
  cosine = DegLut.cos(deg)
20
22
  deg_cos = Math.cos(deg * to_radian)
21
- assert_in_delta(cosine, deg_cos, delta = 0.000001)
23
+ assert_in_delta(cosine, deg_cos, 0.000001)
22
24
  end
23
25
  end
24
26
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative 'test_helper'
3
4
  require 'java'
4
5
  require_relative '../lib/propane'
@@ -11,41 +12,69 @@ include MathTool
11
12
  Dir.chdir(File.dirname(__FILE__))
12
13
 
13
14
  class HelperMethodsTest < Minitest::Test
14
-
15
- ARRAY = %w(albatross dog horse)
16
- def test_hex_color
15
+ ARRAY = %w[albatross dog horse].freeze
16
+ def test_hex_color
17
17
  col_double = 0.5
18
18
  hexcolor = 0xFFCC6600
19
19
  dodgy_hexstring = '*56666'
20
20
  hexstring = '#CC6600'
21
21
  assert hex_color(col_double) == 0.5, 'double as a color'
22
- assert hex_color(hexcolor) == -3381760, 'hexadecimal fixnum color'
23
- assert hex_color(hexstring) == -3381760, 'hexadecimal string color'
22
+ assert hex_color(hexcolor) == -3_381_760, 'hexadecimal fixnum color'
23
+ assert hex_color(hexstring) == -3_381_760, 'hexadecimal string color'
24
24
  assert_raises(StandardError, 'Dodgy Hexstring') do
25
25
  hex_color(dodgy_hexstring)
26
26
  end
27
27
  assert_raises(StandardError, 'Dodgy Color Conversion') do
28
28
  hex_color([])
29
29
  end
30
- end
30
+ end
31
31
 
32
32
  def test_dist
33
- ax, ay, bx, by = 0, 0, 1.0, 1.0
34
- assert_in_epsilon(dist(ax, ay, bx, by), Math.sqrt(2), epsilon = 0.0001, msg = '2D distance')
33
+ ax = 0
34
+ ay = 0
35
+ bx = 1.0
36
+ by = 1.0
37
+ assert_in_epsilon(dist(ax, ay, bx, by), Math.sqrt(2), 0.0001, '2D distance')
35
38
  by = 0.0
36
- assert_in_epsilon(dist(ax, ay, bx, by), 1.0, epsilon = 0.0001, msg = 'when y dimension is zero')
37
- ax, ay, bx, by = 0, 0, 0.0, 0.0
38
- assert_in_epsilon(dist(ax, ay, bx, by), 0.0, epsilon = 0.0001, msg = 'when x and y dimension are zero')
39
- ax, ay, bx, by = 1, 1, -2.0, -3.0
40
- assert_in_epsilon(dist(ax, ay, bx, by), 5.0, epsilon = 0.0001, msg = 'classic triangle dimensions')
41
- ax, ay, bx, by, cx, cy = -1, -1, 100, 2.0, 3.0, 100
42
- assert_in_epsilon(dist(ax, ay, bx, by, cx, cy), 5.0, epsilon = 0.0001, msg = 'classic triangle dimensions')
43
- ax, ay, bx, by, cx, cy = 0, 0, -1.0, -1.0, 0, 0
44
- assert_in_epsilon(dist(ax, ay, bx, by, cx, cy), Math.sqrt(2), epsilon = 0.0001, msg = '2D distance')
45
- ax, ay, bx, by, cx, cy = 0, 0, 0.0, 0.0, 0, 0
39
+ assert_in_epsilon(dist(ax, ay, bx, by), 1.0, 0.0001, 'when y dimension is zero')
40
+ ax = 0
41
+ ay = 0
42
+ bx = 0.0
43
+ by = 0.0
44
+ assert_in_epsilon(dist(ax, ay, bx, by), 0.0, 0.0001, 'when x and y dimension are zero')
45
+ ax = 1
46
+ ay = 1
47
+ bx = -2.0
48
+ by = -3.0
49
+ assert_in_epsilon(dist(ax, ay, bx, by), 5.0, 0.0001, 'classic triangle dimensions')
50
+ ax = -1
51
+ ay = -1
52
+ bx = 100
53
+ by = 2.0
54
+ cx = 3.0
55
+ cy = 100
56
+ assert_in_epsilon(dist(ax, ay, bx, by, cx, cy), 5.0, 0.0001, 'classic triangle dimensions')
57
+ ax = 0
58
+ ay = 0
59
+ bx = -1.0
60
+ by = -1.0
61
+ cx = 0
62
+ cy = 0
63
+ assert_in_epsilon(dist(ax, ay, bx, by, cx, cy), Math.sqrt(2), 0.0001, '2D distance')
64
+ ax = 0
65
+ ay = 0
66
+ bx = 0.0
67
+ by = 0.0
68
+ cx = 0
69
+ cy = 0
46
70
  assert_in_epsilon(dist(ax, ay, bx, by, cx, cy), 0.0)
47
- ax, ay, bx, by, cx, cy = 0, 0, 1.0, 0.0, 0, 0
48
- assert_in_epsilon(dist(ax, ay, bx, by, cx, cy), 1.0, epsilon = 0.0001, msg = 'when x and z dimension are zero')
71
+ ax = 0
72
+ ay = 0
73
+ bx = 1.0
74
+ by = 0.0
75
+ cx = 0
76
+ cy = 0
77
+ assert_in_epsilon(dist(ax, ay, bx, by, cx, cy), 1.0, 0.0001, 'when x and z dimension are zero')
49
78
  end
50
79
 
51
80
  def test_min
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'test_helper'
2
4
  require 'java'
3
5
  require_relative '../lib/propane'
@@ -6,21 +8,20 @@ Java::Monkstone::PropaneLibrary.new.load(JRuby.runtime, false)
6
8
 
7
9
  # include Processing::HelperMethods
8
10
 
9
-
10
11
  Dir.chdir(File.dirname(__FILE__))
11
12
 
12
13
  class MathToolTest < Minitest::Test
13
- include MathTool
14
- def test_map1d
14
+ include MathTool
15
+ def test_map1d
15
16
  x = [0, 5, 7.5, 10]
16
17
  range1 = (0..10)
17
18
  range2 = (100..1)
18
19
  range3 = (0..10)
19
20
  range4 = (5..105)
20
- assert_in_delta(map1d(x[0], range1, range2), 100, delta = 0.00001, msg = 'map to first')
21
- assert_in_delta(map1d(x[1], range1, range2), 50.5, delta = 0.00001, msg = 'map to reversed intermediate')
22
- assert_in_delta(map1d(x[2], range3, range4), 80.0, delta = 0.00001, msg = 'map to intermediate')
23
- assert_in_delta(map1d(x[3], range1, range2), 1, delta = 0.00001, msg = 'map to last')
21
+ assert_in_delta(map1d(x[0], range1, range2), 100, 0.00001, 'map to first')
22
+ assert_in_delta(map1d(x[1], range1, range2), 50.5, 0.00001, 'map to reversed intermediate')
23
+ assert_in_delta(map1d(x[2], range3, range4), 80.0, 0.00001, 'map to intermediate')
24
+ assert_in_delta(map1d(x[3], range1, range2), 1, 0.00001, 'map to last')
24
25
  end
25
26
 
26
27
  def test_p5map # as map1d except not using range input
@@ -29,47 +30,53 @@ class MathToolTest < Minitest::Test
29
30
  range2 = (100..1)
30
31
  range3 = (0..10)
31
32
  range4 = (5..105)
32
- assert_in_delta(p5map(x[0], range1.first, range1.last, range2.first, range2.last), 100, delta = 0.00001)
33
- assert_in_delta(p5map(x[1], range1.first, range1.last, range2.first, range2.last), 50.5, delta = 0.00001)
34
- assert_in_delta(p5map(x[2], range3.first, range3.last, range4.first, range4.last), 80.0, delta = 0.00001)
35
- assert_in_delta(p5map(x[3], range1.first, range1.last, range2.first, range2.last), 1, delta = 0.00001)
33
+ assert_in_delta(p5map(x[0], range1.first, range1.last, range2.first, range2.last), 100, 0.00001)
34
+ assert_in_delta(p5map(x[1], range1.first, range1.last, range2.first, range2.last), 50.5, 0.00001)
35
+ assert_in_delta(p5map(x[2], range3.first, range3.last, range4.first, range4.last), 80.0, 0.00001)
36
+ assert_in_delta(p5map(x[3], range1.first, range1.last, range2.first, range2.last), 1, 0.00001)
36
37
  end
37
38
 
38
39
  def test_norm
39
40
  x = [10, 140, 210]
40
- start0, last0 = 30, 200
41
- start_int, last_int = 0, 200
42
- assert_in_delta(norm(x[0], start0, last0), -0.11764705882352941, delta = 0.00001, msg = 'unclamped map')
43
- assert_in_delta(norm(x[1], start_int, last_int), 0.7, delta = 0.00001, msg = 'map to intermediate')
44
- assert_in_delta(norm(x[2], start_int, last_int), 1.05, delta = 0.00001, msg = 'unclamped map')
41
+ start0 = 30
42
+ last0 = 200
43
+ start_int = 0
44
+ last_int = 200
45
+ assert_in_delta(norm(x[0], start0, last0), -0.11764705882352941, 0.00001, 'unclamped map')
46
+ assert_in_delta(norm(x[1], start_int, last_int), 0.7, 0.00001, 'map to intermediate')
47
+ assert_in_delta(norm(x[2], start_int, last_int), 1.05, 0.00001, 'unclamped map')
45
48
  end
46
49
 
47
50
  def test_norm_strict
48
51
  x = [10, 140, 210]
49
- assert_in_delta(norm_strict(x[2], x[0], x[1]), 1.0, delta = 0.00001, msg = 'clamped map to 0..1.0')
50
- assert_in_delta(norm_strict(x[2], x[1], x[0]), 0.0, delta = 0.00001, msg = 'clamped map to 0..1.0')
51
- assert_in_delta(norm_strict(x[1], x[0], x[2]), 0.65, delta = 0.00001, msg = 'clamped map to 0..1.0')
52
+ assert_in_delta(norm_strict(x[2], x[0], x[1]), 1.0, 0.00001, 'clamped map to 0..1.0')
53
+ assert_in_delta(norm_strict(x[2], x[1], x[0]), 0.0, 0.00001, 'clamped map to 0..1.0')
54
+ assert_in_delta(norm_strict(x[1], x[0], x[2]), 0.65, 0.00001, 'clamped map to 0..1.0')
52
55
  end
53
56
 
54
57
  def test_lerp # behaviour is deliberately different to processing which is unclamped
55
58
  x = [0.5, 0.8, 2.0]
56
- start0, last0 = 300, 200
57
- start_int, last_int = 0, 200
58
- assert_in_delta(lerp(start0, last0, x[0]), 250, delta = 0.00001, msg = 'produces a intermediate value of a reversed range')
59
- assert_in_delta(lerp(start_int, last_int, x[1]), 160, delta = 0.00001, msg = 'lerps to an intermediate value')
60
- assert_in_delta(lerp(start_int, last_int, x[2]), 200, delta = 0.00001, msg = 'lerps to the last value of a range')
59
+ start0 = 300
60
+ last0 = 200
61
+ start_int = 0
62
+ last_int = 200
63
+ assert_in_delta(lerp(start0, last0, x[0]), 250, 0.00001, 'produces a intermediate value of a reversed range')
64
+ assert_in_delta(lerp(start_int, last_int, x[1]), 160, 0.00001, 'lerps to an intermediate value')
65
+ assert_in_delta(lerp(start_int, last_int, x[2]), 200, 0.00001, 'lerps to the last value of a range')
61
66
  end
62
67
 
63
68
  def test_constrain
64
69
  x_int = [15, 2_500, -2_500]
65
- start_int, last_int = 0, 200
66
- assert_in_delta(constrain(x_int[0], start_int, last_int), 15, delta = 0.00001)
67
- assert_in_delta(constrain(x_int[1], start_int, last_int), 200, delta = 0.00001)
68
- assert_in_delta(constrain(x_int[2], start_int, last_int), 0, delta = 0.00001)
70
+ start_int = 0
71
+ last_int = 200
72
+ assert_in_delta(constrain(x_int[0], start_int, last_int), 15, 0.00001)
73
+ assert_in_delta(constrain(x_int[1], start_int, last_int), 200, 0.00001)
74
+ assert_in_delta(constrain(x_int[2], start_int, last_int), 0, 0.00001)
69
75
  xf = [15.0, 2_500.0, -2_500.0]
70
- startf, lastf = 0, 200.0
71
- assert_in_delta(constrain(xf[0], startf, lastf), 15.0, delta = 0.00001, msg = 'constrain to 0..200')
72
- assert_in_delta(constrain(xf[1], startf, lastf), 200.0, delta = 0.00001, msg = 'constrain to 0..200')
73
- assert_in_delta(constrain(xf[2], startf, lastf), 0.0, delta = 0.00001, msg = 'constrain to 0..200')
76
+ startf = 0
77
+ lastf = 200.0
78
+ assert_in_delta(constrain(xf[0], startf, lastf), 15.0, 0.00001, 'constrain to 0..200')
79
+ assert_in_delta(constrain(xf[1], startf, lastf), 200.0, 0.00001, 'constrain to 0..200')
80
+ assert_in_delta(constrain(xf[2], startf, lastf), 0.0, 0.00001, 'constrain to 0..200')
74
81
  end
75
82
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'test_helper'
4
+ require 'java'
5
+ require_relative '../lib/propane'
6
+ # Mock class
7
+ class WindowsNativeFolder < NativeFolder
8
+ def initialize
9
+ @os = 'mswin'
10
+ @bit = 64
11
+ end
12
+ end
13
+
14
+ class MacNativeFolder < NativeFolder
15
+ def initialize
16
+ @os = 'mac'
17
+ @bit = 64
18
+ end
19
+ end
20
+
21
+ # Test class
22
+ class NativeFolderTest < Minitest::Test
23
+ def test_windows_native_folder
24
+ obj = WindowsNativeFolder.new
25
+ assert_kind_of NativeFolder, obj, 'Constructor Failed'
26
+ assert(/windows/.match?(obj.name))
27
+ assert(/\*.dll/.match?(obj.extension))
28
+ end
29
+
30
+ class NativeFolderTest < Minitest::Test
31
+ def test_windows_native_folder
32
+ obj = MacNativeFolder.new
33
+ assert_kind_of NativeFolder, obj, 'Constructor Failed'
34
+ assert(/macos/.match?(obj.name))
35
+ assert(/\*.dylib/.match?(obj.extension))
36
+ end
37
+ end
38
+
39
+ if /linux/.match?(RbConfig::CONFIG['host_os'].downcase)
40
+ def test_native_folder
41
+ obj = NativeFolder.new
42
+ assert_instance_of NativeFolder, obj, 'Constructor Failed'
43
+ assert(/linux/.match?(obj.name))
44
+ assert(/\*.so/.match?(obj.extension))
45
+ end
46
+ end
47
+ end