propane 3.4.2-java → 3.8.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) 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 +7 -10
  9. data/Rakefile +10 -11
  10. data/bin/propane +3 -1
  11. data/lib/propane.rb +4 -2
  12. data/lib/propane/app.rb +5 -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/slider/slider.rb +23 -22
  34. data/library/vector_utils/vector_utils.rb +4 -0
  35. data/library/video_event/video_event.rb +2 -0
  36. data/pom.rb +37 -36
  37. data/pom.xml +7 -7
  38. data/propane.gemspec +13 -9
  39. data/src/main/java/japplemenubar/JAppleMenuBar.java +3 -3
  40. data/src/main/java/monkstone/ColorUtil.java +1 -3
  41. data/src/main/java/monkstone/MathToolModule.java +1 -1
  42. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  43. data/src/main/java/monkstone/fastmath/DegLutTables.java +111 -0
  44. data/src/main/java/monkstone/fastmath/Deglut.java +6 -56
  45. data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
  46. data/src/main/java/monkstone/noise/Noise.java +116 -0
  47. data/src/main/java/monkstone/noise/NoiseGenerator.java +63 -0
  48. data/src/main/java/monkstone/noise/NoiseMode.java +15 -0
  49. data/src/main/java/monkstone/noise/SimplexNoise.java +137 -103
  50. data/src/main/java/monkstone/noise/ValueNoise.java +170 -0
  51. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  52. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  53. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  54. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  55. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  56. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  57. data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
  58. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  59. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
  60. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -2
  61. data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
  62. data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
  63. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  64. data/src/main/java/processing/awt/PGraphicsJava2D.java +781 -285
  65. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  66. data/src/main/java/processing/awt/PShapeJava2D.java +56 -52
  67. data/src/main/java/processing/awt/PSurfaceAWT.java +308 -208
  68. data/src/main/java/processing/awt/ShimAWT.java +581 -0
  69. data/src/main/java/processing/core/PApplet.java +13142 -13883
  70. data/src/main/java/processing/core/PConstants.java +477 -447
  71. data/src/main/java/processing/core/PFont.java +914 -880
  72. data/src/main/java/processing/core/PGraphics.java +152 -136
  73. data/src/main/java/processing/core/PImage.java +275 -372
  74. data/src/main/java/processing/core/PMatrix.java +172 -159
  75. data/src/main/java/processing/core/PMatrix2D.java +478 -415
  76. data/src/main/java/processing/core/PMatrix3D.java +762 -735
  77. data/src/main/java/processing/core/PShape.java +2887 -2651
  78. data/src/main/java/processing/core/PShapeOBJ.java +97 -92
  79. data/src/main/java/processing/core/PShapeSVG.java +1705 -1490
  80. data/src/main/java/processing/core/PStyle.java +40 -37
  81. data/src/main/java/processing/core/PSurface.java +139 -97
  82. data/src/main/java/processing/core/PSurfaceNone.java +296 -218
  83. data/src/main/java/processing/core/PVector.java +995 -963
  84. data/src/main/java/processing/core/ThinkDifferent.java +12 -8
  85. data/src/main/java/processing/data/DoubleDict.java +756 -710
  86. data/src/main/java/processing/data/DoubleList.java +749 -696
  87. data/src/main/java/processing/data/FloatDict.java +748 -702
  88. data/src/main/java/processing/data/FloatList.java +751 -697
  89. data/src/main/java/processing/data/IntDict.java +720 -673
  90. data/src/main/java/processing/data/IntList.java +699 -633
  91. data/src/main/java/processing/data/JSONArray.java +931 -873
  92. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  93. data/src/main/java/processing/data/JSONTokener.java +351 -341
  94. data/src/main/java/processing/data/LongDict.java +710 -663
  95. data/src/main/java/processing/data/LongList.java +701 -635
  96. data/src/main/java/processing/data/Sort.java +37 -41
  97. data/src/main/java/processing/data/StringDict.java +525 -486
  98. data/src/main/java/processing/data/StringList.java +626 -580
  99. data/src/main/java/processing/data/Table.java +3690 -3510
  100. data/src/main/java/processing/data/TableRow.java +182 -183
  101. data/src/main/java/processing/data/XML.java +957 -883
  102. data/src/main/java/processing/event/Event.java +87 -67
  103. data/src/main/java/processing/event/KeyEvent.java +48 -41
  104. data/src/main/java/processing/event/MouseEvent.java +88 -113
  105. data/src/main/java/processing/event/TouchEvent.java +10 -6
  106. data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
  107. data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
  108. data/src/main/java/processing/net/Client.java +20 -20
  109. data/src/main/java/processing/net/Server.java +9 -9
  110. data/src/main/java/processing/opengl/FontTexture.java +286 -266
  111. data/src/main/java/processing/opengl/FrameBuffer.java +389 -377
  112. data/src/main/java/processing/opengl/LinePath.java +132 -89
  113. data/src/main/java/processing/opengl/LineStroker.java +588 -581
  114. data/src/main/java/processing/opengl/PGL.java +660 -567
  115. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  116. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  117. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
  118. data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
  119. data/src/main/java/processing/opengl/PShader.java +369 -461
  120. data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
  121. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
  122. data/src/main/java/processing/opengl/Texture.java +1492 -1401
  123. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  124. data/test/create_test.rb +21 -20
  125. data/test/deglut_spec_test.rb +4 -2
  126. data/test/helper_methods_test.rb +49 -20
  127. data/test/math_tool_test.rb +39 -32
  128. data/test/native_folder.rb +47 -0
  129. data/test/respond_to_test.rb +3 -2
  130. data/test/sketches/key_event.rb +2 -2
  131. data/test/sketches/library/my_library/my_library.rb +3 -0
  132. data/test/test_helper.rb +2 -0
  133. data/test/vecmath_spec_test.rb +35 -22
  134. data/vendors/Rakefile +35 -40
  135. metadata +47 -23
  136. data/library/simplex_noise/simplex_noise.rb +0 -3
  137. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  138. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  139. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  140. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Propane::App
