v2d 0.0.1
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.
- data.tar.gz.sig +0 -0
- data/Manifest +6 -0
- data/README +21 -0
- data/Rakefile +13 -0
- data/ext/extconf.rb +4 -0
- data/ext/v2d.c +136 -0
- data/spec/v2d_spec.rb +71 -0
- data/v2d.gemspec +33 -0
- metadata +102 -0
- metadata.gz.sig +1 -0
data.tar.gz.sig
ADDED
Binary file
|
data/Manifest
ADDED
data/README
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Installation:
|
2
|
+
ruby extconf.rb
|
3
|
+
make
|
4
|
+
make install
|
5
|
+
|
6
|
+
Usage:
|
7
|
+
require 'v2d'
|
8
|
+
|
9
|
+
v1 = V2D[1.0, 2.0] # or v1 = V2D.new(1.0, 2.0)
|
10
|
+
v2 = V2D[0, 0]
|
11
|
+
|
12
|
+
v2.x = v1.x + 10 # v2 = V2D[11, 0]
|
13
|
+
v2.y = v1.y + 10 # v2 = V2D[11, 12]
|
14
|
+
(v1 + v2) == V2D[12, 14]
|
15
|
+
(v1 - v2) == V2D[-10, -10]
|
16
|
+
(v1 * 3) == V2D[3, 6]
|
17
|
+
(v2 / 4) == V2D[2.75, 3]
|
18
|
+
V2D[3, 4].abs == 5
|
19
|
+
|
20
|
+
Tests:
|
21
|
+
spec v2d_spec.rb
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('v2d', '0.0.1') do |p|
|
6
|
+
p.description = "2D Vector implemented as Ruby extension"
|
7
|
+
p.url = "http://github.com/cypok/v2d"
|
8
|
+
p.author = "Vladimir Parfinenko"
|
9
|
+
p.email = "vladimir.parfinenko@gmail.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
13
|
+
|
data/ext/extconf.rb
ADDED
data/ext/v2d.c
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <math.h>
|
3
|
+
|
4
|
+
VALUE cV2D;
|
5
|
+
|
6
|
+
ID ix, iy;
|
7
|
+
|
8
|
+
/* DEFINITIONS */
|
9
|
+
|
10
|
+
/*VALUE v2d_initialize(VALUE self);*/
|
11
|
+
VALUE v2d_initialize_with_x_and_y(VALUE self, VALUE x, VALUE y);
|
12
|
+
VALUE v2d_square_brackets(VALUE klass, VALUE x, VALUE y);
|
13
|
+
VALUE v2d_get_x(VALUE self);
|
14
|
+
VALUE v2d_get_y(VALUE self);
|
15
|
+
VALUE v2d_set_x(VALUE self, VALUE x);
|
16
|
+
VALUE v2d_set_y(VALUE self, VALUE y);
|
17
|
+
VALUE v2d_add(VALUE self, VALUE other);
|
18
|
+
VALUE v2d_sub(VALUE self, VALUE other);
|
19
|
+
VALUE v2d_mul(VALUE self, VALUE multiplier);
|
20
|
+
VALUE v2d_div(VALUE self, VALUE divisor);
|
21
|
+
VALUE v2d_abs(VALUE self);
|
22
|
+
VALUE v2d_equals(VALUE self, VALUE other);
|
23
|
+
|
24
|
+
void Init_v2d() {
|
25
|
+
cV2D = rb_define_class("V2D", rb_cObject);
|
26
|
+
|
27
|
+
/*rb_define_method(cV2D, "initialize", v2d_initialize, 0);*/
|
28
|
+
rb_define_method(cV2D, "initialize", v2d_initialize_with_x_and_y, 2);
|
29
|
+
rb_define_singleton_method(cV2D, "[]", v2d_square_brackets, 2);
|
30
|
+
rb_define_method(cV2D, "x", v2d_get_x, 0);
|
31
|
+
rb_define_method(cV2D, "y", v2d_get_y, 0);
|
32
|
+
rb_define_method(cV2D, "x=", v2d_set_x, 1);
|
33
|
+
rb_define_method(cV2D, "y=", v2d_set_y, 1);
|
34
|
+
rb_define_method(cV2D, "+", v2d_add, 1);
|
35
|
+
rb_define_method(cV2D, "-", v2d_sub, 1);
|
36
|
+
rb_define_method(cV2D, "*", v2d_mul, 1);
|
37
|
+
rb_define_method(cV2D, "/", v2d_div, 1);
|
38
|
+
rb_define_method(cV2D, "abs", v2d_abs, 0);
|
39
|
+
rb_define_method(cV2D, "==", v2d_equals, 1);
|
40
|
+
|
41
|
+
ix = rb_intern("@x");
|
42
|
+
iy = rb_intern("@y");
|
43
|
+
}
|
44
|
+
|
45
|
+
/* IMPLEMENTATION */
|
46
|
+
|
47
|
+
/*VALUE v2d_initialize(VALUE self) {*/
|
48
|
+
/*return self;*/
|
49
|
+
/*}*/
|
50
|
+
|
51
|
+
VALUE v2d_initialize_with_x_and_y(VALUE self, VALUE x, VALUE y) {
|
52
|
+
rb_ivar_set(self, ix, x);
|
53
|
+
rb_ivar_set(self, iy, y);
|
54
|
+
return self;
|
55
|
+
}
|
56
|
+
|
57
|
+
VALUE v2d_square_brackets(VALUE klass, VALUE x, VALUE y) {
|
58
|
+
VALUE args[] = {x, y};
|
59
|
+
return rb_class_new_instance(2, args, cV2D);
|
60
|
+
}
|
61
|
+
|
62
|
+
VALUE v2d_get_x(VALUE self) {
|
63
|
+
return rb_ivar_get(self, ix);
|
64
|
+
}
|
65
|
+
|
66
|
+
VALUE v2d_get_y(VALUE self) {
|
67
|
+
return rb_ivar_get(self, iy);
|
68
|
+
}
|
69
|
+
|
70
|
+
VALUE v2d_set_x(VALUE self, VALUE x) {
|
71
|
+
return rb_ivar_set(self, ix, x);
|
72
|
+
}
|
73
|
+
|
74
|
+
VALUE v2d_set_y(VALUE self, VALUE y) {
|
75
|
+
return rb_ivar_set(self, iy, y);
|
76
|
+
}
|
77
|
+
|
78
|
+
VALUE v2d_add(VALUE self, VALUE other) {
|
79
|
+
double left_x = NUM2DBL(rb_ivar_get(self, ix));
|
80
|
+
double left_y = NUM2DBL(rb_ivar_get(self, iy));
|
81
|
+
double right_x = NUM2DBL(rb_ivar_get(other, ix));
|
82
|
+
double right_y = NUM2DBL(rb_ivar_get(other, iy));
|
83
|
+
VALUE args[] = {
|
84
|
+
rb_float_new(left_x + right_x),
|
85
|
+
rb_float_new(left_y + right_y)
|
86
|
+
};
|
87
|
+
return rb_class_new_instance(2, args, cV2D);
|
88
|
+
}
|
89
|
+
|
90
|
+
VALUE v2d_sub(VALUE self, VALUE other) {
|
91
|
+
double left_x = NUM2DBL(rb_ivar_get(self, ix));
|
92
|
+
double left_y = NUM2DBL(rb_ivar_get(self, iy));
|
93
|
+
double right_x = NUM2DBL(rb_ivar_get(other, ix));
|
94
|
+
double right_y = NUM2DBL(rb_ivar_get(other, iy));
|
95
|
+
VALUE args[] = {
|
96
|
+
rb_float_new(left_x - right_x),
|
97
|
+
rb_float_new(left_y - right_y)
|
98
|
+
};
|
99
|
+
return rb_class_new_instance(2, args, cV2D);
|
100
|
+
}
|
101
|
+
|
102
|
+
VALUE v2d_mul(VALUE self, VALUE multiplier) {
|
103
|
+
double left_x = NUM2DBL(rb_ivar_get(self, ix));
|
104
|
+
double left_y = NUM2DBL(rb_ivar_get(self, iy));
|
105
|
+
double right = NUM2DBL(multiplier);
|
106
|
+
VALUE args[] = {
|
107
|
+
rb_float_new(left_x * right),
|
108
|
+
rb_float_new(left_y * right)
|
109
|
+
};
|
110
|
+
return rb_class_new_instance(2, args, cV2D);
|
111
|
+
}
|
112
|
+
|
113
|
+
VALUE v2d_div(VALUE self, VALUE divisor) {
|
114
|
+
double left_x = NUM2DBL(rb_ivar_get(self, ix));
|
115
|
+
double left_y = NUM2DBL(rb_ivar_get(self, iy));
|
116
|
+
double right = NUM2DBL(divisor);
|
117
|
+
VALUE args[] = {
|
118
|
+
rb_float_new(left_x / right),
|
119
|
+
rb_float_new(left_y / right)
|
120
|
+
};
|
121
|
+
return rb_class_new_instance(2, args, cV2D);
|
122
|
+
}
|
123
|
+
|
124
|
+
VALUE v2d_abs(VALUE self) {
|
125
|
+
double x = NUM2DBL(rb_ivar_get(self, ix));
|
126
|
+
double y = NUM2DBL(rb_ivar_get(self, iy));
|
127
|
+
return rb_float_new(sqrt(x*x + y*y));
|
128
|
+
}
|
129
|
+
|
130
|
+
VALUE v2d_equals(VALUE self, VALUE other) {
|
131
|
+
double left_x = NUM2DBL(rb_ivar_get(self, ix));
|
132
|
+
double left_y = NUM2DBL(rb_ivar_get(self, iy));
|
133
|
+
double right_x = NUM2DBL(rb_ivar_get(other, ix));
|
134
|
+
double right_y = NUM2DBL(rb_ivar_get(other, iy));
|
135
|
+
return (left_x == right_x && left_y == right_y) ? Qtrue : Qfalse;
|
136
|
+
}
|
data/spec/v2d_spec.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'v2d'
|
2
|
+
|
3
|
+
describe V2D do
|
4
|
+
it "#new should create with arguments" do
|
5
|
+
v = V2D.new(1,2)
|
6
|
+
v.x.should == 1
|
7
|
+
end
|
8
|
+
|
9
|
+
it "#[] should create with arguments" do
|
10
|
+
v = V2D[1, 2]
|
11
|
+
v.x.should == 1
|
12
|
+
end
|
13
|
+
|
14
|
+
it "#x should return first coordinate" do
|
15
|
+
V2D[1, 2].x.should == 1
|
16
|
+
end
|
17
|
+
|
18
|
+
it "#y should return second coordinate" do
|
19
|
+
V2D[1, 2].y.should == 2
|
20
|
+
end
|
21
|
+
|
22
|
+
it "#x= should set first coordinate" do
|
23
|
+
v = V2D[1, 2]
|
24
|
+
v.x = 3
|
25
|
+
v.should == V2D[3, 2]
|
26
|
+
end
|
27
|
+
|
28
|
+
it "#y should set second coordinate" do
|
29
|
+
v = V2D[1, 2]
|
30
|
+
v.y = 3
|
31
|
+
v.should == V2D[1, 3]
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "operations" do
|
35
|
+
before do
|
36
|
+
@v1 = V2D[1.0, 2]
|
37
|
+
@v2 = V2D[3, 9.0]
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#+" do
|
41
|
+
it "should return new vector as sum" do
|
42
|
+
(@v1+@v2).should == V2D[4, 11]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#-" do
|
47
|
+
it "should return new vector as difference" do
|
48
|
+
(@v1-@v2).should == V2D[-2, -7]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#*" do
|
53
|
+
it "should return new vector as product" do
|
54
|
+
(@v1*3).should == V2D[3, 6]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#/" do
|
59
|
+
it "should return new vector as quotient" do
|
60
|
+
(@v1/2).should == V2D[0.5, 1]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#abs" do
|
65
|
+
it "should return absolute value of vector" do
|
66
|
+
@v1.abs.should == Math::sqrt(5)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
data/v2d.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{v2d}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Vladimir Parfinenko"]
|
9
|
+
s.cert_chain = ["/Users/cypok/gem-public_cert.pem"]
|
10
|
+
s.date = %q{2010-09-15}
|
11
|
+
s.description = %q{2D Vector implemented as Ruby extension}
|
12
|
+
s.email = %q{vladimir.parfinenko@gmail.com}
|
13
|
+
s.extensions = ["ext/extconf.rb"]
|
14
|
+
s.extra_rdoc_files = ["README", "ext/extconf.rb", "ext/v2d.c"]
|
15
|
+
s.files = ["README", "Rakefile", "ext/extconf.rb", "ext/v2d.c", "spec/v2d_spec.rb", "Manifest", "v2d.gemspec"]
|
16
|
+
s.homepage = %q{http://github.com/cypok/v2d}
|
17
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "V2d", "--main", "README"]
|
18
|
+
s.require_paths = ["ext"]
|
19
|
+
s.rubyforge_project = %q{v2d}
|
20
|
+
s.rubygems_version = %q{1.3.7}
|
21
|
+
s.signing_key = %q{/Users/cypok/gem-private_key.pem}
|
22
|
+
s.summary = %q{2D Vector implemented as Ruby extension}
|
23
|
+
|
24
|
+
if s.respond_to? :specification_version then
|
25
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
26
|
+
s.specification_version = 3
|
27
|
+
|
28
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
29
|
+
else
|
30
|
+
end
|
31
|
+
else
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: v2d
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Vladimir Parfinenko
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain:
|
17
|
+
- |
|
18
|
+
-----BEGIN CERTIFICATE-----
|
19
|
+
MIIDSDCCAjCgAwIBAgIBADANBgkqhkiG9w0BAQUFADBKMRwwGgYDVQQDDBN2bGFk
|
20
|
+
aW1pci5wYXJmaW5lbmtvMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJ
|
21
|
+
k/IsZAEZFgNjb20wHhcNMTAwOTE1MDg0MTM2WhcNMTEwOTE1MDg0MTM2WjBKMRww
|
22
|
+
GgYDVQQDDBN2bGFkaW1pci5wYXJmaW5lbmtvMRUwEwYKCZImiZPyLGQBGRYFZ21h
|
23
|
+
aWwxEzARBgoJkiaJk/IsZAEZFgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
|
24
|
+
ggEKAoIBAQCvZkpRSuCHyoPAGvQzWo6JTxJIYpPglVbJalWLUouWhcGewCFcoGpy
|
25
|
+
jSkyG1nFUa2AdfEf9x39ZJeRRN7rbH1pcWsXbyMXojWjJ6XhjPL7IlWR1U70qYKO
|
26
|
+
c27RdnFhtnd7acXkx/tPrOk/Z/MYVdl9zYXa1gT+uXIWd+M/CS8sRgjSsf3Uxty/
|
27
|
+
hObfwgNzWcBCC2iLbi+WTWrvAqO6nj9uRiktEowVH3hUQeg0RQ5PALtmwEGxlfJ6
|
28
|
+
HtcL7sKP5lGUkJ8/ZDUofOgkatJmA8V98Qpz3SSEGbPcGw9vtm2lKThwb/6BJ8mO
|
29
|
+
fsBh9jiK1ccDVCJmtSJpsIBfxgIyZz7zAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYD
|
30
|
+
VR0PBAQDAgSwMB0GA1UdDgQWBBTPzkzZ+7oNX5uWByxqDPaCcxL2izANBgkqhkiG
|
31
|
+
9w0BAQUFAAOCAQEAd0d1BgRz8j+M599IbrQtJOE7IwcmmKM7oQ36mtfb/+MpMZtt
|
32
|
+
AI6gbwF5mO9PgWduOjsefH0YI54gjbEH5LeU+eX18WyZPjFtPPQA9oV2e87EcLMU
|
33
|
+
N9DLKwhaZrZw0Hkpj9RxguPmoOKds8sRK9OLg1iiLx42sLQ+T6eIn5g0y6QHN9fW
|
34
|
+
f8O73LNFaCcG5dfl0dQU0gjJEJ4OsgSpSob1Vxhcoz6U1XTQmj7ZUqMn5qKq9Nh0
|
35
|
+
a2F49GO07YddCacBqSjA4DZoQxVsdruI7dtOcvHYvoOB8tY7Ue9XKPcRcyyZa6XN
|
36
|
+
78F0qvtLjR0DAnN6uYs98PR+jHE+0ckLX3D9sw==
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
|
39
|
+
date: 2010-09-15 00:00:00 +07:00
|
40
|
+
default_executable:
|
41
|
+
dependencies: []
|
42
|
+
|
43
|
+
description: 2D Vector implemented as Ruby extension
|
44
|
+
email: vladimir.parfinenko@gmail.com
|
45
|
+
executables: []
|
46
|
+
|
47
|
+
extensions:
|
48
|
+
- ext/extconf.rb
|
49
|
+
extra_rdoc_files:
|
50
|
+
- README
|
51
|
+
- ext/extconf.rb
|
52
|
+
- ext/v2d.c
|
53
|
+
files:
|
54
|
+
- README
|
55
|
+
- Rakefile
|
56
|
+
- ext/extconf.rb
|
57
|
+
- ext/v2d.c
|
58
|
+
- spec/v2d_spec.rb
|
59
|
+
- Manifest
|
60
|
+
- v2d.gemspec
|
61
|
+
has_rdoc: true
|
62
|
+
homepage: http://github.com/cypok/v2d
|
63
|
+
licenses: []
|
64
|
+
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options:
|
67
|
+
- --line-numbers
|
68
|
+
- --inline-source
|
69
|
+
- --title
|
70
|
+
- V2d
|
71
|
+
- --main
|
72
|
+
- README
|
73
|
+
require_paths:
|
74
|
+
- ext
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
hash: 3
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 11
|
90
|
+
segments:
|
91
|
+
- 1
|
92
|
+
- 2
|
93
|
+
version: "1.2"
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project: v2d
|
97
|
+
rubygems_version: 1.3.7
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: 2D Vector implemented as Ruby extension
|
101
|
+
test_files: []
|
102
|
+
|
metadata.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
K]��"HYQݤ���0�[���\^�r9�d
|