basis-processing 0.5.7 → 0.5.8

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.
Files changed (3) hide show
  1. data/basis.gemspec +1 -1
  2. data/lib/screen.rb +19 -11
  3. metadata +4 -4
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = "basis-processing"
3
- s.version = "0.5.7"
3
+ s.version = "0.5.8"
4
4
  s.add_dependency('knnball', '>= 0.0.6')
5
5
  s.author = "Avishek Sen Gupta"
6
6
  s.email = "avishek.sen.gupta@gmail.com"
@@ -38,6 +38,19 @@ class Screen
38
38
  end
39
39
  end
40
40
 
41
+ def at(point, &block)
42
+ if (!point[:x] || !point[:y])
43
+ @artist.reset_matrix
44
+ block.call(point, self) if block
45
+ return
46
+ end
47
+ p = transformed(point)
48
+ if (block)
49
+ @artist.reset_matrix
50
+ block.call(point, p, self)
51
+ end
52
+ end
53
+
41
54
  def plot(point, options = {:bar => false, :track => false}, &block)
42
55
  if (!point[:x] || !point[:y])
43
56
  @artist.reset_matrix
@@ -55,8 +68,7 @@ class Screen
55
68
  @artist.ellipse(p[:x], p[:y], 5, 5)
56
69
  end
57
70
  @artist.line(standard_x_axis_point[:x], standard_x_axis_point[:y], p[:x], p[:y]) if options[:bar]
58
- return if !@should_join
59
- @artist.line(@buffer[:x], @buffer[:y], p[:x], p[:y]) if @buffer
71
+ @artist.line(@buffer[:x], @buffer[:y], p[:x], p[:y]) if @should_join && @buffer
60
72
  @buffer = p
61
73
  end
62
74
 
@@ -72,20 +84,16 @@ class Screen
72
84
  end
73
85
 
74
86
  def transformed(data_point)
75
- # standard_point = @basis.standard_basis(data_point)
76
- # @transform.apply(standard_point)
77
87
  transformed_p = @affine_transform.mult([data_point[:x], data_point[:y]].to_java(:float), nil)
78
88
  {:x => transformed_p[0], :y => transformed_p[1]}
79
89
  end
80
90
 
81
91
  def original(onscreen_point)
82
- # p = @transform.unapply(onscreen_point)
83
- # @basis.original(p)
84
92
  transformed_p = @inverse_affine_transform.mult([onscreen_point[:x], onscreen_point[:y]].to_java(:float), nil)
85
93
  {:x => transformed_p[0], :y => transformed_p[1]}
86
94
  end
87
95
 
88
- def draw_ticks(ticks, displacement)
96
+ def draw_ticks(ticks, displacement, block)
89
97
  ticks.each do |l|
90
98
  from = l[:from]
91
99
  to = l[:to]
@@ -93,7 +101,7 @@ class Screen
93
101
  to = {:x => from[:x] + tick_vector[:x], :y => from[:y] + tick_vector[:y]}
94
102
  @artist.line(from[:x],from[:y],to[:x],to[:y])
95
103
  @artist.fill(1)
96
- @artist.text(l[:label], to[:x]+displacement[:x], to[:y]+displacement[:y])
104
+ @artist.text((block ? block.call(l[:label]) : l[:label]), to[:x]+displacement[:x], to[:y]+displacement[:y])
97
105
  end
98
106
  end
99
107
 
@@ -103,7 +111,7 @@ class Screen
103
111
  {:x => 5*vector[:x]/magnitude, :y => 5*vector[:y]/magnitude}
104
112
  end
105
113
 
106
- def draw_axes(x_interval, y_interval)
114
+ def draw_axes(x_interval, y_interval, labelling_blocks = {})
107
115
  f = @artist.createFont("Georgia", 24, true);
108
116
  @artist.text_font(f,16)
109
117
  axis_screen_transform = Transform.new({:x => 800, :y => -800}, @transform.origin)
@@ -121,8 +129,8 @@ class Screen
121
129
  @artist.line(x_ticks.first[:from][:x],x_ticks.first[:from][:y],x_ticks.last[:from][:x],x_ticks.last[:from][:y])
122
130
  @artist.line(y_ticks.first[:from][:x],y_ticks.first[:from][:y],y_ticks.last[:from][:x],y_ticks.last[:from][:y])
123
131
 
124
- draw_ticks(x_ticks, {:x => 0, :y => 20})
125
- draw_ticks(y_ticks, {:x => -50, :y => 0})
132
+ draw_ticks(x_ticks, {:x => 0, :y => 20}, labelling_blocks[:x])
133
+ draw_ticks(y_ticks, {:x => -50, :y => 0}, labelling_blocks[:y])
126
134
 
127
135
  @artist.stroke(0.4, 1.0, 0.5, 0.2)
128
136
  grid_lines = @basis.grid_lines(x_interval, y_interval).collect {|gl| {:from => @transform.apply(gl[:from]), :to => @transform.apply(gl[:to])}}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basis-processing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.5.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-09 00:00:00.000000000Z
12
+ date: 2011-10-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: knnball
16
- requirement: &9073420 !ruby/object:Gem::Requirement
16
+ requirement: &17679680 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.0.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *9073420
24
+ version_requirements: *17679680
25
25
  description: Basis provides a set of classes for easily plotting and transforming
26
26
  arbitrary 2D coordinate systems by specifying their basis vectors in Ruby-Processing.
27
27
  email: avishek.sen.gupta@gmail.com