2
4
  include Java::MonkstoneVideoevent::CaptureEvent
3
5
  include Java::MonkstoneVideoevent::MovieEvent
data/pom.rb CHANGED
@@ -1,7 +1,8 @@
1
- project 'propane', 'https://github.com/monkstone/propane' do
1
+ # frozen_string_literal: true
2
2
 
3
+ project 'propane', 'https://github.com/monkstone/propane' do
3
4
  model_version '4.0.0'
4
- id 'propane:propane:3.4.2'
5
+ id 'propane:propane:3.8.0'
5
6
  packaging 'jar'
6
7
 
7
8
  description 'An integrated processing-core (somewhat hacked), with additional java code for a jruby version of processing.'
@@ -33,49 +34,49 @@ project 'propane', 'https://github.com/monkstone/propane' do
33
34
 
34
35
  issue_management 'https://github.com/ruby-processing/propane/issues', 'Github'
35
36
 
36
- source_control( :url => 'https://github.com/ruby-processing/propane',
37
- :connection => 'scm:git:git://github.com/ruby-processing/propane.git',
38
- :developer_connection => 'scm:git:git@github.com/ruby-processing/propane.git' )
37
+ source_control(url: 'https://github.com/ruby-processing/propane',
38
+ connection: 'scm:git:git://github.com/ruby-processing/propane.git',
39
+ developer_connection: 'scm:git:git@github.com/ruby-processing/propane.git')
39
40
 
40
- properties( 'propane.basedir' => '${project.basedir}',
41
+ properties('propane.basedir' => '${project.basedir}',
41
42
  'processing.api' => 'http://processing.github.io/processing-javadocs/core/',
42
43
  'source.directory' => 'src',
43
44
  'polyglot.dump.pom' => 'pom.xml',
44
45
  'project.build.sourceEncoding' => 'utf-8',
45
- 'jogl.version' => '2.3.2',
46
- 'jruby.api' => 'http://jruby.org/apidocs/' )
46
+ 'jogl.version' => '2.3.2', # for compiling actual included 2.4.0-rc
47
+ 'jruby.api' => 'http://jruby.org/apidocs/')
47
48
 
48
- pom 'org.jruby:jruby:9.2.9.0'
49
- jar 'org.processing:video:3.3.7'
49
+ pom 'org.jruby:jruby:9.2.16.0'
50
+ jar 'org.processing:video:3.3.7' # only for compiling
50
51
  jar 'org.jogamp.jogl:jogl-all:${jogl.version}'
51
52
  jar 'org.jogamp.gluegen:gluegen-rt-main:${jogl.version}'
52
53
 
53
54
  overrides do
