quaternion_c2 0.9.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +29 -0
- data/lib/quaternion_c2/arithmetic.rb +2 -1
- data/lib/quaternion_c2/comparison.rb +55 -0
- data/lib/quaternion_c2/equality.rb +0 -1
- data/lib/quaternion_c2.rb +1 -0
- data/quaternion_c2.gemspec +4 -1
- metadata +23 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d786fc0057f8807e1a12a9c55c19e124fa7edd24eccf3d686c1a927685c01bc
|
4
|
+
data.tar.gz: a98e2aaed384903bff5a13b844b5097b88f360a1ed8a182b2a1a774b45e46d8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45c7c781395f45cb8a0adc3acb2e2a6c0c6f7d58e03a14da74490080048146aee760a5835eb524f1c02a4dce77d3bfbc2f008aa88b89754394d57900c34eaca8
|
7
|
+
data.tar.gz: 3afc20e3e7b5fe2874343ade34e6550f862a1f21cb097ff3b403465f63b4364d1dc050748219fdac26b0328310eb995dd1fbf38598cd4d76cc12e5fb346ce92f
|
@@ -0,0 +1,29 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push: {}
|
5
|
+
pull_request: {}
|
6
|
+
schedule:
|
7
|
+
- cron: '45 23 1 * *' # Monthly check
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
unit-test:
|
11
|
+
strategy:
|
12
|
+
fail-fast: false
|
13
|
+
matrix:
|
14
|
+
ruby: [ '2.1', '2.2', '2.3', '2.4', '2.5', '2.6', '2.7',
|
15
|
+
'3.0', '3.1', '3.2',
|
16
|
+
head ]
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
name: Unit test with Ruby ${{ matrix.ruby }}
|
19
|
+
steps:
|
20
|
+
- name: Checkout repository
|
21
|
+
uses: actions/checkout@v3
|
22
|
+
- name: Setup Ruby
|
23
|
+
uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby }}
|
26
|
+
bundler-cache: true
|
27
|
+
- name: Run RSpec
|
28
|
+
run: |
|
29
|
+
bundle exec rake spec
|
@@ -83,7 +83,8 @@ class Quaternion
|
|
83
83
|
[:quo, :fdiv].each do |sym|
|
84
84
|
define_method(sym) do |other|
|
85
85
|
if other.kind_of?(Quaternion)
|
86
|
-
self * other.conj.send(sym, other.abs2)
|
86
|
+
n = self * other.conj.send(sym, other.abs2)
|
87
|
+
__new__(n.a / 1, n.b / 1) # Canonicalize rationals as Complex does
|
87
88
|
elsif other.kind_of?(Numeric) && other.complex?
|
88
89
|
__new__(@a.send(sym, other), @b.send(sym, other.conj))
|
89
90
|
else
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
require_relative 'arithmetic' # define Quaternion#coerce
|
3
|
+
|
4
|
+
if Complex.public_method_defined?(:<=>)
|
5
|
+
class Quaternion
|
6
|
+
##
|
7
|
+
# Compare values if both are real numbers.
|
8
|
+
#
|
9
|
+
# @param other [Object]
|
10
|
+
# @return [-1, 0, 1, or nil]
|
11
|
+
#
|
12
|
+
def <=>(other)
|
13
|
+
if other.kind_of?(Quaternion)
|
14
|
+
(@b == 0 && other.b == 0) ? (@a <=> other.a) : nil
|
15
|
+
elsif other.kind_of?(Numeric) && other.complex?
|
16
|
+
(@b == 0) ? (@a <=> other) : nil
|
17
|
+
elsif other.respond_to?(:coerce)
|
18
|
+
n1, n2 = other.coerce(self)
|
19
|
+
n1 <=> n2
|
20
|
+
else
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Check whether built-in Complex#<=> uses type coercions.
|
27
|
+
if (Complex.rect(0, 0) <=> Quaternion.send(:new, 0, 0)).nil?
|
28
|
+
warn "Redefine Complex#<=> to allow type coercions."
|
29
|
+
|
30
|
+
class Complex
|
31
|
+
##
|
32
|
+
# Compare values if both are real numbers.
|
33
|
+
#
|
34
|
+
# @param other [Object]
|
35
|
+
# @return [-1, 0, 1, or nil]
|
36
|
+
#
|
37
|
+
def <=>(other)
|
38
|
+
if other.kind_of?(Complex)
|
39
|
+
(imag == 0 && other.imag == 0) ? (real <=> other.real) : nil
|
40
|
+
elsif other.kind_of?(Numeric) && other.real?
|
41
|
+
(imag == 0) ? (real <=> other) : nil
|
42
|
+
elsif other.respond_to?(:coerce)
|
43
|
+
n1, n2 = other.coerce(self)
|
44
|
+
n1 <=> n2
|
45
|
+
else
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
else
|
52
|
+
class Quaternion
|
53
|
+
undef <=>
|
54
|
+
end
|
55
|
+
end
|
data/lib/quaternion_c2.rb
CHANGED
data/quaternion_c2.gemspec
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = "quaternion_c2"
|
6
|
-
spec.version = "0.
|
6
|
+
spec.version = "1.0.0"
|
7
7
|
spec.authors = ["Masahiro Nomoto"]
|
8
8
|
spec.email = ["hmmnrst@users.noreply.github.com"]
|
9
9
|
|
@@ -11,6 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.description = %q{Provides a numeric class Quaternion which is similar to a built-in class Complex.}
|
12
12
|
spec.homepage = "https://github.com/hmmnrst/quaternion_c2"
|
13
13
|
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = ">= 2.1" # matrix:0.1.0 does not support ruby 2.0
|
14
15
|
|
15
16
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
17
|
f.match(%r{^(test|spec|features)/})
|
@@ -19,6 +20,8 @@ Gem::Specification.new do |spec|
|
|
19
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
21
|
spec.require_paths = ["lib"]
|
21
22
|
|
23
|
+
spec.add_dependency "matrix" # Vector
|
24
|
+
|
22
25
|
spec.add_development_dependency "bundler"
|
23
26
|
spec.add_development_dependency "rake"
|
24
27
|
spec.add_development_dependency "rspec", "~> 3.0"
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quaternion_c2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masahiro Nomoto
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: matrix
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,6 +74,7 @@ executables: []
|
|
60
74
|
extensions: []
|
61
75
|
extra_rdoc_files: []
|
62
76
|
files:
|
77
|
+
- ".github/workflows/test.yml"
|
63
78
|
- ".gitignore"
|
64
79
|
- ".rspec"
|
65
80
|
- ".travis.yml"
|
@@ -74,6 +89,7 @@ files:
|
|
74
89
|
- lib/quaternion_c2/attributes.rb
|
75
90
|
- lib/quaternion_c2/base.rb
|
76
91
|
- lib/quaternion_c2/classification.rb
|
92
|
+
- lib/quaternion_c2/comparison.rb
|
77
93
|
- lib/quaternion_c2/conversion.rb
|
78
94
|
- lib/quaternion_c2/equality.rb
|
79
95
|
- lib/quaternion_c2/to_type.rb
|
@@ -85,7 +101,7 @@ homepage: https://github.com/hmmnrst/quaternion_c2
|
|
85
101
|
licenses:
|
86
102
|
- MIT
|
87
103
|
metadata: {}
|
88
|
-
post_install_message:
|
104
|
+
post_install_message:
|
89
105
|
rdoc_options: []
|
90
106
|
require_paths:
|
91
107
|
- lib
|
@@ -93,16 +109,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
109
|
requirements:
|
94
110
|
- - ">="
|
95
111
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
112
|
+
version: '2.1'
|
97
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
114
|
requirements:
|
99
115
|
- - ">="
|
100
116
|
- !ruby/object:Gem::Version
|
101
117
|
version: '0'
|
102
118
|
requirements: []
|
103
|
-
|
104
|
-
|
105
|
-
signing_key:
|
119
|
+
rubygems_version: 3.3.7
|
120
|
+
signing_key:
|
106
121
|
specification_version: 4
|
107
122
|
summary: Quaternion class
|
108
123
|
test_files: []
|