picrate 2.0.1-java → 2.3.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -1
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +1 -1
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -2
  5. data/CHANGELOG.md +10 -0
  6. data/README.md +6 -3
  7. data/Rakefile +2 -1
  8. data/docs/_includes/footer.html +1 -1
  9. data/docs/_layouts/post.html +1 -1
  10. data/docs/_methods/alternative_methods.md +2 -1
  11. data/docs/_methods/noise_mode.md +88 -0
  12. data/docs/_posts/2018-05-06-install_jruby.md +3 -3
  13. data/docs/_posts/2018-11-18-building-gem.md +3 -1
  14. data/docs/_posts/2020-03-09-auto_install_picrate.md +2 -3
  15. data/docs/_posts/2020-05-11-getting_started_manjaro.md +20 -8
  16. data/docs/classes.md +2 -2
  17. data/docs/editors.md +2 -2
  18. data/docs/gems.md +3 -3
  19. data/docs/index.html +1 -1
  20. data/docs/libraries.md +2 -2
  21. data/docs/live.md +2 -2
  22. data/docs/magic.md +2 -2
  23. data/docs/methods.md +2 -2
  24. data/docs/modules.md +3 -3
  25. data/docs/objects.md +2 -2
  26. data/lib/picrate.rb +2 -1
  27. data/lib/picrate/app.rb +7 -2
  28. data/lib/picrate/helper_methods.rb +1 -1
  29. data/lib/picrate/native_folder.rb +1 -3
  30. data/lib/picrate/runner.rb +4 -4
  31. data/lib/picrate/version.rb +1 -1
  32. data/library/jcomplex/jcomplex.rb +1 -0
  33. data/library/pdf/pdf.rb +6 -0
  34. data/mvnw +2 -2
  35. data/mvnw.cmd +2 -2
  36. data/picrate.gemspec +3 -2
  37. data/pom.rb +22 -8
  38. data/pom.xml +27 -5
  39. data/src/main/java/monkstone/PicrateLibrary.java +1 -1
  40. data/src/main/java/monkstone/complex/JComplex.java +252 -0
  41. data/src/main/java/monkstone/fastmath/DegLutTables.java +111 -0
  42. data/src/main/java/monkstone/fastmath/Deglut.java +41 -93
  43. data/src/main/java/monkstone/noise/FastTerrain.java +874 -0
  44. data/src/main/java/monkstone/noise/Noise.java +90 -0
  45. data/src/main/java/monkstone/noise/NoiseGenerator.java +75 -0
  46. data/src/main/java/monkstone/noise/NoiseMode.java +28 -0
  47. data/src/main/java/monkstone/noise/OpenSimplex2F.java +881 -0
  48. data/src/main/java/monkstone/noise/OpenSimplex2S.java +1106 -0
  49. data/src/main/java/monkstone/noise/SmoothTerrain.java +1099 -0
  50. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  51. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
  52. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  53. data/src/main/java/processing/awt/PGraphicsJava2D.java +22 -23
  54. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  55. data/src/main/java/processing/awt/ShimAWT.java +711 -0
  56. data/src/main/java/processing/core/PApplet.java +14880 -14101
  57. data/src/main/java/processing/core/PConstants.java +5 -5
  58. data/src/main/java/processing/core/PFont.java +1 -1
  59. data/src/main/java/processing/core/PGraphics.java +284 -271
  60. data/src/main/java/processing/core/PImage.java +1620 -1815
  61. data/src/main/java/processing/core/PShape.java +18 -18
  62. data/src/main/java/processing/core/PSurface.java +105 -139
  63. data/src/main/java/processing/core/PSurfaceNone.java +29 -0
  64. data/src/main/java/processing/core/PVector.java +23 -23
  65. data/src/main/java/processing/data/Table.java +4 -4
  66. data/src/main/java/processing/net/Client.java +13 -13
  67. data/src/main/java/processing/net/Server.java +5 -5
  68. data/src/main/java/processing/opengl/PGL.java +649 -3699
  69. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +2503 -2278
  70. data/src/main/java/processing/opengl/PJOGL.java +374 -1526
  71. data/src/main/java/processing/opengl/PSurfaceJOGL.java +220 -86
  72. data/src/main/java/processing/pdf/PGraphicsPDF.java +607 -0
  73. data/test/deglut_spec_test.rb +2 -2
  74. data/test/respond_to_test.rb +0 -1
  75. data/vendors/Rakefile +33 -21
  76. data/vendors/{picrate_sketches.geany → geany.rb} +32 -7
  77. metadata +24 -9
  78. data/src/main/java/monkstone/noise/SimplexNoise.java +0 -465