54
- plugin( 'org.codehaus.mojo:versions-maven-plugin:2.7',
55
- 'generateBackupPoms' => 'false' )
56
- plugin( :compiler, '3.8.1',
57
- 'release' => '11' )
58
- plugin( :javadoc, '3.1.1',
59
- 'detectOfflineLinks' => 'false',
60
- 'links' => [ '${jruby.api}',
61
- '${processing.api}' ] )
62
- plugin(
63
- :jar, '3.1.2',
55
+ plugin('org.codehaus.mojo:versions-maven-plugin:2.7',
56
+ 'generateBackupPoms' => 'false')
57
+ plugin(:compiler, '3.8.1',
58
+ 'release' => '11')
59
+ plugin(:javadoc, '3.2.0',
60
+ 'detectOfflineLinks' => 'false',
61
+ 'links' => ['${jruby.api}',
62
+ '${processing.api}'])
63
+ plugin(:jar, '3.2.0',
64
64
  'archive' => {
65
- 'manifestEntries' => { 'Class-Path' => 'gluegen-rt.jar jog-all.jar' }
66
- }
67
- )
68
- end
69
- build do
70
- resource do
71
- directory '${source.directory}/main/java'
72
- includes '**/**/*.glsl', '**/*.jnilib'
73
- excludes '**/**/*.java'
74
- end
75
- resource do
76
- directory '${source.directory}/main/resources'
77
- includes '**/*.png', '*.txt'
78
- excludes
65
+ 'manifestEntries' => {
66
+ 'Automatic-Module-Name' => 'processing.core'
67
+ }
68
+ })
69
+ end
70
+ build do
71
+ resource do
72
+ directory '${source.directory}/main/java'
73
+ includes '**/**/*.glsl', '**/*.jnilib'
74
+ excludes '**/**/*.java'
75
+ end
76
+ resource do
77
+ directory '${source.directory}/main/resources'
78
+ includes '**/*.png', '*.txt'
79
+ excludes
80
+ end
81
+ end
79
82
  end
80
- end
81
- end
data/pom.xml CHANGED
@@ -2,16 +2,16 @@
2
2
  <!--
3
3
 
4
4
 
5
- DO NOT MODIFIY - GENERATED CODE
5
+ DO NOT MODIFY - GENERATED CODE
6
6
 
7
7
 
8
8
  -->
9
- <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
9
+ <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
10
10
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
11
11
  <modelVersion>4.0.0</modelVersion>
12
12
  <groupId>propane</groupId>
13
13
  <artifactId>propane</artifactId>
14
- <version>3.4.2</version>
14
+ <version>3.8.0</version>
15
15
  <name>propane</name>
16
16
  <description>An integrated processing-core (somewhat hacked), with additional java code for a jruby version of processing.</description>
17
17
  <url>https://github.com/monkstone/propane</url>
@@ -74,7 +74,7 @@ DO NOT MODIFIY - GENERATED CODE
74
74
  <dependency>
75
75
  <groupId>org.jruby</groupId>
76
76
  <artifactId>jruby</artifactId>
77
- <version>9.2.9.0</version>
77
+ <version>9.2.16.0</version>
78
78
  <type>pom</type>
79
79
  </dependency>
80
80
  <dependency>
@@ -132,7 +132,7 @@ DO NOT MODIFIY - GENERATED CODE
132
132
  </plugin>
133
133
  <plugin>
134
134
  <artifactId>maven-javadoc-plugin</artifactId>
135
- <version>3.1.1</version>
135
+ <version>3.2.0</version>
136
136
  <configuration>
137
137
  <detectOfflineLinks>false</detectOfflineLinks>
138
138
  <links>
@@ -143,11 +143,11 @@ DO NOT MODIFIY - GENERATED CODE
143
143
  </plugin>
144
144
  <plugin>
145
145
  <artifactId>maven-jar-plugin</artifactId>
146
- <version>3.1.2</version>
146
+ <version>3.2.0</version>
147
147
  <configuration>
148
148
  <archive>
149
149
  <manifestEntries>
150
- <Class-Path>gluegen-rt.jar jog-all.jar</Class-Path>
150
+ <Automatic-Module-Name>processing.core</Automatic-Module-Name>
151
151
  </manifestEntries>
152
152
  </archive>
153
153
  </configuration>
data/propane.gemspec CHANGED
@@ -1,5 +1,6 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'propane/version'
5
6
 
@@ -8,27 +9,30 @@ Gem::Specification.new do |gem|
8
9
  gem.version = Propane::VERSION
9
10
  gem.authors = ['monkstone']
10
11
  gem.email = ['mamba2928@yahoo.co.uk']
