barretina 0.2.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffc7c0e9a4bd67952488271345c86b2ac78177de604ca0c66df617c2243c8be4
4
- data.tar.gz: 578af134723316525a9c79de0094c8395d43671e67ea17cbe19c74a1d2b5d492
3
+ metadata.gz: ac558fc394ad22a35a7f4d7611e64107524bb58bbf9419eea8f91add82d2b074
4
+ data.tar.gz: 66ceeb22ab0a69276788fe5f61f0e772aaeec59343df8bb4bbe115a6e9714bb8
5
5
  SHA512:
6
- metadata.gz: 869f990d92768bf90b2cdbafddc91afba9bac0220bce72e8967c6413e44e329b54e6f26f05a78202a4861f990d37c83540decd03666a4032be840033e78ad4e5
7
- data.tar.gz: 1769112e3d0abe5967e7a11d425481d3156d44d5d515f98c3a89e9158be7513e9b7a58498f335ff2d4f42906b039f6164cff569f32e034272d354d5e24120204
6
+ metadata.gz: 77550d27f80a4bb48a6544ff3b670cdfa7693c3b6ac8d10034341800d7dcaa633dc5a2f6acd6f7f71a7ffdda272b68e6e2c7910a309c683fed99fd427f2bd5ee
7
+ data.tar.gz: 7b7409f66cff4d22c3e363b2ef872f607072d9a3d0f29778541025677c3435e354ab56737c46a3c80fdb2d3be5b5b16a0a996de7c0a0878c148b008a337f1639
data/Gemfile CHANGED
@@ -5,3 +5,5 @@ source "https://rubygems.org"
5
5
  gemspec
6
6
 
7
7
  gem "minitest", "~> 5.25"
8
+
9
+ gem "rake", "~> 13.3"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- barretina (0.1.2)
4
+ barretina (0.2.0)
5
5
  irb (~> 1.15)
6
6
  ruby2d (~> 0.12.1)
7
7
 
@@ -22,6 +22,7 @@ GEM
22
22
  psych (5.2.6)
23
23
  date
24
24
  stringio
25
+ rake (13.3.0)
25
26
  rdoc (6.14.2)
26
27
  erb
27
28
  psych (>= 4.0.0)
@@ -37,6 +38,7 @@ PLATFORMS
37
38
  DEPENDENCIES
38
39
  barretina!
39
40
  minitest (~> 5.25)
41
+ rake (~> 13.3)
40
42
 
41
43
  BUNDLED WITH
42
44
  2.6.9
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- Barretina v0.2.0
1
+ Barretina v0.2.1
2
2
  =========
3
3
  **WORK IN PROGRESS**
4
4
 
5
5
  A 2D and 3D figure modeler.
6
6
 
7
- Or, in other words: my own Blender.
7
+ Or, in other words: _my own Blender_.
8
8
 
9
9
  ## Why?
10
10
 