data/lib/picrate.rb CHANGED
@@ -9,4 +9,5 @@ end
9
9
  Dir["#{PICRATE_ROOT}/lib/*.jar"].sort.each do |jar|
10
10
  require jar
11
11
  end
12
- require_relative 'picrate/app'
12
+ require "#{PICRATE_ROOT}/lib/picrate/app"
13
+ require "#{PICRATE_ROOT}/lib/picrate/helpers/numeric"
data/lib/picrate/app.rb CHANGED
@@ -5,7 +5,7 @@ require_relative 'helper_methods'
5
5
  require_relative 'library_loader'
6
6
  # A wrapper module for the processing App
7
7
  module Processing
8
- include_package 'processing.core' # imports the processing jar.
8
+ include_package 'processing.core' # imports the processing classes.
9
9
  # Load vecmath, fastmath and mathtool modules
10
10
  Java::Monkstone::PicrateLibrary.load(JRuby.runtime)
11
11
  SKETCH_ROOT = File.absolute_path('.')
@@ -16,6 +16,10 @@ module Processing
16
16
  java_import 'monkstone.vecmath.ShapeRender'
17
17
  end
18
18
 
19
+ module NoiseModule
20
+ java_import 'monkstone.noise.NoiseMode'
21
+ end
22
+
19
23
  # This class is the base class the user should inherit from when making
20
24
  # their own sketch.
21
25
  #
@@ -55,6 +59,7 @@ module Processing
55
59
  include HelperMethods
56
60
  include MathTool
57
61
  include Math
62
+ include NoiseModule
58
63
  # Alias some methods for familiarity for Shoes coders.
59
64
  alias oval ellipse
60
65
  alias stroke_width stroke_weight
@@ -144,7 +149,7 @@ module Processing
144
149
  def data_path(dat)
145
150
  dat_root = File.join(SKETCH_ROOT, 'data')
146
151
  Dir.mkdir(dat_root) unless File.exist?(dat_root)
147
- File.join(dat_root, dat)
152
+ File.join(dat_root, dat).to_java(:string)
148
153
  end
149
154
 
150
155
  private
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: false
2
2
 
3
3
  # processing module wrapper
4
- require_relative 'helpers/numeric'
4
+
5
5
  module Processing
6
6
  # Provides some convenience methods
7
7
  module HelperMethods
@@ -1,5 +1,3 @@
1
- require 'rbconfig'
2
-
3
1
  # Utility to load native binaries on Java CLASSPATH
4
2
  #HACK until jruby returns a more specific 'host_os' than 'linux'
5
3
  class NativeFolder
@@ -10,7 +8,7 @@ class NativeFolder
10
8
  ARM64 = '-aarch64'.freeze
11
9
 
12
10
  def initialize
13
- @os = RbConfig::CONFIG['host_os'].downcase
11
+ @os = java.lang.System.get_property('os.name')
14
12
  @bit = java.lang.System.get_property('os.arch')
15
13
  end
16
14
 
@@ -32,7 +32,7 @@ module Processing
32
32
  opt_parser = OptionParser.new do |opts|
33
33
  # Set a banner, displayed at the top
34
34
  # of the help screen.
35
- opts.banner = 'Usage: picrate [options] [<sketch.rb>]'
35
+ opts.banner = 'Usage: picrate [options] [<name>]'
36
36
 
37
37
  # Define the options, and what they do
38
38
  options[:version] = false
@@ -55,6 +55,8 @@ module Processing
55
55
  # assumed to have this option.
56
56
  opts.on_tail('-h', '--help', 'Display this screen') do
57
57
  puts opts
58
+ puts ''
59
+ puts 'Run a sketch: jruby [--dev] [<sketch.rb>]'
58
60
  exit