11
- gem.licenses = %w(GPL-3.0 LGPL-2.0)
12
+ gem.licenses = %w[GPL-3.0 LGPL-2.0]
12
13
  gem.description = <<-EOS
13
14
  A batteries included version of processing in ruby targetting jdk11.
14
15
  EOS
15
- gem.summary = %q{ruby implementation of processing-4.0 on MacOS, linux and windows (64bit only)}
16
+ gem.summary = 'ruby implementation of processing-4.0 on MacOS, linux and windows (64bit only)'
16
17
  gem.homepage = 'https://ruby-processing.github.io/propane/'
17
- gem.files = `git ls-files`.split($/)
18
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
19
  gem.files << "lib/propane-#{Propane::VERSION}.jar"
19
20
  gem.files << 'lib/gluegen-rt.jar'
20
21
  gem.files << 'lib/jogl-all.jar'
21
22
  gem.files << 'lib/gluegen-rt-natives-linux-amd64.jar'
22
23
  gem.files << 'lib/gluegen-rt-natives-macosx-universal.jar'
24
+ # gem.files << 'lib/gluegen-rt-natives-ios-arm64.jar'
23
25
  gem.files << 'lib/gluegen-rt-natives-windows-amd64.jar'
24
26
  gem.files << 'lib/jogl-all-natives-linux-amd64.jar'
25
27
  gem.files << 'lib/jogl-all-natives-macosx-universal.jar'
28
+ # gem.files << 'lib/jogl-all-natives-ios-arm64.jar'
26
29
  gem.files << 'lib/jogl-all-natives-windows-amd64.jar'
27
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
30
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
28
31
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
29
- gem.add_development_dependency 'rake', '~> 12.3'
30
- gem.add_development_dependency 'minitest', '~> 5.11'
31
- gem.add_runtime_dependency 'arcball', '~> 1.0', '>= 1.0.0'
32
+ gem.add_development_dependency 'jruby-openssl', '~> 0.1.0', '>=0.1.3'
33
+ gem.add_development_dependency 'minitest', '~> 5.14'
34
+ gem.add_runtime_dependency 'rake', '~> 12.3'
35
+ gem.add_runtime_dependency 'arcball', '~> 1.0', '>= 1.0.2'
32
36
  gem.require_paths = ['lib']
33
37
  gem.platform = 'java'
34
38
  gem.requirements << 'java runtime >= 11.0.2+'
@@ -19,9 +19,8 @@
19
19
  */
20
20
  package japplemenubar;
21
21
 
22
- import java.io.File;
23
- import java.io.IOException;
24
- import java.io.InputStream;
22
+ import java.io.*;
23
+
25
24
  import processing.core.PApplet;
26
25
 
27
26
 
@@ -59,6 +58,7 @@ public class JAppleMenuBar {
59
58
  }
60
59
  } catch (IOException e) {
61
60
  sadness("Unknown error, here's the stack trace.");
61
+ e.printStackTrace();
62
62
  }
63
63
  }
64
64
 
@@ -3,7 +3,7 @@
3
3
  * in their sketches. Includes a method to efficiently convert an array of web
4
4
  * strings to an array of color int, and another to convert an array of color
5
5
  * int to a string that can be used in ruby code (to generate web color array).
6
- * Copyright (c) 2015-19 Martin Prout.
6
+ * Copyright (c) 2015-20 Martin Prout.
7
7
  * This utility is free software; you can redistribute it and/or modify
8
8
  * it under the terms of the GNU Lesser General Public License as published by
9
9
  * the Free Software Foundation; either version 2.1 of the License, or (at
@@ -13,8 +13,6 @@
13
13
  */
14
14
  package monkstone;
15
15
 
16
- import java.util.ArrayList;
17
- import java.util.List;
18
16
  import java.util.Random;
19
17
  /**
20
18
  *
@@ -2,7 +2,7 @@
2
2
  * The purpose of this tool is to allow JRubyArt users to use an alternative
3
3
  * to processing.org map, lerp and norm methods in their sketches and to implement
4
4
  * JRubyArt convenenience method grid(width, height, stepW, stepH) { |x, y| do stuff }
5
- * Copyright (c) 2015-19 Martin Prout. This tool is free software; you can
5
+ * Copyright (c) 2015-20 Martin Prout. This tool is free software; you can
6
6
  * redistribute it and/or modify it under the terms of the GNU Lesser General
7
7
  * Public License as published by the Free Software Foundation; either version
8
8
  * 2.1 of the License, or (at your option) any later version.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The purpose of this class is to load the MathTool into ruby-processing runtime
3
- * Copyright (C) 2015-19 Martin Prout. This code is free software; you can
3
+ * Copyright (C) 2015-20 Martin Prout. This code is free software; you can
4
4
  * redistribute it and/or modify it under the terms of the GNU Lesser General
5
5
  * Public License as published by the Free Software Foundation; either version
6
6
  * 2.1 of the License, or (at your option) any later version.
@@ -41,6 +41,6 @@ public class PropaneLibrary implements Library {
41
41
  */
42
42
  @Override
43
43
  public void load(final Ruby runtime, boolean wrap) throws IOException {
44
- load(runtime);
44
+ PropaneLibrary.load(runtime);
45
45
  }
46
46
  }
