mirror of
https://github.com/rastapasta/mapscii.git
synced 2025-03-20 00:46:38 +01:00
🚤 reducing points after scaling to speed up rendering
This commit is contained in:
parent
f5fdd8dea5
commit
05558f0cdf
@ -19,7 +19,7 @@ module.exports = class Renderer
|
|||||||
labelMargin: 5
|
labelMargin: 5
|
||||||
|
|
||||||
#"poi_label", "water",
|
#"poi_label", "water",
|
||||||
drawOrder: ["water", "admin", "building", "road", "place_label", "poi_label", "housenum_label"]
|
drawOrder: ["admin", "building", "road", "place_label", "poi_label", "housenum_label"]
|
||||||
|
|
||||||
icons:
|
icons:
|
||||||
car: "🚗"
|
car: "🚗"
|
||||||
@ -122,8 +122,7 @@ module.exports = class Renderer
|
|||||||
unless style = @styler.getStyleFor layer, feature, 14
|
unless style = @styler.getStyleFor layer, feature, 14
|
||||||
return false
|
return false
|
||||||
|
|
||||||
toDraw = for points in feature.points
|
toDraw = (@_scaleAndReduce points, scale for points in feature.points)
|
||||||
[point.x/scale, point.y/scale] for point in points
|
|
||||||
|
|
||||||
color = style.paint['line-color'] or style.paint['fill-color'] or style.paint['text-color']
|
color = style.paint['line-color'] or style.paint['fill-color'] or style.paint['text-color']
|
||||||
|
|
||||||
@ -159,5 +158,22 @@ module.exports = class Renderer
|
|||||||
if @labelBuffer.writeIfPossible text, x, point[1], (@config.layers[layer]?.margin or @config.labelMargin)
|
if @labelBuffer.writeIfPossible text, x, point[1], (@config.layers[layer]?.margin or @config.labelMargin)
|
||||||
@canvas.text text, x, point[1], colorCode, false
|
@canvas.text text, x, point[1], colorCode, false
|
||||||
|
|
||||||
|
_scaleAndReduce: (points, scale) ->
|
||||||
|
lastX = null
|
||||||
|
lastY = null
|
||||||
|
scaled = []
|
||||||
|
|
||||||
|
for point in points
|
||||||
|
x = Math.floor point.x/scale
|
||||||
|
y = Math.floor point.y/scale
|
||||||
|
|
||||||
|
if lastX isnt x or lastY isnt y
|
||||||
|
lastY = y
|
||||||
|
lastX = x
|
||||||
|
scaled.push [x, y]
|
||||||
|
|
||||||
|
scaled
|
||||||
|
|
||||||
|
|
||||||
notify: (text) ->
|
notify: (text) ->
|
||||||
@_write "\r\x1B[K"+text
|
@_write "\r\x1B[K"+text
|
||||||
|
Loading…
Reference in New Issue
Block a user