59
61
  end
60
62
  end
@@ -81,9 +83,7 @@ module Processing
81
83
  library ||= 'new'
82
84
  choice = library.downcase
83
85
  case choice
84
- when /sound/
85
- warn 'The sound library is broken, try minim instead'
86
- when /samples|video/
86
+ when /samples|sound|video/
87
87
  system "cd #{PICRATE_ROOT}/vendors && rake install_#{choice}"
88
88
  when /new/
89
89
  # install samples and config geany
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PiCrate
4
- VERSION = '2.0.1'
4
+ VERSION = '2.3.0'
5
5
  end
@@ -0,0 +1 @@
1
+ java_import Java::MonkstoneComplex::JComplex
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @TODO usage
4
+ class Processing::App
5
+ java_import Java::ProcessingPdf::PGraphicsPDF
6
+ end
data/mvnw CHANGED
@@ -212,9 +212,9 @@ else
212
212
  echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
213
213
  fi
214
214
  if [ -n "$MVNW_REPOURL" ]; then
215
- jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
215
+ jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
216
216
  else
217
- jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
217
+ jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
218
218
  fi
219
219
  while IFS="=" read key value; do
220
220
  case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
data/mvnw.cmd CHANGED
@@ -120,7 +120,7 @@ SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
120
120
  set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
121
121
  set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
122
122
 
123
- set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
123
+ set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
124
124
 
125
125
  FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
126
126
  IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
@@ -134,7 +134,7 @@ if exist %WRAPPER_JAR% (
134
134
  )
