chipmunk-ffi 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__)+'/spec_helper'
2
+ describe 'BBStruct in chipmunk' do
3
+ describe 'BB class' do
4
+ it 'can be created by l,b,r,t' do
5
+ bb = CP::BB.new(1,2,3,4)
6
+ bb.l.should == 1
7
+ bb.b.should == 2
8
+ bb.r.should == 3
9
+ bb.t.should == 4
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,42 @@
1
+ describe 'A new Body' do
2
+ it 'should be creatable' do
3
+ b = CP::Body.new(5, 7)
4
+ b.m.should == 5
5
+ b.i.should == 7
6
+ end
7
+
8
+ it 'can set its mass' do
9
+ b = CP::Body.new(5, 7)
10
+ b.m = 900
11
+ b.m.should == 900
12
+ end
13
+
14
+ it 'can set its pos' do
15
+ b = CP::Body.new(5, 7)
16
+ b.p.x.should == 0
17
+ b.p.y.should == 0
18
+
19
+ b.pos = vec2(4,6)
20
+ # b.pos.x.should == 4
21
+ # b.pos.y.should == 6
22
+ end
23
+
24
+ it 'can set its moment'
25
+ it 'can set its vel'
26
+ it 'can set its force'
27
+ it 'can set its angle'
28
+ it 'can set its angle_vel'
29
+ it 'can set its torque'
30
+ it 'can get its rot'
31
+ it 'can get local2world'
32
+ it 'can get world2local'
33
+ it 'can reset its forces'
34
+ it 'can apply force'
35
+ it 'can apply impulse'
36
+ it 'can update its velocity over a timestep'
37
+
38
+ it 'should be able to update its position' do
39
+ b = CP::Body.new(5, 7)
40
+ b.update_position 25
41
+ end
42
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__)+'/spec_helper'
2
+ describe 'CP module' do
3
+ it 'CP should calc moment for poly' do
4
+ verts = []
5
+ verts << vec2(1,1)
6
+ verts << vec2(1,2)
7
+ verts << vec2(2,2)
8
+ moment_for_poly(90, verts, vec2(0,0)).should == 420.0
9
+ end
10
+
11
+ it 'can give a version' do
12
+ v = CP::VERSION
13
+ # 5.0.0
14
+ v.split(".").size.should == 3
15
+ end
16
+ end
@@ -0,0 +1,61 @@
1
+ require File.dirname(__FILE__)+'/spec_helper'
2
+ describe 'ShapeStruct in chipmunk' do
3
+ describe 'Circle class' do
4
+ it 'can be created' do
5
+ bod = CP::Body.new 90, 76
6
+ s = CP::Shape::Circle.new bod, 40, CP::ZERO_VEC_2
7
+ end
8
+
9
+ it 'can get its body' do
10
+ bod = CP::Body.new 90, 76
11
+ s = CP::Shape::Circle.new bod, 20, CP::ZERO_VEC_2
12
+ s.body.should == bod
13
+ end
14
+
15
+ it 'can get its elasticity' do
16
+ bod = CP::Body.new 90, 76
17
+ s = CP::Shape::Circle.new bod, 20, CP::ZERO_VEC_2
18
+ s.e.should == 0
19
+ s.e = 0.5
20
+ s.e.should == 0.5
21
+ end
22
+
23
+ it 'can build a BB' do
24
+ bod = CP::Body.new 90, 76
25
+ s = CP::Shape::Circle.new bod, 40, CP::ZERO_VEC_2
26
+ bb = s.bb
27
+ bb.should_not be_nil
28
+ bb.l.should == -40
29
+ bb.b.should == -40
30
+ bb.r.should == 40
31
+ bb.t.should == 40
32
+ end
33
+
34
+ it 'can get its layers' do
35
+ bod = CP::Body.new 90, 76
36
+ s = CP::Shape::Circle.new bod, 40, CP::ZERO_VEC_2
37
+ s.layers.should == -1
38
+ end
39
+
40
+ it 'can get its col type' do
41
+ bod = CP::Body.new 90, 76
42
+ s = CP::Shape::Circle.new bod, 40, CP::ZERO_VEC_2
43
+ s.collision_type.should == nil
44
+ s.collision_type = :foo
45
+ s.collision_type.should == :foo
46
+ s.struct.collision_type.should == :foo.object_id
47
+ end
48
+ end
49
+ describe 'Segment class' do
50
+ it 'can be created' do
51
+ bod = CP::Body.new 90, 76
52
+ s = CP::Shape::Segment.new bod, vec2(1,1), vec2(2,2), 5
53
+ end
54
+ end
55
+ describe 'Poly class' do
56
+ it 'can be created' do
57
+ bod = CP::Body.new 90, 76
58
+ s = CP::Shape::Poly.new bod, [vec2(1,1), vec2(2,2),vec2(3,3)], CP::ZERO_VEC_2
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__)+'/spec_helper'
2
+ describe 'Shape in chipmunk' do
3
+ it 'can be created' do
4
+ s = CP::Space.new
5
+ end
6
+ it 'can set its iterations' do
7
+ s = CP::Space.new
8
+ s.iterations = 9
9
+ s.iterations.should == 9
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec'
2
+ $: << File.dirname(__FILE__)+'/../lib'
3
+
4
+ require 'chipmunk-ffi'
5
+ include CP
@@ -0,0 +1,152 @@
1
+ require File.dirname(__FILE__)+'/spec_helper'
2
+ describe 'Vect in chipmunk' do
3
+ describe 'global modifications' do
4
+ it 'should create vec2 global func' do
5
+ v = vec2(4,3)
6
+ v.class.should == CP::Vec2
7
+ v.x.should == 4
8
+ v.y.should == 3
9
+ end
10
+ it 'should create ZERO_VEC_2 to use' do
11
+ v = CP::ZERO_VEC_2
12
+ v.x.should == 0
13
+ v.y.should == 0
14
+ end
15
+
16
+ it 'should freeze ZERO_VEC_2' do
17
+ v = CP::ZERO_VEC_2
18
+ v.frozen?.should be_true
19
+ lambda {v.x = 5}.should raise_error
20
+ v.x.should == 0
21
+ end
22
+ end
23
+ describe 'Vec2 class' do
24
+ it 'can be created by x,y' do
25
+ v = CP::Vec2.new(1,3)
26
+ v.x.should == 1
27
+ v.y.should == 3
28
+ end
29
+
30
+ it 'can add and not modify orig' do
31
+ v1 = CP::Vec2.new(1,3)
32
+ v2 = v1 + CP::Vec2.new(4,9)
33
+ v1.x.should == 1
34
+ v1.y.should == 3
35
+
36
+ v2.x.should == 5
37
+ v2.y.should == 12
38
+ end
39
+
40
+ it 'can subtract and not modify orig' do
41
+ v1 = CP::Vec2.new(1,3)
42
+ v2 = v1 - CP::Vec2.new(4,9)
43
+ v1.x.should == 1
44
+ v1.y.should == 3
45
+
46
+ v2.x.should == -3
47
+ v2.y.should == -6
48
+ end
49
+
50
+ it 'can multiply and not modify orig' do
51
+ v1 = CP::Vec2.new(1,3)
52
+ v2 = v1 * 3
53
+ v1.x.should == 1
54
+ v1.y.should == 3
55
+
56
+ v2.x.should == 3
57
+ v2.y.should == 9
58
+ end
59
+
60
+ it 'can divide and not modify orig' do
61
+ v1 = CP::Vec2.new(9,3)
62
+ v2 = v1 / 3
63
+ v1.x.should == 9
64
+ v1.y.should == 3
65
+
66
+ v2.x.should == 3
67
+ v2.y.should == 1
68
+ end
69
+
70
+ it 'can set and get x,y' do
71
+ v = CP::Vec2.new(4,5)
72
+ v.x = 7
73
+ v.y = 2
74
+ v.x.should == 7
75
+ v.y.should == 2
76
+ end
77
+
78
+ it 'can report itself into a string' do
79
+ v = CP::Vec2.new(4,5)
80
+ v.to_s.should == "( 4.000, 5.000)"
81
+ end
82
+
83
+ it 'can create a Vec2 from an angle (0)' do
84
+ v = CP::Vec2.for_angle(0)
85
+ v.x.should == 1
86
+ v.y.should == 0
87
+ end
88
+
89
+ it 'can create a Vec2 from an angle (PI)' do
90
+ v = CP::Vec2.for_angle(Math::PI)
91
+ v.x.should be_close(-1,0.001)
92
+ v.y.should be_close(0,0.001)
93
+ end
94
+
95
+ it 'can give the angle of the Vec2' do
96
+ v = CP::Vec2.new(-1,0)
97
+ v.to_angle.should be_close(Math::PI,0.001)
98
+ end
99
+
100
+ it 'can return an array of itself' do
101
+ v = CP::Vec2.new(-1,0)
102
+ v.to_a.should == [-1,0]
103
+ end
104
+
105
+ it 'can return the negated version of itself' do
106
+ v = -CP::Vec2.new(-1,-4)
107
+ v.x.should == 1
108
+ v.y.should == 4
109
+ end
110
+
111
+ it 'can return the normalized version of itself' do
112
+ v = CP::Vec2.new(10,20).normalize
113
+ v.x.should be_close(0.447,0.001)
114
+ v.y.should be_close(0.894,0.001)
115
+ end
116
+
117
+ it 'can be normalized! (with a bang)' do
118
+ v = CP::Vec2.new(10,20)
119
+ v2 = v.normalize!
120
+ v.x.should be_close(0.447,0.001)
121
+ v.y.should be_close(0.894,0.001)
122
+
123
+ v2.x.should be_close(0.447,0.001)
124
+ v2.y.should be_close(0.894,0.001)
125
+ end
126
+
127
+ it 'can get its own length' do
128
+ v = CP::Vec2.new(10,20)
129
+ v.length.should be_close(22.361, 0.001)
130
+ end
131
+
132
+ it 'can get its own lengthsq' do
133
+ v = CP::Vec2.new(10,20)
134
+ v.lengthsq.should be_close(500, 0.001)
135
+ end
136
+
137
+ it 'can dot'
138
+ it 'can cross'
139
+ it 'can get dist from other vec2'
140
+ it 'can get dist squared from other vec2'
141
+ it 'can tell if its near? another vec2'
142
+ it 'can perp'
143
+ it 'can rperp'
144
+ it 'can rotate'
145
+ it 'can unrotate'
146
+ it 'can lerp'
147
+ it 'can lerpconst'
148
+ it 'can normalize_safe'
149
+ it 'can project'
150
+
151
+ end
152
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chipmunk-ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shawn Anderson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-02 00:00:00 -05:00
12
+ date: 2009-12-04 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -45,6 +45,19 @@ files:
45
45
  - VERSION
