cglm 0.1.1 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 239ddc2c75a6a3939ded1179375071ae43924887a73f8c193e256e2f6e45879f
4
- data.tar.gz: 5b3f6be03330019caa0024adb0062e5a20d9e88e5b9141debb3028c39bb4f7b3
3
+ metadata.gz: 89c806f5a00ef690cfead8c0c384f4a7c0cc5c1734129a43313f952e4c96b04f
4
+ data.tar.gz: 3609604cbbee1cc090c70ed9e21cde21f77be10a20cdfd1c3964c955a53bb47a
5
5
  SHA512:
6
- metadata.gz: 76c5578265a2e6130746a46a47aa3f2749e9d7202dea356dc2f2e7708515112986d7dee9602a272f2b0d2cd32b98aceddfb4292cd3e5aaf09a7c3afade0c6c9e
7
- data.tar.gz: 730f64f9d352059b73d38d2b1da7020eae9bc3ea8b49f91514a853d7f12eb95fd00e1b5cc89320bc5a722f143930348d6c865f935e50e987cdc4b536d5d3f7fd
6
+ metadata.gz: 65337d472039a5ad4e8a613b760f6de059d5461f19ad8410a6fe6e87e218a5303de8396dad3ba7311e5c41bc9caedf0274cb633fb08d091ef7b54b092169bb45
7
+ data.tar.gz: 6fa21d54b27454acda36f4bcb73bd0f99e17707448627d9ed50071076da60b0d3c8544ab8c000379efe5c04c2cabbd5f5f5cdf2a02aeee71e5093739c48ecf79
data/Gemfile.lock CHANGED
@@ -1,25 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cglm (0.1.1)
4
+ cglm (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- docile (1.3.2)
10
- github-markup (3.0.4)
11
- json (2.3.0)
12
- minitest (5.14.0)
13
- rake (13.0.1)
14
- rake-compiler (1.1.0)
9
+ docile (1.4.0)
10
+ github-markup (4.0.0)
11
+ minitest (5.15.0)
12
+ rake (13.0.6)
13
+ rake-compiler (1.1.9)
15
14
  rake
16
- redcarpet (3.5.0)
17
- simplecov (0.17.1)
15
+ redcarpet (3.5.1)
16
+ simplecov (0.21.2)
18
17
  docile (~> 1.1)
19
- json (>= 1.8, < 3)
20
- simplecov-html (~> 0.10.0)
21
- simplecov-html (0.10.2)
22
- yard (0.9.24)
18
+ simplecov-html (~> 0.11)
19
+ simplecov_json_formatter (~> 0.1)
20
+ simplecov-html (0.12.3)
21
+ simplecov_json_formatter (0.1.4)
22
+ webrick (1.7.0)
23
+ yard (0.9.27)
24
+ webrick (~> 1.7.0)
23
25
 
24
26
  PLATFORMS
25
27
  ruby
@@ -36,4 +38,4 @@ DEPENDENCIES
36
38
  yard (~> 0.9)
37
39
 
38
40
  BUNDLED WITH
39
- 2.1.2
41
+ 2.2.3
data/ext/cglm/rb_cglm.c CHANGED
@@ -5,6 +5,7 @@ VALUE rb_cFiddle = Qnil,
5
5
  rb_mCGLM = Qnil,
6
6
  rb_cCGLMBase = Qnil,
7
7
  rb_cVectorType = Qnil,
8
+ rb_cMatrixType = Qnil,
8
9
  rb_cMat3 = Qnil,
9
10
  rb_cMat4 = Qnil,
10
11
  rb_cVec3 = Qnil,
@@ -33,9 +34,9 @@ void Init_cglm(void) {
33
34
  rb_mCGLM = rb_define_module("CGLM");
34
35
  rb_mEuler = rb_define_module_under(rb_mCGLM, "Euler");
35
36
  rb_cCGLMBase = rb_define_class_under(rb_mCGLM, "Base", rb_cObject);
36
- rb_cMat3 = rb_define_class_under(rb_mCGLM, "Mat3", rb_cCGLMBase);
37
- rb_cMat4 = rb_define_class_under(rb_mCGLM, "Mat4", rb_cCGLMBase);
38
- rb_cCGLMBase = rb_define_class_under(rb_mCGLM, "Base", rb_cObject);
37
+ rb_cMatrixType = rb_define_class_under(rb_mCGLM, "MatrixType", rb_cCGLMBase);
38
+ rb_cMat3 = rb_define_class_under(rb_mCGLM, "Mat3", rb_cMatrixType);
39
+ rb_cMat4 = rb_define_class_under(rb_mCGLM, "Mat4", rb_cMatrixType);
39
40
  rb_cVectorType = rb_define_class_under(rb_mCGLM, "VectorType", rb_cCGLMBase);
40
41
  rb_cAABB = rb_define_class_under(rb_mCGLM, "AABB", rb_cCGLMBase);
41
42
  rb_cVec3 = rb_define_class_under(rb_mCGLM, "Vec3", rb_cVectorType);
data/ext/cglm/rb_cglm.h CHANGED
@@ -97,7 +97,7 @@ static inline size_t vec3_size() { return sizeof(vec3); }
97
97
  static inline size_t vec4_size() { return sizeof(vec4); }
98
98
  static inline size_t aabb_size() { return sizeof(aabb); }
99
99
  static inline size_t mat4_size() { return sizeof(mat4); }
100
- static inline size_t mat3_size() { return sizeof(mat4); }
100
+ static inline size_t mat3_size() { return sizeof(mat3); }
101
101
  static inline size_t quat_size() { return sizeof(mat4); }
102
102
  static inline size_t plane_size() { return sizeof(plane); }
103
103
 
@@ -153,7 +153,7 @@ static inline void *VAL2ADDR(VALUE val, size_t min_size) {
153
153
  VALUE addr = rb_funcall(val, rb_intern("addr"), 0);
154
154
  VALUE size = rb_funcall(addr, rb_intern("size"), 0);
155
155
  if (min_size > NUM2SIZET(size))
156
- rb_raise(rb_eArgError, "memory store (size %zu) is not large enough to be converted into the requested type (size %zu)", NUM2SIZET(size), min_size);
156
+ rb_raise(rb_eArgError, "memory store (size %zu) is not large enough to be converted into the requested type (size %zu)", (size_t) NUM2SIZET(size), min_size);
157
157
  return NUM2PTR(rb_funcall(addr, rb_intern("to_i"), 0));
158
158
  }
159
159
 
@@ -130,22 +130,30 @@ VALUE rb_cglm_translate_z_self(VALUE self, VALUE flt) {
130
130
  }
131
131
 
132
132
  /* call-seq: translate(vec3) => new Mat4 */
133
- VALUE rb_cglm_translate_new(VALUE klass, VALUE vec_v) {
134
- VALUE dest = MAT4_NEW(ALLOC_MAT4);
133
+ VALUE rb_cglm_translate_new(int argc, VALUE *argv, VALUE klass) {
134
+ VALUE vec_v, dest;
135
+ rb_scan_args(argc, argv, "11", &vec_v, &dest);
136
+ if (NIL_P(dest)) dest = MAT4_NEW(ALLOC_MAT4);
135
137
  glm_translate_make(VAL2MAT4(dest), VAL2VEC3(vec_v));
136
138
  return dest;
137
139
  }
138
140
 
139
141
  /* call-seq: scale(vec3) => new Mat4 */
140
- VALUE rb_cglm_scale_new(VALUE klass, VALUE vec_v) {
141
- VALUE dest = MAT4_NEW(ALLOC_MAT4);
142
+ VALUE rb_cglm_scale_new(int argc, VALUE *argv, VALUE klass) {
143
+ VALUE vec_v, dest;
144
+ rb_scan_args(argc, argv, "11", &vec_v, &dest);
145
+ if (NIL_P(dest)) dest = MAT4_NEW(ALLOC_MAT4);
142
146
  glm_scale_make(VAL2MAT4(dest), VAL2VEC3(vec_v));
143
147
  return dest;
144
148
  }
145
149
 
146
- /* call-seq: rotate(axis, angle) => new Mat4 */
147
- VALUE rb_cglm_rotate_new(VALUE klass, VALUE axis, VALUE angle) {
148
- VALUE dest = MAT4_NEW(ALLOC_MAT4);
150
+ /*
151
+ * call-seq: rotate(axis, angle[, dest]) => dest | new Mat4
152
+ */
153
+ VALUE rb_cglm_rotate_new(int argc, VALUE *argv, VALUE klass) {
154
+ VALUE axis, angle, dest;
155
+ rb_scan_args(argc, argv, "21", &axis, &angle, &dest);
156
+ if (NIL_P(dest)) dest = MAT4_NEW(ALLOC_MAT4);
149
157
  glm_rotate_make(VAL2MAT4(dest), (float) NUM2DBL(angle), VAL2VEC3(axis));
150
158
  return dest;
151
159
  }
@@ -318,8 +326,8 @@ void Init_cglm_affine() {
318
326
  rb_define_method(rb_cMat4, "decompose_rs", rb_cglm_decompose_rs, 2);
319
327
  rb_define_method(rb_cMat4, "decompose", rb_cglm_decompose, 3);
320
328
 
321
- rb_define_singleton_method(rb_cMat4, "translate", rb_cglm_translate_new, 1);
322
- rb_define_singleton_method(rb_cMat4, "scale", rb_cglm_scale_new, 1);
323
- rb_define_singleton_method(rb_cMat4, "rotate", rb_cglm_rotate_new, 2);
329
+ rb_define_singleton_method(rb_cMat4, "translate", rb_cglm_translate_new,-1);
330
+ rb_define_singleton_method(rb_cMat4, "scale", rb_cglm_scale_new, -1);
331
+ rb_define_singleton_method(rb_cMat4, "rotate", rb_cglm_rotate_new, -1);
324
332
  rb_define_singleton_method(rb_cMat4, "axis_angle_rotate_at", rb_cglm_rotate_at_new, 3);
325
333
  }
@@ -9,7 +9,9 @@ VALUE rb_cglm_quat_new_identity(int argc, VALUE *argv, VALUE self) {
9
9
  return dest;
10
10
  }
11
11
 
12
- /* call-seq: axis_angle(axis, angle[, dest]) => dest | new Quat */
12
+ /*
13
+ * call-seq: axis_angle(axis, angle[, dest]) => dest | new Quat
14
+ */
13
15
  VALUE rb_cglm_quat_new_axis_angle(int argc, VALUE *argv, VALUE self) {
14
16
  VALUE axis, angle, dest;
15
17
  rb_scan_args(argc, argv, "21", &axis, &angle, &dest);
@@ -201,13 +203,13 @@ VALUE rb_cglm_quat_to_mat3t(int argc, VALUE *argv, VALUE self) {
201
203
 
202
204
  /* call-seq: lerp!(from, to, amount) => self */
203
205
  VALUE rb_cglm_quat_lerp_self(VALUE self, VALUE from, VALUE to, VALUE amount) {
204
- glm_quat_lerp(VAL2QUAT(from), VAL2QUAT(to), NUM2FLT(to), VAL2QUAT(self));
206
+ glm_quat_lerp(VAL2QUAT(from), VAL2QUAT(to), NUM2FLT(amount), VAL2QUAT(self));
205
207
  return self;
206
208
  }
207
209
 
208
210
  /* call-seq: slerp!(from, to, amount) => self */
209
211
  VALUE rb_cglm_quat_slerp_self(VALUE self, VALUE from, VALUE to, VALUE amount) {
210
- glm_quat_slerp(VAL2QUAT(from), VAL2QUAT(to), NUM2FLT(to), VAL2QUAT(self));
212
+ glm_quat_slerp(VAL2QUAT(from), VAL2QUAT(to), NUM2FLT(amount), VAL2QUAT(self));
211
213
  return self;
212
214
  }
213
215
 
data/lib/cglm/base.rb CHANGED
@@ -18,7 +18,8 @@ module CGLM
18
18
 
19
19
  def copy_to(other)
20
20
  size = addr.size > other.addr.size ? other.addr.size : addr.size
21
- other.addr[0, size] = addr[0, size]
21
+ other.addr[0, size] = addr
22
+ other
22
23
  end
23
24
 
24
25
  def dup(other = nil)
data/lib/cglm/mat3.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module CGLM
2
- class Mat3 < Base
2
+ class Mat3 < MatrixType
3
3
  # Performs multiplication with `other` and returns the result.
4
4
  #
5
5
  # * `other` is a Mat3 or Vec3.
@@ -23,5 +23,12 @@ module CGLM
23
23
  left = "#<#{self.class}@#{addr.to_i.to_s(16)} ["
24
24
  left + vals.join(",\n" + (" " * left.size)) + "]>"
25
25
  end
26
+
27
+ # Returns a flat array of floats, rather than the 2D array returned by
28
+ # #to_a. Equivalent to `to_a.flatten`, but more efficient.
29
+ def to_flat_a
30
+ addr = self.addr
31
+ addr[0, addr.size].unpack("F*")
32
+ end
26
33
  end
27
34
  end
data/lib/cglm/mat4.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module CGLM
2
- class Mat4 < Base
2
+ class Mat4 < MatrixType
3
3
  def initialize(initial_values = nil, **args)
4
4
  super(**args)
5
5
  case initial_values
@@ -0,0 +1,10 @@
1
+ module CGLM
2
+ class MatrixType < Base
3
+ # Returns a flat array of floats, rather than the 2D array returned by
4
+ # #to_a. Equivalent to `to_a.flatten`, but more efficient.
5
+ def to_flat_a
6
+ addr = self.addr
7
+ addr[0, addr.size].unpack("F*")
8
+ end
9
+ end
10
+ end
data/lib/cglm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CGLM
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/cglm.rb CHANGED
@@ -13,6 +13,7 @@ end
13
13
  module CGLM
14
14
  require 'cglm/base'
15
15
  require 'cglm/vector_type'
16
+ require 'cglm/matrix_type'
16
17
  require 'cglm/aabb'
17
18
  require 'cglm/vec3'
18
19
  require 'cglm/vec4'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cglm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin MacKenzie IV
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-23 00:00:00.000000000 Z
11
+ date: 2022-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,7 +122,7 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- description:
125
+ description:
126
126
  email:
127
127
  - sinisterchipmunk@gmail.com
128
128
  executables: []
@@ -241,6 +241,7 @@ files:
241
241
  - lib/cglm/frustum.rb
242
242
  - lib/cglm/mat3.rb
243
243
  - lib/cglm/mat4.rb
244
+ - lib/cglm/matrix_type.rb
244
245
  - lib/cglm/plane.rb
245
246
  - lib/cglm/quat.rb
246
247
  - lib/cglm/sphere.rb
@@ -255,7 +256,7 @@ metadata:
255
256
  allowed_push_host: https://rubygems.org
256
257
  homepage_uri: https://github.com/sinisterchipmunk/cglm-ruby
257
258
  source_code_uri: https://github.com/sinisterchipmunk/cglm-ruby
258
- post_install_message:
259
+ post_install_message:
259
260
  rdoc_options: []
260
261
  require_paths:
261
262
  - lib
@@ -270,8 +271,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
271
  - !ruby/object:Gem::Version
271
272
  version: '0'
272
273
  requirements: []
273
- rubygems_version: 3.1.2
274
- signing_key:
274
+ rubygems_version: 3.3.7
275
+ signing_key:
275
276
  specification_version: 4
276
277
  summary: Ruby bindings for CGLM (https://github.com/recp/cglm), a high performance
277
278
  math library for graphics applications.