135
135
  ) else (
136
136
  if not "%MVNW_REPOURL%" == "" (
137
- SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
137
+ SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
138
138
  )
139
139
  if "%MVNW_VERBOSE%" == "true" (
140
140
  echo Couldn't find %WRAPPER_JAR%, downloading it ...
data/picrate.gemspec CHANGED
@@ -27,12 +27,13 @@ Gem::Specification.new do |gem|
27
27
  gem.files << 'lib/jogl-all-natives-linux-amd64.jar'
28
28
  gem.files << 'lib/jogl-all-natives-linux-armv6hf.jar'
29
29
  gem.files << 'lib/jogl-all-natives-linux-aarch64.jar'
30
+ gem.files << 'lib/itextpdf-5.5.13.2.jar'
30
31
  gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
31
32
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
32
33
  gem.add_development_dependency 'minitest', '~> 5.10'
33
- gem.add_development_dependency 'rake', '~> 12.3'
34
+ gem.add_runtime_dependency 'rake', '~> 13.0'
34
35
  gem.add_runtime_dependency 'arcball', '~> 1.0', '>= 1.0.1'
35
36
  gem.require_paths = ['lib']
36
37
  gem.platform = 'java'
37
- gem.requirements << 'java runtime == 11'
38
+ gem.requirements << 'java runtime == 11+'
38
39
  end
data/pom.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  project 'picrate', 'http://maven.apache.org' do
4
4
  model_version '4.0.0'
5
- id 'ruby-processing:picrate:2.0.1'
5
+ id 'ruby-processing:picrate:2.3.0'
6
6
  packaging 'jar'
7
7
 
8
8
  description 'An integrated processing-core (somewhat hacked), with additional java code for a jruby version of processing.'
@@ -24,6 +24,7 @@ project 'picrate', 'http://maven.apache.org' do
24
24
  issue_management 'https://github.com/ruby-processing/PiCrate/issues', 'Github'
25
25
  # Need to update to jogl 2.4.1 as soon as available, then make a dependency
26
26
  properties('jogl.version' => '2.3.2',
27
+ 'itextpdf.version' => '5.5.13.2',
27
28
  'jruby.api' => 'http://jruby.org/apidocs/',
28
29
  'source.directory' => 'src',
29
30
  'processing.api' => 'http://processing.github.io/processing-javadocs/core/',
@@ -31,15 +32,27 @@ project 'picrate', 'http://maven.apache.org' do
31
32
  'project.build.sourceEncoding' => 'utf-8',
32
33
  'polyglot.dump.pom' => 'pom.xml')
33
34
 
34
- pom 'org.jruby:jruby:9.2.11.0'
35
+ pom 'org.jruby:jruby:9.2.16.0'
35
36
  jar 'org.jogamp.jogl:jogl-all:${jogl.version}'
36
37
  jar 'org.jogamp.gluegen:gluegen-rt-main:${jogl.version}'
37
38
  jar 'org.processing:video:3.0.2'
39
+ jar 'com.itextpdf:itextpdf:${itextpdf.version}'
38
40
  end
39
41
 
40
42
  overrides do
41
43
  plugin :resources, '3.1.0'
42
- plugin :dependency, '3.1.2'
44
+ plugin :dependency, '3.1.2' do
45
+ execute_goals( id: 'default-cli',
46
+ artifactItems:[
47
+ { groupId: 'com.itextpdf',
48
+ artifactId: 'itextpdf',
49
+ version: '${itextpdf.version}',
50
+ type: 'jar',
51
+ outputDirectory: '${picrate.basedir}/lib'
52
+ }
53
+ ]
54
+ )
55
+ end
43
56
  plugin(:compiler, '3.8.1',
44
57
  'release' => '11')
45
58
  plugin(:javadoc, '2.10.4',
@@ -47,11 +60,12 @@ overrides do
47
60
  'links' => ['${processing.api}',
48
61
  '${jruby.api}'])
49
62
  plugin(:jar, '3.2.0',
50
- 'archive' => {
51
- 'manifestEntries' => {
52
- 'Class-Path' => 'gluegen-rt.jar jog-all.jar'
53
- }
54
- })
63
+ 'archive' => {
64
+ 'manifestEntries' => {
65
+ 'Automatic-Module-Name' => 'processing.core'
66
+ }
67
+ }
68
+ )
55
69
  plugin :jdeps, '3.1.2' do
56
70
  execute_goals 'jdkinternals', 'test-jdkinternals'
57
71
  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>ruby-processing</groupId>
13
13
  <artifactId>picrate</artifactId>
14
- <version>2.0.1</version>
14
+ <version>2.3.0</version>
15
15
  <name>picrate</name>
16
16
  <description>An integrated processing-core (somewhat hacked), with additional java code for a jruby version of processing.</description>
17
17
  <url>http://maven.apache.org</url>
@@ -64,6 +64,7 @@ DO NOT MODIFIY - GENERATED CODE
64
64
  <url>https://github.com/ruby-processing/PiCrate/issues</url>
65
65
  </issueManagement>
66
66
  <properties>
67
+ <itextpdf.version>5.5.13.2</itextpdf.version>
67
68
  <jogl.version>2.3.2</jogl.version>
68
69
  <jruby.api>http://jruby.org/apidocs/</jruby.api>
69
70
  <picrate.basedir>${project.basedir}</picrate.basedir>
@@ -76,7 +77,7 @@ DO NOT MODIFIY - GENERATED CODE
76
77
  <dependency>
77
78
  <groupId>org.jruby</groupId>
78
79
  <artifactId>jruby</artifactId>
79
- <version>9.2.11.0</version>
80
+ <version>9.2.16.0</version>
80
81
  <type>pom</type>
81
82
  </dependency>
82
83
  <dependency>
@@ -94,6 +95,11 @@ DO NOT MODIFIY - GENERATED CODE
94
95
  <artifactId>video</artifactId>
95
96
  <version>3.0.2</version>
96
97
  </dependency>
98
+ <dependency>
99
+ <groupId>com.itextpdf</groupId>
100
+ <artifactId>itextpdf</artifactId>
101
+ <version>${itextpdf.version}</version>
102
+ </dependency>
97
103
  </dependencies>
98
104
  <build>
99
105
  <resources>
@@ -124,6 +130,22 @@ DO NOT MODIFIY - GENERATED CODE
124
130
  <plugin>
125
131
  <artifactId>maven-dependency-plugin</artifactId>
126
132
  <version>3.1.2</version>
133
+ <executions>
134
+ <execution>
135
+ <id>default-cli</id>
136
+ <configuration>
137
+ <artifactItems>
138
+ <artifactItem>
139
+ <groupId>com.itextpdf</groupId>
140
+ <artifactId>itextpdf</artifactId>
141
+ <version>${itextpdf.version}</version>
142
+ <type>jar</type>
143
+ <outputDirectory>${picrate.basedir}/lib</outputDirectory>
144
+ </artifactItem>
145
+ </artifactItems>
146
+ </configuration>
147
+ </execution>
148
+ </executions>
127
149
  </plugin>
128
150
  <plugin>
129
151
  <artifactId>maven-compiler-plugin</artifactId>
@@ -149,7 +171,7 @@ DO NOT MODIFIY - GENERATED CODE
149
171
  <configuration>
150
172
  <archive>
151
173
  <manifestEntries>
152
- <Class-Path>gluegen-rt.jar jog-all.jar</Class-Path>
174
+ <Automatic-Module-Name>processing.core</Automatic-Module-Name>
153
175
  </manifestEntries>
154
176
  </archive>
155
177
  </configuration>
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The purpose of this class is to load the MathTool into PiCrate runtime
3
- * Copyright (C) 2018-20 Martin Prout. This code is free software; you can
3
+ * Copyright (C) 2018-21 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.
@@ -0,0 +1,252 @@
1
+ package monkstone.complex;
2
+
3
+ import java.util.Objects;
4
+
5
+ /**
6
+ * The purpose of this class is to to make Complex operations more efficient
7
+ * than JRuby RubyComplex, by having a simpler interface, only modest
8
+ * improvements were obtained (but this is better than nothing on RaspberryPI).
9
+ */
10
+ public final class JComplex {
11
+
12
+ private final double re; // the real part
13
+ private final double im; // the imaginary part
14
+ private final static JComplex ZERO = new JComplex(0, 0);
15
+ private final static JComplex NAN = new JComplex(Double.NaN, Double.NaN);
16
+
17
+ /**
18
+ * create a new object with the given real and imaginary parts
19
+ *
20
+ * @param real
21
+ * @param imag
22
+ */
23
+ public JComplex(double real, double imag) {
24
+ re = real;
25
+ im = imag;
26
+ }
27
+
28
+ /**
29
+ * @return a string representation of the invoking Complex object
30
+ */
31
+ @Override
32
+ public String toString() {
33
+ return "JComplex(" + re + ", " + im + "i)";
34
+ }
35
+
36
+ /**
37
+ *
38
+ * @return abs/modulus/magnitude
39
+ */
40
+ public final double abs() {
41
+ return Math.hypot(re, im);
42
+ }
43
+
44
+ /**
45
+ *
46
+ * @return square of abs/modulus/magnitude
47
+ */
48
+ public final double abs2() {
49
+ return re * re + im * im;
50
+ }
51
+
52
+ /**
53
+ *
54
+ * @return angle/phase/argument, normalized to be between -pi and pi
55
+ */
56
+ public final double phase() {
57
+ return Math.atan2(im, re);
58
+ }
59
+
60
+ /**
61
+ *
62
+ * @param b
63
+ * @return a new Complex object whose value is (this + b)
64
+ */
65
+ public final JComplex add(JComplex b) {
66
+ JComplex a = this; // invoking object
67
+ double real = a.re + b.re;
68
+ double imag = a.im + b.im;
69
+ return new JComplex(real, imag);
70
+ }
71
+
72
+ /**
73
+ *
74
+ * @param scalar
75
+ * @return a new Complex object whose value is (this + scalar)
76
+ */
77
+ public final JComplex add(double scalar) {
78
+ return new JComplex(re + scalar, im);
79
+ }
80
+
81
+ public final boolean zero() {
82
+ return this.equals(ZERO);
83
+ }
84
+
85
+ /**
86
+ *
87
+ * @param b
88
+ * @return a new Complex object whose value is (this - b)
89
+ */
90
+ public final JComplex sub(JComplex b) {
91
+ JComplex a = this;
92
+ double real = a.re - b.re;
93
+ double imag = a.im - b.im;
94
+ return new JComplex(real, imag);
95
+ }
96
+
97
+ /**
98
+ *
99
+ * @param scalar
100
+ * @return a new Complex object whose value is (this - scalar)
101
+ */
102
+ public final JComplex sub(double scalar) {
103
+ return new JComplex(re - scalar, im);
104
+ }
105
+
106
+ /**
107
+ *
108
+ * @param b
109
+ * @return a new Complex object whose value is (this * b)
110
+ */
111
+ public final JComplex mul(JComplex b) {
112
+ JComplex a = this;
113
+ double real = a.re * b.re - a.im * b.im;
114
+ double imag = a.re * b.im + a.im * b.re;
115
+ return new JComplex(real, imag);
116
+ }
117
+
118
+ /**
119
+ * Also known as scale
120
+ *
121
+ * @param b
122
+ * @return a new Complex object whose value is (this * b)
123
+ */
124
+ public final JComplex mul(double b) {
125
+ return new JComplex(re * b, im * b);
126
+ }
127
+
128
+ /**
129
+ *
130
+ * @return a new Complex object whose value is the conjugate of this
131
+ */
132
+ public final JComplex conjugate() {
133
+ return new JComplex(re, -im);
134
+ }
135
+
136
+ /**
137
+ *
138
+ * @return a new Complex object whose value is the reciprocal of this
139
+ */
140
+ private JComplex reciprocal() {
141
+ double scale = re * re + im * im; // self dot product
142
+ return new JComplex(re / scale, -im / scale);
143
+ }
144
+
145
+ /**
146
+ *
147
+ * @param other
148
+ * @return this^other
149
+ */
150
+ public final JComplex pow(JComplex other) {
151
+ if (this.zero()) {
152
+ if (other.zero()) {
153
+ return ZERO;
154
+ }
155
+ return NAN;
156
+ }
157
+ return (this).log().mul(other).exp();
158
+ }
159
+
160
+ /**
161
+ *
162
+ * @param scalar
163
+ * @return this^scalar
164
+ */
165
+ public final JComplex pow(double scalar) {
166
+ if (this.zero()) {
167
+ if (scalar == 0) {
168
+ return ZERO;
169
+ }
170
+ return NAN;
171
+ }
172
+ return (this).log().mul(scalar).exp();
173
+ }
174
+
175
+ /**
176
+ *
177
+ * @return log
178
+ */
179
+ private JComplex log() {
180
+ return new JComplex(Math.log(abs()), Math.atan2(im, re));
181
+ }
182
+
183
+ /**
184
+ *
185
+ * @return real part
186
+ */
187
+ public final double re() {
188
+ return re;
189
+ }
190
+
191
+ /**
192
+ *
193
+ * @return imaginary part
194
+ */
195
+ public final double im() {
196
+ return im;
197
+ }
198
+
199
+ /**
200
+ *
201
+ * @param b
202
+ * @return a / b
203
+ */
204
+ public final JComplex div(JComplex b) {
205
+ JComplex a = this;
206
+ return a.mul(b.reciprocal());
207
+ }
208
+
209
+ /**
210
+ *
211
+ * @param b
212
+ * @return a / b
213
+ */
214
+ public final JComplex div(double b) {
215
+ if (b == 0) {
216
+ return NAN;
217
+ }
218
+ return new JComplex(re / b, im / b);
219
+ }
220
+
221
+ /**
222
+ *
223
+ * @return a new Complex object whose value is the complex exponential of
224
+ * this
225
+ */
226
+ public final JComplex exp() {
227
+ return new JComplex(Math.exp(re) * Math.cos(im), Math.exp(re) * Math.sin(im));
228
+ }
229
+
230
+ @Override
231
+ public final int hashCode() {
232
+ return Objects.hash(re, im);
233
+ }
234
+
235
+ @Override
236
+ public final boolean equals(Object obj) {
237
+ if (this == obj) {
238
+ return true;
239
+ }
240
+ if (obj == null) {
241
+ return false;
242
+ }
243
+ if (getClass() != obj.getClass()) {
244
+ return false;
245
+ }
246
+ final JComplex other = (JComplex) obj;
247
+ if (Double.doubleToLongBits(this.re) != Double.doubleToLongBits(other.re)) {
248
+ return false;
249
+ }
250
+ return Double.doubleToLongBits(this.im) == Double.doubleToLongBits(other.im);
251
+ }
252
+ }