@@ -24,12 +24,22 @@ I write in a diary every big commit, and I summarize the evolution of the projec
24
24
  - [Run BCM](#run-bcm)
25
25
  - [Tests](#tests)
26
26
  - [Run tests](#run-tests)
27
+ - [Using Rake](#using-rake)
28
+ - [Test files separately](#test-files-separately)
29
+ - [Algebraic classes](#algebraic-classes)
30
+ - [Generic vectors](#generic-vectors)
31
+ - [Vector](#vector)
32
+ - [Line](#line)
33
+ - [2D vectors](#2d-vectors)
34
+ - [3D vectors](#3d-vectors)
27
35
 
28
36
  ## BCM: Barretina Console Mode
29
37
 
30
- BCM is a way to run all Barretina's code without the graphic interface. I created with the intention to test while I work on this project.
38
+ BCM is a way to run all Barretina's code without the graphic interface. I created with the intention to review the code while working on this project.
31
39
 
32
- Actually, it's IRB but with a particular configuration.
40
+ It's really usefull to work with the algebraic classes about vector spaces.
41
+
42
+ In fact, it's IRB but with a particular configuration.
33
43
 
34
44
  ### Run BCM
35
45
 
@@ -48,11 +58,36 @@ bcm:003:0> p + q
48
58
 
49
59
  ## Tests
50
60
 
51
- I use [Minitest](https://github.com/minitest/minitest) to create some unit tests.
61
+ This project uses [Minitest](https://github.com/minitest/minitest).
62
+
63
+ All tests are situated in `test/`, and actually them only review the geometry classes.
52
64
 
53
65
  ### Run tests
54
66
 
55
- At the moment, you can run the tests manually as a Ruby file. Eg:
67
+ #### Using Rake
68
+
69
+ Using the `rake` command will execute the tests.
70
+
71
+ It's recomended to use a specific command to only start the tests under the Bundle
72
+
73
+ ```
74
+ $ bundle exec rake test
75
+ Run options: --seed 17133
76
+
77
+ # Running:
78
+
79
+ ................................................
80
+
81
+ Finished in 0.004434s, 10826.1088 runs/s, 30448.4310 assertions/s.
82
+
83
+ 48 runs, 135 assertions, 0 failures, 0 errors, 0 skips
84
+ ```
85
+
86
+ To see other options, read the [Minitest official documentation](https://github.com/minitest/minitest?tab=readme-ov-file#rake-tasks-).
87
+
88
+ #### Test files separately
89
+
90
+ It's possible to choose the files to run, using the Ruby command and the path of the file:
56
91
 
57
92
  ```
58
93
  $ ruby test/barretina/vector_space/test_vector.rb
@@ -67,4 +102,74 @@ Finished in 0.003157s, 2851.0290 runs/s, 19006.8599 assertions/s.
67
102
  9 runs, 60 assertions, 0 failures, 0 errors, 0 skips
68
103
  ```
69
104
 
70
- Eventually, I will reorganize in a Rake file.
105
+ ## Algebraic classes
106
+
107
+ ### Generic vectors
108
+
109
+ I came up with the idea for this project because I awas studying algebra, which had vector spaces as main subject matter.
110
+
111
+ For that reason, I started with a class to work with vectors: `Barretina::VectorSpace::Vector`.
112
+
113
+ This class can work with vectors from all dimensions, but at the same time is to slow for a render application. In order to create a better app, there is a module specific for 2D vectors (and will be another for 3D).
114
+
115
+ But was really fun to implement that class and study how ruby can adapt the behavior for every number of dimensions.
116
+
117
+ #### Vector
118
+
119
+ For definition, a vector can add with another and results into a vector, and also can be scaled by a scalar number (integer or rational).
120
+
121
+ The `Barretina::VectorSpace::Vector` meet the requeriments.
122
+
123
+ **Important**: the vectors only work correctly with other vectors in same dimension.
124
+
125
+ The `BCM` interpreter has includeds the different vector spaces modules, then it's possible to invoke `Barretina::VectorSpace::Vector` with only `Vector`.
126
+
127
+ ```
128
+ $ bin/bcm
129
+ BCM - Barretina Console Mode
130
+ bcm:001:0> v = Vector.new(1, 3, 5, 1)
131
+ -> #<Vector (1, 3, 5, 1)>
132
+ bcm:002:0> w = Vector[2, 2, 3, -1]
133
+ -> #<Vector (2, 2, 3, -1)>
134
+ bcm:003:0> v + w
135
+ -> #<Vector (3, 5, 8, 0)>
136
+ bcm:004:0> v - w
137
+ -> #<Vector (-1, 1, 2, 2)>
138
+ bcm:005:0> v * 3
139
+ -> #<Vector (3, 9, 15, 3)>
140
+ bcm:006:0> v.to_s
141
+ -> "(1, 3, 5, 1)"
142
+ bcm:007:0> "#{v} + #{w} = #{v + w}"
143
+ -> "(1, 3, 5, 1) + (2, 2, 3, -1) = (3, 5, 8, 0)"
144
+ ```
145
+
146
+ #### Line
147
+
148
+ It's possible to have a line object, `Barretina::VectorSpace::Line`, that includes two vectors and can calculate the distance between both:
149
+
150
+ ```
151
+ $ bin/bcm
152
+ BCM - Barretina Console Mode
153
+ bcm:001:0> v = Vector.new(1, 3, 5, 1)
154
+ -> #<Vector (1, 3, 5, 1)>
155
+ bcm:002:0> w = Vector[2, 2, 3, -1]
156
+ -> #<Vector (2, 2, 3, -1)>
157
+ bcm:003:0> l = Line.new(v, w)
158
+ -> #<Line (1, 3, 5, 1)-(2, 2, 3, -1)>
159
+ bcm:004:0> l.length
160
+ -> 3.1622776601683795
161
+ ```
162
+
163
+ ### 2D vectors
164
+
165
+ In that module there are three important elements to calculate the objects to render: vectors, lines and polygons.
166
+
167
+ - `Barretina::VectorSpace2D::Vector2D`
168
+ - `Barretina::VectorSpace2D::Line2D`
169
+ - `Barretina::VectorSpace2D::Polygon`
170
+
171
+ All of these are usefull to calculate the objects coordenates and transformations to start with graphic rendering.
172
+
173
+ ### 3D vectors
174
+
175
+ At the moment I didn't started with 3D spaces.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "minitest/test_task"
2
+
3
+ Minitest::TestTask.create # named test, sensible defaults
4
+
5
+ task :default => :test
@@ -4,7 +4,7 @@ module Barretina
4
4
  module VectorSpace
5
5
  class Vector
6
6
  def self.[](*args)
7
- Vector.new *args
7
+ Vector.new(*args)
8
8
  end
9
9
 
10
10
  attr_accessor :coordenates
@@ -26,7 +26,7 @@ module Barretina
26
26
  end
27
27
 
28
28
  def * scalar
29
- Vector.new *coordenates.map { |c| c * scalar }
29
+ Vector.new(*coordenates.map { |c| c * scalar })
30
30
  rescue => e
31
31
  raise "Scalar value must be a Numeric instance (recomended Integer or Float), not a #{scalar.class}" unless scalar.is_a? Numeric
32
32
  raise e
@@ -53,7 +53,7 @@ module Barretina
53
53
  end
54
54
 
55
55
  def add vector, &block
56
- Vector.new *[coordenates, vector.coordenates].transpose.map(&block)
56
+ Vector.new(*[coordenates, vector.coordenates].transpose.map(&block))
57
57
  rescue IndexError => e
58
58
  raise IndexError, "Impossible add or substract vectors with different dimesions"
59
59
  rescue => e
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Barretina
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barretina
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricard Ferrero
@@ -54,6 +54,7 @@ files:
54
54
  - Gemfile.lock
55
55
  - LICENSE
56
56
  - README.md
57
+ - Rakefile
57
58
  - bin/barretina
58
59
  - bin/bcm
59
60
  - lib/barretina.rb