🎨 working on background color based polygon filling

pull/7/head
Michael Straßburger 2016-09-28 14:11:05 +02:00
rodzic 22907f4168
commit f5fdd8dea5
4 zmienionych plików z 18 dodań i 4 usunięć

Wyświetl plik

@ -34,7 +34,9 @@ module.exports = class BrailleBuffer
@foregroundBuffer = [] @foregroundBuffer = []
@backgroundBuffer = [] @backgroundBuffer = []
setBackground: (idx, color) -> setBackground: (x, y, color) ->
return unless 0 <= x < @width and 0 <= y < @height
idx = @_project x, y
@backgroundBuffer[idx] = color @backgroundBuffer[idx] = color
setPixel: (x, y, color) -> setPixel: (x, y, color) ->

Wyświetl plik

@ -49,6 +49,10 @@ module.exports = class Canvas
bresenham projected[i-1]..., projected[i]..., bresenham projected[i-1]..., projected[i]...,
(x, y) => @buffer.setPixel x, y, color (x, y) => @buffer.setPixel x, y, color
background: (x, y, color) ->
point = @_project x, y
@buffer.setBackground point[0], point[1], color
# TODO: support for polygon holes # TODO: support for polygon holes
polygon: (points, color) -> polygon: (points, color) ->
vertices = [] vertices = []

Wyświetl plik

@ -19,7 +19,7 @@ module.exports = class Renderer
labelMargin: 5 labelMargin: 5
#"poi_label", "water", #"poi_label", "water",
drawOrder: ["admin", "building", "road", "place_label", "poi_label", "housenum_label"] drawOrder: ["water", "admin", "building", "road", "place_label", "poi_label", "housenum_label"]
icons: icons:
car: "🚗" car: "🚗"
@ -109,9 +109,11 @@ module.exports = class Renderer
features = @features[layer].tree.search box features = @features[layer].tree.search box
@notify "rendering #{features.length} #{layer} features.." @notify "rendering #{features.length} #{layer} features.."
for feature in features for feature in features
@_drawFeature layer, feature.data, scale @_drawFeature layer, feature, scale
_drawFeature: (layer, data, scale) ->
feature = data.data
_drawFeature: (layer, feature, scale) ->
# TODO: this is ugly :) need to be fixed @style # TODO: this is ugly :) need to be fixed @style
#return false if feature.properties.class is "ferry" #return false if feature.properties.class is "ferry"
feature.type = "LineString" if layer is "building" or layer is "road" feature.type = "LineString" if layer is "building" or layer is "road"
@ -137,6 +139,11 @@ module.exports = class Renderer
when "Polygon" when "Polygon"
@canvas.polygon toDraw[0], colorCode @canvas.polygon toDraw[0], colorCode
# points = toDraw[0]
# for y in [Math.max(0,Math.floor(data.minY/scale))..Math.min(@height, Math.floor(data.maxY/scale))] by 4
# for x in [Math.max(0, Math.floor(data.minX/scale))..Math.min(@width, Math.floor(data.maxX/scale))] by 2
# if utils.pointInPolygon points, [x, y]
# @canvas.background x, y, colorCode
when "Point" when "Point"
text = feature.properties["name_"+@config.language] or text = feature.properties["name_"+@config.language] or

Wyświetl plik

@ -16,6 +16,7 @@ utils =
point[0] < (polygon[j][0]-polygon[i][0]) * (point[1]-polygon[i][1]) / (polygon[j][1]-polygon[i][1]) + polygon[i][0] point[0] < (polygon[j][0]-polygon[i][0]) * (point[1]-polygon[i][1]) / (polygon[j][1]-polygon[i][1]) + polygon[i][0]
inside = !inside inside = !inside
j = i j = i
inside
deg2rad: (angle) -> deg2rad: (angle) ->
# (angle / 180) * Math.PI # (angle / 180) * Math.PI