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 +1 -1
- data/lib/coordinate_system.rb +16 -5
- data/lib/matrix_operations.rb +8 -0
- data/lib/screen.rb +5 -0
- data/lib/transform.rb +4 -0
- metadata +3 -3
data/basis.gemspec
CHANGED
data/lib/coordinate_system.rb
CHANGED
@@ -77,13 +77,24 @@ class CoordinateSystem
|
|
77
77
|
|
78
78
|
|
79
79
|
def standard_basis(point)
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
|
data/lib/matrix_operations.rb
CHANGED
@@ -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
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:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 6
|
10
|
+
version: 0.4.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Avishek Sen Gupta
|