numerix 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +5 -0
- data/.yardopts +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +66 -0
- data/Rakefile +18 -0
- data/TODO.txt +25 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ext/numerix/common.h +107 -0
- data/ext/numerix/extconf.rb +3 -0
- data/ext/numerix/matrix3x2.c +638 -0
- data/ext/numerix/matrix3x2.h +52 -0
- data/ext/numerix/matrix4x4.c +1807 -0
- data/ext/numerix/matrix4x4.h +90 -0
- data/ext/numerix/matrix_base.c +307 -0
- data/ext/numerix/matrix_base.h +70 -0
- data/ext/numerix/numerix.c +33 -0
- data/ext/numerix/numerix.h +19 -0
- data/ext/numerix/plane.c +311 -0
- data/ext/numerix/plane.h +34 -0
- data/ext/numerix/quaternion.c +712 -0
- data/ext/numerix/quaternion.h +53 -0
- data/ext/numerix/structure.c +154 -0
- data/ext/numerix/structure.h +24 -0
- data/ext/numerix/vector.c +326 -0
- data/ext/numerix/vector.h +57 -0
- data/ext/numerix/vector2.c +641 -0
- data/ext/numerix/vector2.h +64 -0
- data/ext/numerix/vector3.c +805 -0
- data/ext/numerix/vector3.h +68 -0
- data/ext/numerix/vector4.c +727 -0
- data/ext/numerix/vector4.h +63 -0
- data/ext/numerix/vector_base.c +94 -0
- data/ext/numerix/vector_base.h +30 -0
- data/extra/numerix128.png +0 -0
- data/extra/numerix24.png +0 -0
- data/extra/numerix32.png +0 -0
- data/extra/numerix320.png +0 -0
- data/extra/numerix48.png +0 -0
- data/extra/numerix96.png +0 -0
- data/lib/numerix/error.rb +36 -0
- data/lib/numerix/matrix3x2.rb +420 -0
- data/lib/numerix/matrix4x4.rb +676 -0
- data/lib/numerix/matrix_base.rb +14 -0
- data/lib/numerix/plane.rb +154 -0
- data/lib/numerix/quaternion.rb +355 -0
- data/lib/numerix/structure.rb +124 -0
- data/lib/numerix/vector.rb +13 -0
- data/lib/numerix/vector2.rb +534 -0
- data/lib/numerix/vector3.rb +572 -0
- data/lib/numerix/vector4.rb +551 -0
- data/lib/numerix/vector_base.rb +14 -0
- data/lib/numerix/version.rb +6 -0
- data/lib/numerix.rb +10 -0
- data/numerix.gemspec +30 -0
- metadata +167 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 466136197ebd04c9c5daeb6b6eafdcfebc5788e8
|
4
|
+
data.tar.gz: 9c5162a141745a2c3a0ab1cb1429c2bcf563e317
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7e69b9ab91b0787cd16bfaf2e379e0e0648e6efac52681986b80b81e58921d70f9b350274c0e18e1ea464576c407705f6d80b8421216487b7d0a1689a17b9642
|
7
|
+
data.tar.gz: 037dabaa658ae2d6a286ff1de482071afae69f915f8cb8bf5b1ff6a25aeed0fbc4824d5054a41c789a819c2e834959ba91a3a12e6e8adc6f35d9166e67bd196b
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at efreed09@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Eric Freed
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
# ![logo](./extra/numerix32.png) Numerix
|
3
|
+
|
4
|
+
Numerix is a powerful and feature-rich Ruby C-extension for working with vectors and matrices.
|
5
|
+
|
6
|
+
The vector and matrix classes that are part of Ruby's standard library are implemented purely as Ruby code, and lack anything beyond the most basic function. Numerix strives to make working with vectors more "Ruby-like", and far exceeds Ruby's built-in implementations many times over in regards to speed and performance.
|
7
|
+
|
8
|
+
Great care has been take to make the library "interop" friendly, where each class can easily be passed as a "pointer" or binary string for interop with native libraries, using Ruby's `Fiddle`, FFI, or even Ruby's legacy `Win32API`. Numerix has been built from the ground-up for Ruby, not playing middle-man between Ruby and an existing library, and is optimized specifically for it, with focus on speed and a robust collection of functionality.
|
9
|
+
|
10
|
+
This is my first publicly released C extension for Ruby, and I welcome bug reports of any kind, in addition to feature requests, and ALL constructive feedback. Please don't hesitate to report any issues [on GitHub](https://github.com/ForeverZer0/numerix/issues)!
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'numerix'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install numerix
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Numerix was based strongly off the `System.Numerics` library of Microsoft's .NET Framework (the inspiration behind the name), and contains the minimum set of functions and classes that are within it, in addition to many more.
|
31
|
+
|
32
|
+
The following base classes are implemented completeley, and all work together to form a unified experience.
|
33
|
+
|
34
|
+
* **Vector2** - A structure encapsulating two single precision floating point values (_x, y_)
|
35
|
+
* **Vector3** - A structure encapsulating three single precision floating point values (_x, y, z_)
|
36
|
+
* **Vector4** - A structure encapsulating four single precision floating point values (_x, y, z, w_)
|
37
|
+
* **Matrix3x2** - A structure encapsulating a 3x2 matrix
|
38
|
+
* **Matrix4x4** - A structure encapsulating a 4x4 matrix
|
39
|
+
* **Plane** - A structure encapsulating a 3D plane (Vector3 denoting _normal_ and a float for _distance_)
|
40
|
+
* **Quaternion** - A structure encapsulating four single precision floating point values (_x, y, z, w_)
|
41
|
+
|
42
|
+
In addition to the "core" classes, there is a basic `Vector` class that is an analog to the standard library's `Vector` class, but implemented in `C`. This class allows for arbitrary sized vectors same as its Ruby analog, but is not as optmized or feature-rich as is possible with the fixed-size vector classes.
|
43
|
+
|
44
|
+
For each method (where applicable), there is typically a standard "pure" method, and "impure" variation that alters the object's state. All of the impure methods follow the standard Ruby convention of being suffixed with a `!`.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
# Create a vector with 3 elements
|
48
|
+
vec3 = Vector3.new(5.0, 4.0, 9.0)
|
49
|
+
|
50
|
+
norm = vec3.normalize
|
51
|
+
vec3.normalize!
|
52
|
+
```
|
53
|
+
|
54
|
+
There is a host of methods available for each class, which are outlined in detail within the documentation, and excompass all that would be expected of any vector/matrix library, and additionally many "helper" functions to efficiently perform many common and less-common operations. All of these functions are implemented the "Ruby-way", following standard Ruby style and syntax.
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ForeverZer0/numerix. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
59
|
+
|
60
|
+
## License
|
61
|
+
|
62
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
63
|
+
|
64
|
+
## Code of Conduct
|
65
|
+
|
66
|
+
Everyone interacting in the Numerix project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ForeverZer0/numerix/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.libs << "lib"
|
7
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
8
|
+
end
|
9
|
+
|
10
|
+
require "rake/extensiontask"
|
11
|
+
|
12
|
+
task :build => :compile
|
13
|
+
|
14
|
+
Rake::ExtensionTask.new("numerix") do |ext|
|
15
|
+
ext.lib_dir = "lib/numerix"
|
16
|
+
end
|
17
|
+
|
18
|
+
task :default => [:clobber, :compile, :test]
|
data/TODO.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
fix equality checking (consistent)
|
4
|
+
|
5
|
+
|
6
|
+
coerce Ruby Vector, Matrix, Pointer, etc
|
7
|
+
|
8
|
+
|
9
|
+
DOCUMENTE ** function in matrix classes !!!!!!!!!!!
|
10
|
+
|
11
|
+
MOVE ** from VectorBase to individual vector classes and document
|
12
|
+
|
13
|
+
[equiv, self]
|
14
|
+
|
15
|
+
|
16
|
+
RANGE ERRORS IN MATRIX CLASS(ES)
|
17
|
+
|
18
|
+
|
19
|
+
//////////////// PLANE /////////////////////////////
|
20
|
+
// to_a, to_h
|
21
|
+
// to_vec4
|
22
|
+
// normalize, !
|
23
|
+
// dot
|
24
|
+
// dot_coord
|
25
|
+
// dot_normal
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "numerix"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
#ifndef NUMERIX_COMMON_H
|
2
|
+
#define NUMERIX_COMMON_H 1
|
3
|
+
|
4
|
+
#include "ruby.h"
|
5
|
+
|
6
|
+
#define NUMERIX_MIN(a, b) (a < b ? a : b)
|
7
|
+
#define NUMERIX_MAX(a, b) (a > b ? a : b)
|
8
|
+
#define NUMERIX_CLAMP(value, min, max) (value < min ? min : value > max ? max : value)
|
9
|
+
|
10
|
+
#define NUMERIX_TYPE_P(obj, klass) (rb_obj_is_kind_of(obj, klass) == Qtrue)
|
11
|
+
#define NUMERIX_INHERIT_P(klass, super) (rb_class_inherited_p(klass, super) == Qtrue)
|
12
|
+
|
13
|
+
#define NUMERIX_PI 3.141593f
|
14
|
+
#define NUMERIX_HALF_PI 1.570796f
|
15
|
+
|
16
|
+
#define NUM2FLT(value) ((float)rb_num2dbl(value))
|
17
|
+
#define NUMERIX_WRAP(klass, ptr) Data_Wrap_Struct(klass, NULL, RUBY_DEFAULT_FREE, ptr)
|
18
|
+
|
19
|
+
#define CLASS_NAME(obj) rb_class2name(CLASS_OF(obj))
|
20
|
+
|
21
|
+
#define FLT_EQUAL(a, b) fabsf(a - b) < FLT_EPSILON
|
22
|
+
|
23
|
+
#define PRIVATE_CLASS_METHOD(klass, methodName) rb_funcall(klass, rb_intern("private_class_method"), 1, ID2SYM(rb_intern(methodName)))
|
24
|
+
|
25
|
+
typedef struct Vector2 {
|
26
|
+
float x; /* The X component of the vector. */
|
27
|
+
float y; /* The Y component of the vector. */
|
28
|
+
} Vector2;
|
29
|
+
|
30
|
+
typedef struct Vector3 {
|
31
|
+
float x; /* The X component of the vector. */
|
32
|
+
float y; /* The Y component of the vector. */
|
33
|
+
float z; /* The Z component of the vector. */
|
34
|
+
} Vector3;
|
35
|
+
|
36
|
+
typedef struct Vector4 {
|
37
|
+
float x; /* The X component of the vector. */
|
38
|
+
float y; /* The Y component of the vector. */
|
39
|
+
float z; /* The Z component of the vector. */
|
40
|
+
float w; /* The W component of the vector. */
|
41
|
+
} Vector4;
|
42
|
+
|
43
|
+
typedef struct Quaternion {
|
44
|
+
float x; /* Specifies the X-value of the vector component of the Quaternion. */
|
45
|
+
float y; /* Specifies the Y-value of the vector component of the Quaternion. */
|
46
|
+
float z; /* Specifies the Z-value of the vector component of the Quaternion. */
|
47
|
+
float w; /* Specifies the rotation component of the Quaternion. */
|
48
|
+
} Quaternion;
|
49
|
+
|
50
|
+
typedef struct Plane {
|
51
|
+
Vector3 normal; /* The normal vector of the Plane. */
|
52
|
+
float distance; /* The distance of the Plane along its normal from the origin. */
|
53
|
+
} Plane;
|
54
|
+
|
55
|
+
typedef struct Matrix3x2 {
|
56
|
+
float m11; /* Value at row 1, column 1 of the matrix. */
|
57
|
+
float m12; /* Value at row 1, column 2 of the matrix. */
|
58
|
+
|
59
|
+
float m21; /* Value at row 2, column 1 of the matrix. */
|
60
|
+
float m22; /* Value at row 2, column 2 of the matrix. */
|
61
|
+
|
62
|
+
float m31; /* Value at row 3, column 1 of the matrix. */
|
63
|
+
float m32; /* Value at row 3, column 2 of the matrix. */
|
64
|
+
} Matrix3x2;
|
65
|
+
|
66
|
+
typedef struct Matrix4x4 {
|
67
|
+
float m11; /* Value at row 1, column 1 of the matrix. */
|
68
|
+
float m12; /* Value at row 1, column 2 of the matrix. */
|
69
|
+
float m13; /* Value at row 1, column 3 of the matrix. */
|
70
|
+
float m14; /* Value at row 1, column 4 of the matrix. */
|
71
|
+
|
72
|
+
float m21; /* Value at row 2, column 1 of the matrix. */
|
73
|
+
float m22; /* Value at row 2, column 2 of the matrix. */
|
74
|
+
float m23; /* Value at row 2, column 3 of the matrix. */
|
75
|
+
float m24; /* Value at row 2, column 4 of the matrix. */
|
76
|
+
|
77
|
+
float m31; /* Value at row 3, column 1 of the matrix. */
|
78
|
+
float m32; /* Value at row 3, column 2 of the matrix. */
|
79
|
+
float m33; /* Value at row 3, column 3 of the matrix. */
|
80
|
+
float m34; /* Value at row 3, column 4 of the matrix. */
|
81
|
+
|
82
|
+
float m41; /* Value at row 4, column 1 of the matrix. */
|
83
|
+
float m42; /* Value at row 4, column 2 of the matrix. */
|
84
|
+
float m43; /* Value at row 4, column 3 of the matrix. */
|
85
|
+
float m44; /* Value at row 4, column 4 of the matrix. */
|
86
|
+
} Matrix4x4;
|
87
|
+
|
88
|
+
typedef struct BasicVector {
|
89
|
+
int count;
|
90
|
+
float *values;
|
91
|
+
} BasicVector;
|
92
|
+
|
93
|
+
extern VALUE rb_numerix_abstract_initialize(VALUE self);
|
94
|
+
extern VALUE rb_mNumerix;
|
95
|
+
extern VALUE rb_eNumerixError;
|
96
|
+
extern VALUE rb_cNumerixStruct;
|
97
|
+
extern VALUE rb_cVectorBase;
|
98
|
+
extern VALUE rb_cMatrixBase;
|
99
|
+
extern VALUE rb_cVector2;
|
100
|
+
extern VALUE rb_cVector3;
|
101
|
+
extern VALUE rb_cVector4;
|
102
|
+
extern VALUE rb_cMatrix3x2;
|
103
|
+
extern VALUE rb_cMatrix4x4;
|
104
|
+
extern VALUE rb_cQuaternion;
|
105
|
+
extern VALUE rb_cPlane;
|
106
|
+
|
107
|
+
#endif /* NUMERIX_COMMON_H */
|