@@ -0,0 +1,111 @@
1
+ /*
2
+ * Copyright (c) 2021 Martin Prout
3
+ *
4
+ * This library is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU Lesser General Public
6
+ * License as published by the Free Software Foundation; either
7
+ * version 2.1 of the License, or (at your option) any later version.
8
+ *
9
+ * http://creativecommons.org/licenses/LGPL/2.1/
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+ package monkstone.fastmath;
21
+
22
+ public final class DegLutTables {
23
+
24
+ /**
25
+ *
26
+ */
27
+ static public final float PI = 3.1415927f;
28
+
29
+ /**
30
+ *
31
+ */
32
+ static public final float PI2 = PI * 2;
33
+ static private final int SIN_BITS = 15; // 16KB. Adjust for accuracy.
34
+ static private final int SIN_MASK = ~(-1 << SIN_BITS);
35
+ static private final int SIN_COUNT = SIN_MASK + 1;
36
+
37
+ static private final float RAD_FULL = PI * 2;
38
+ static private final float DEG_FULL = 360;
39
+ static private final float RAD_TO_INDEX = SIN_COUNT / RAD_FULL;
40
+ static private final float DEG_TO_INDEX = SIN_COUNT / DEG_FULL;
41
+
42
+ /**
43
+ * multiply by this to convert from radians to degrees
44
+ */
45
+ static public final float RADIANS_TO_DEGREES = 180f / PI;
46
+
47
+ /**
48
+ *
49
+ */
50
+ static public final float RAD_DEG = RADIANS_TO_DEGREES;
51
+ /**
52
+ * multiply by this to convert from degrees to radians
53
+ */
54
+ static public final float DEGREES_TO_RADIANS = PI / 180;
55
+
56
+ /**
57
+ *
58
+ */
59
+ static public final float DEG_RAD = DEGREES_TO_RADIANS;
60
+
61
+ static private class Sin {
62
+
63
+ static final float[] table = new float[SIN_COUNT];
64
+
65
+ static {
66
+ for (int i = 0; i < SIN_COUNT; i++) {
67
+ table[i] = (float) Math.sin((i + 0.5f) / SIN_COUNT * RAD_FULL);
68
+ }
69
+ for (int i = 0; i < 360; i += 90) {
70
+ table[(int) (i * DEG_TO_INDEX) & SIN_MASK] = (float) Math.sin(i * DEGREES_TO_RADIANS);
71
+ }
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Returns the sine in radians from a lookup table.
77
+ * @param radians
78
+ * @return
79
+ */
80
+ static public final float sin(float radians) {
81
+ return Sin.table[(int) (radians * RAD_TO_INDEX) & SIN_MASK];
82
+ }
83
+
84
+ /**
85
+ * Returns the cosine in radians from a lookup table.
86
+ * @param radians
87
+ * @return
88
+ */
89
+ static public final float cos(float radians) {
90
+ return Sin.table[(int) ((radians + PI / 2) * RAD_TO_INDEX) & SIN_MASK];
91
+ }
92
+
93
+ /**
94
+ * Returns the sine in radians from a lookup table.
95
+ * @param degrees
96
+ * @return
97
+ */
98
+ static public final float sinDeg(float degrees) {
99
+ return Sin.table[(int) (degrees * DEG_TO_INDEX) & SIN_MASK];
100
+ }
101
+
102
+ /**
103
+ * Returns the cosine in radians from a lookup table.
104
+ * @param degrees
105
+ * @return
106
+ */
107
+ static public final float cosDeg(float degrees) {
108
+ return Sin.table[(int) ((degrees + 90) * DEG_TO_INDEX) & SIN_MASK];
109
+ }
110
+ }
111
+
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2015-19 Martin Prout
2
+ * Copyright (c) 2015-21 Martin Prout
3
3
  *
4
4
  * This library is free software; you can redistribute it and/or
5
5
  * modify it under the terms of the GNU Lesser General Public
@@ -20,7 +20,7 @@
20
20
  package monkstone.fastmath;
21
21
 
22
22
  import org.jruby.Ruby;
23
- import org.jruby.RubyInteger;
23
+ import org.jruby.RubyNumeric;
24
24
  import org.jruby.RubyModule;
25
25
  import org.jruby.anno.JRubyModule;
26
26
  import org.jruby.anno.JRubyMethod;
@@ -34,38 +34,6 @@ import org.jruby.runtime.builtin.IRubyObject;
34
34
  @JRubyModule(name = "DegLut")
35
35
  public class Deglut {
36
36
 
37
- /**
38
- * Lookup table for degree cosine/sine, has a fixed precision 1.0 degrees
39
- * Quite accurate but imprecise
40
- *
41
- * @author Martin Prout <martin_p@lineone.net>
42
- */
43
- static final double[] SIN_DEG_LUT = new double[91];
44
- /**
45
- *
46
- */
47
- public static final double TO_RADIANS = Math.PI / 180;
48
- /**
49
- *
50
- */
51
- private static boolean initialized = false;
52
-
53
- private final static int NINETY = 90;
54
- private final static int FULL = 360;
55
- private static final long serialVersionUID = -1466528933765940101L;
56
-
57
- /**
58
- * Initialize sin table with values (first quadrant only)
59
- */
60
- public static final void initTable() {
61
- if (initialized == false) {
62
- for (int i = 0; i <= NINETY; i++) {
63
- SIN_DEG_LUT[i] = Math.sin(TO_RADIANS * i);
64
- }
65
- initialized = true;
66
- }
67
- }
68
-
69
37
  /**
70
38
  *
71
39
  * @param runtime Ruby
@@ -73,7 +41,6 @@ public class Deglut {
73
41
  public static void createDeglut(final Ruby runtime) {
74
42
  RubyModule deglutModule = runtime.defineModule("DegLut");
75
43
  deglutModule.defineAnnotatedMethods(Deglut.class);
76
- Deglut.initTable();
77
44
  }
78
45
 
79
46
  /**
@@ -84,18 +51,9 @@ public class Deglut {
84
51
  * @return sin IRubyObject
85
52
  */
86
53
  @JRubyMethod(name = "sin", module = true)
87
-
88
54
  public static IRubyObject sin(ThreadContext context, IRubyObject recv, IRubyObject other) {
89
- int thet = (int) ((RubyInteger) other).getLongValue();
90
- while (thet < 0) {
91
- thet += FULL; // Needed because negative modulus plays badly in java
92
- }
93
- int theta = thet % FULL;
94
- int y = theta % NINETY;
95
- double result = (theta < NINETY) ? SIN_DEG_LUT[y] : (theta < 180)
96
- ? SIN_DEG_LUT[NINETY - y] : (theta < 270)
97
- ? -SIN_DEG_LUT[y] : -SIN_DEG_LUT[NINETY - y];
98
- return context.runtime.newFloat(result);
55
+ float thet = (float) ((RubyNumeric) other).getLongValue();
56
+ return context.runtime.newFloat(DegLutTables.sinDeg(thet));
99
57
  }
100
58
 
101
59
  /**
@@ -107,15 +65,7 @@ public class Deglut {
107
65
  */
108
66
  @JRubyMethod(name = "cos", module = true)
109
67
  public static IRubyObject cos(ThreadContext context, IRubyObject recv, IRubyObject other) {
110
- int thet = (int) ((RubyInteger) other).getLongValue();
111
- while (thet < 0) {
112
- thet += FULL; // Needed because negative modulus plays badly in java
113
- }
114
- int theta = thet % FULL;
115
- int y = theta % NINETY;
116
- double result = (theta < NINETY) ? SIN_DEG_LUT[NINETY - y] : (theta < 180)
117
- ? -SIN_DEG_LUT[y] : (theta < 270)
118
- ? -SIN_DEG_LUT[NINETY - y] : SIN_DEG_LUT[y];
119
- return context.runtime.newFloat(result);
68
+ float thet = (float) ((RubyNumeric) other).getLongValue();
69
+ return context.runtime.newFloat(DegLutTables.cosDeg(thet));
120
70
  }
121
71
  }