Class: CartoCSSHelper::Info

Inherits:
Object
  • Object
show all
Defined in:
lib/cartocss_helper/tag_lister.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_expected_composite(key, value) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/cartocss_helper/tag_lister.rb', line 43

def self.get_expected_composite(key, value)
  CartoCSSHelper::Configuration.get_style_specific_data.list_of_documented_tags.each do |documented|
    next unless documented.key == key
    return documented.composite if documented.value == value
  end
  return nil
end

.get_expected_state(key, value) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/cartocss_helper/tag_lister.rb', line 35

def self.get_expected_state(key, value)
  CartoCSSHelper::Configuration.get_style_specific_data.list_of_documented_tags.each do |documented|
    next unless documented.key == key
    return documented.state if documented.value == value
  end
  return nil
end

.rendered_on_zlevel(tags, type, zlevel, on_water) ⇒ Object



201
202
203
204
205
# File 'lib/cartocss_helper/tag_lister.rb', line 201

def self.rendered_on_zlevel(tags, type, zlevel, on_water)
  empty = Scene.new({}, zlevel, on_water, type, true)
  tested = Scene.new(tags, zlevel, on_water, type, true)
  return tested.is_output_different(empty)
end

Instance Method Details

#asssume_that_no_composite_will_match(key, value, zlevels) ⇒ Object



102
103
104
105
106
107
108
109
# File 'lib/cartocss_helper/tag_lister.rb', line 102

def asssume_that_no_composite_will_match(key, value, zlevels)
  @last_composite = nil
  if is_rendered key, value, zlevels
    return :primary
  else
    return :ignored
  end
end

#assume_that_only_this_composite_can_match(key, value, zlevels, expected_composite) ⇒ Object



92
93
94
95
96
97
98
99
100
# File 'lib/cartocss_helper/tag_lister.rb', line 92

def assume_that_only_this_composite_can_match(key, value, zlevels, expected_composite)
  if is_rendered_as_composite key, value, expected_composite, zlevels
    @last_composite = how_rendered_as_composite key, value, expected_composite, zlevels
    return :composite
  else
    @last_composite = nil
    return :ignored
  end
end

#get_render_state_of_tag(key, value, quick_and_more_prone_to_errors) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/cartocss_helper/tag_lister.rb', line 71

def get_render_state_of_tag(key, value, quick_and_more_prone_to_errors)
  if Info.get_expected_state(key, value) == :ignored
    @last_composite = nil
    return :ignored
  end
  zlevels = [22, 13] # TODO: - this is specially tuned for Default
  expected_composite = Info.get_expected_composite(key, value)
  if quick_and_more_prone_to_errors
    return get_render_state_of_tag_quick_heurestic(key, value, expected_composite, zlevels)
  end
  return get_render_state_of_tag_thorough(key, value, expected_composite, zlevels)
end

#get_render_state_of_tag_quick_heuresticObject



84
85
86
87
88
89
90
# File 'lib/cartocss_helper/tag_lister.rb', line 84

def get_render_state_of_tag_quick_heurestic
  if expected_composite != nil
    return assume_that_only_this_composite_can_match(key, value, zlevels, expected_composite)
  else
    return asssume_that_no_composite_will_match(key, value, zlevels)
  end
end

#get_render_state_of_tag_thorough(key, value, expected_composite, zlevels) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/cartocss_helper/tag_lister.rb', line 111

def get_render_state_of_tag_thorough(key, value, expected_composite, zlevels)
  if is_rendered key, value, zlevels
    @last_composite = nil
    return :primary
  end
  if is_rendered_as_composite key, value, expected_composite
    @last_composite = how_rendered_as_composite key, value, expected_composite
    return :composite
  else
    @last_composite = nil
    return :ignored
  end
end

#get_render_state_of_tags(quick_and_more_prone_to_errors) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cartocss_helper/tag_lister.rb', line 58

def get_render_state_of_tags(quick_and_more_prone_to_errors)
  states = []
  @last_composite = nil
  Heuristic.get_tags.each do |tag|
    key = tag[0]
    value = tag[1]
    # print_render_state_of_tag key, value
    state = get_render_state_of_tag(key, value, quick_and_more_prone_to_errors)
    states.push(TagRenderingStatus.new(key, value, state, @last_composite))
  end
  return states
end

#how_rendered_as_composite(key, value, suggested_composite, zlevels = [Configuration.get_max_z]) ⇒ Object

