basis-processing 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/basis.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = "basis-processing"
3
- s.version = "0.4.5"
3
+ s.version = "0.4.6"
4
4
  s.author = "Avishek Sen Gupta"
5
5
  s.email = "avishek.sen.gupta@gmail.com"
6
6
  s.homepage = "http://avishek.net/blog"
@@ -77,13 +77,24 @@ class CoordinateSystem
77
77
 
78
78
 
79
79
  def standard_basis(point)
80
- standard_point =
81
- {
82
- :x => @x_basis_vector[:x]*point[:x] + @y_basis_vector[:x]*point[:y],
83
- :y => @x_basis_vector[:y]*point[:x] + @y_basis_vector[:y]*point[:y]
84
- }
80
+ basis_matrix =
81
+ [
82
+ [@x_basis_vector[:x], @y_basis_vector[:x]],
83
+ [@x_basis_vector[:y], @y_basis_vector[:y]]
84
+ ]
85
+ standard_point = MatrixOperations::into2Dx1D(basis_matrix, point)
85
86
 
86
87
  MatrixOperations::into2Dx1D(@standard_transform, standard_point)
87
88
  end
89
+
90
+ def original(onscreen_point)
91
+ p1 = MatrixOperations::into2Dx1D(MatrixOperations::inverse2D(@standard_transform), onscreen_point)
92
+ basis_matrix =
93
+ [
94
+ [@x_basis_vector[:x], @y_basis_vector[:x]],
95
+ [@x_basis_vector[:y], @y_basis_vector[:y]]
96
+ ]
97
+ MatrixOperations::into2Dx1D(MatrixOperations::inverse2D(basis_matrix), p1)
98
+ end
88
99
  end
89
100
 
@@ -12,5 +12,13 @@ module MatrixOperations
12
12
  :y => transform[1][0]*point[:x] + transform[1][1]*point[:y]
13
13
  }
14
14
  end
15
+
16
+ def MatrixOperations.inverse2D(m)
17
+ determinant = (m[0][0]*m[1][1] - m[0][1]*m[1][0]).to_f;
18
+ [
19
+ [m[1][1]/determinant, -m[0][1]/determinant],
20
+ [-m[1][0]/determinant, m[0][0]/determinant]
21
+ ]
22
+ end
15
23
  end
16
24
 
data/lib/screen.rb CHANGED
@@ -16,6 +16,11 @@ class Screen
16
16
  end
17
17
  end
18
18
 
19
+ def original(onscreen_point, basis)
20
+ p = @transform.unapply(onscreen_point)
21
+ basis.original(p)
22
+ end
23
+
19
24
  def draw_ticks(ticks, displacement)
20
25
  ticks.each do |l|
21
26
  from = @transform.apply(l[:from])
data/lib/transform.rb CHANGED
@@ -9,6 +9,10 @@ class Transform
9
9
  { :x => @origin[:x] + p[:x] * @scale[:x], :y => @origin[:y] + p[:y] * @scale[:y]}
10
10
  end
11
11
 
12
+ def unapply(p)
13
+ { :x => (p[:x] - @origin[:x]) / @scale[:x], :y => (p[:y] - @origin[:y]) / @scale[:y]}
14
+ end
15
+
12
16
  def signed
13
17
  Transform.new({:x => (@scale[:x]<=>0.0).to_i, :y => (@scale[:y]<=>0.0).to_i}, @origin)
14
18
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basis-processing
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 5
10
- version: 0.4.5
9
+ - 6
10
+ version: 0.4.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Avishek Sen Gupta