46
46
  - chipmunk-ffi.gemspec
47
47
  - lib/chipmunk-ffi.rb
48
+ - lib/chipmunk-ffi/bb.rb
49
+ - lib/chipmunk-ffi/body.rb
50
+ - lib/chipmunk-ffi/core.rb
51
+ - lib/chipmunk-ffi/shape.rb
52
+ - lib/chipmunk-ffi/space.rb
53
+ - lib/chipmunk-ffi/vec2.rb
54
+ - spec/bb_spec.rb
55
+ - spec/body_spec.rb
56
+ - spec/core_spec.rb
57
+ - spec/shape_spec.rb
58
+ - spec/space_spec.rb
59
+ - spec/spec_helper.rb
60
+ - spec/vec2_spec.rb
48
61
  has_rdoc: true
49
62
  homepage: http://shawn42.github.com/chipmunk-ffi
50
63
  licenses: []
@@ -73,5 +86,11 @@ rubygems_version: 1.3.5
73
86
  signing_key:
74
87
  specification_version: 3
75
88
  summary: FFI bindings for chipmunk physics lib.
76
- test_files: []
77
-
89
+ test_files:
90
+ - spec/bb_spec.rb
91
+ - spec/body_spec.rb
92
+ - spec/core_spec.rb
93
+ - spec/shape_spec.rb
94
+ - spec/space_spec.rb
95
+ - spec/spec_helper.rb
96
+ - spec/vec2_spec.rb