TODO: - note that some tags may be rendered up to X zoom level, but checking all zlevels would take too much time



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/cartocss_helper/tag_lister.rb', line 184

def how_rendered_as_composite(key, value, suggested_composite, zlevels = [Configuration.get_max_z]) # TODO: - note that some tags may be rendered up to X zoom level, but checking all zlevels would take too much time
  [false, true].each do |on_water|
    zlevels.each do |zlevel|
      result = how_rendered_on_zlevel_as_composite({ key => value }, 'closed_way', zlevel, on_water, suggested_composite)
      return result if result != nil
      result = how_rendered_on_zlevel_as_composite({ key => value }, 'way', zlevel, on_water, suggested_composite)
      return result if result != nil
      result = how_rendered_on_zlevel_as_composite({ key => value }, 'node', zlevel, on_water, suggested_composite)
      return result if result != nil
    end
  end
  if suggested_composite != nil
    return how_rendered_as_composite key, value, nil
  end
  return nil
end

#is_key_rendered_and_value_ignored(key, value) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/cartocss_helper/tag_lister.rb', line 144

def is_key_rendered_and_value_ignored(key, value)
  return false if notis_rendered key, get_generic_tag_value
  [false, true].each do |on_water|
    [Configuration.get_max_z].each do |zlevel|
      ['area', 'closed_way', 'way', 'node'].each do |type|
        next unless CartoCSSHelper::Info.rendered_on_zlevel({ key => value }, type, zlevel, on_water)
        unless is_key_rendered_and_value_ignored_set(key, value, type, zlevel, on_water)
          return false
        end
      end
    end
  end
  return true
end

#is_key_rendered_and_value_ignored_set(key, value, type, zlevel, on_water) ⇒ Object



159
160
161
162
163
# File 'lib/cartocss_helper/tag_lister.rb', line 159

def is_key_rendered_and_value_ignored_set(key, value, type, zlevel, on_water)
  with_tested_value = Scene.new({ key => value }, zlevel, on_water, type, true)
  with_generic_value = Scene.new({ key => get_generic_tag_value }, zlevel, on_water, type, true)
  return !with_tested_value.is_output_different(with_generic_value)
end

#is_rendered(key, value, zlevels = [Configuration.get_max_z]) ⇒ Object

TODO: - note that some tags may be rendered up to X zoom level, but checking all zlevels would take too much time



165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/cartocss_helper/tag_lister.rb', line 165

def is_rendered(key, value, zlevels = [Configuration.get_max_z]) # TODO: - note that some tags may be rendered up to X zoom level, but checking all zlevels would take too much time
  [false, true].each do |on_water|
    zlevels.each do |zlevel| #
      ['area', 'closed_way', 'way', 'node'].each do |type|
        if CartoCSSHelper::Info.rendered_on_zlevel({ key => value }, type, zlevel, on_water)
          return true
        end
      end
    end
  end
  return false
end

#is_rendered_as_composite(key, value, suggested_composite = nil, zlevels = [Configuration.get_max_z]) ⇒ Object

TODO: - note that some tags may be rendered up to X zoom level, but checking all zlevels would take too much time



178
179
180
181
182
# File 'lib/cartocss_helper/tag_lister.rb', line 178

def is_rendered_as_composite(key, value, suggested_composite = nil, zlevels = [Configuration.get_max_z]) # TODO: - note that some tags may be rendered up to X zoom level, but checking all zlevels would take too much time
  reason = how_rendered_as_composite key, value, suggested_composite, zlevels
  return false if reason == nil
  return true
end


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/cartocss_helper/tag_lister.rb', line 125

def print_render_state_of_tag(key, value)
  if is_rendered key, value
    @last_composite = nil
    if value == get_generic_tag_value
      puts "#{key}=#{value} - primary generic tag value"
    elsif is_key_rendered_and_value_ignored(key, value)
      puts "#{key}=#{value} - primary, but rendering the same as generic value"
    else
      puts "#{key}=#{value} - primary"
    end
  elsif is_rendered_as_composite key, value, @last_composite
    @last_composite = how_rendered_as_composite key, value, @last_composite
    puts "#{key}=#{value} - composite with #{@last_composite} - and maybe other tags"
  else
    @last_composite = nil
    puts "#{key}=#{value} - not displayed"
  end
end


51
52
53
54
55
56
# File 'lib/cartocss_helper/tag_lister.rb', line 51

def print_render_state_of_tags(git_branch)
  Git.checkout git_branch
  get_render_state_of_tags.each do |state|
    state.code_print
  end
end