diff --git a/src/Canvas.coffee b/src/Canvas.coffee index 4b18e2f..b5cbea8 100644 --- a/src/Canvas.coffee +++ b/src/Canvas.coffee @@ -16,6 +16,7 @@ glMatrix = require 'gl-matrix' earcut = require 'earcut' BrailleBuffer = require './BrailleBuffer' +utils = require './utils' vec2 = glMatrix.vec2 mat2d = glMatrix.mat2d @@ -56,8 +57,15 @@ module.exports = class Canvas # TODO: support for polygon holes polygon: (points, color) -> vertices = [] + lastPoint = [-1, -1] for point in points - vertices = vertices.concat @_project point[0], point[1] + point = @_project point[0], point[1] + point[0] = utils.clamp point[0], 0, @width + point[1] = utils.clamp point[1], 0, @height + + if point[0] isnt lastPoint[0] or point[1] isnt lastPoint[1] + vertices = vertices.concat point[0], point[1] + lastPoint = point triangles = earcut vertices extract = (pointId) -> diff --git a/src/Renderer.coffee b/src/Renderer.coffee index 51de27d..aed6cd8 100644 --- a/src/Renderer.coffee +++ b/src/Renderer.coffee @@ -19,7 +19,7 @@ module.exports = class Renderer labelMargin: 5 #"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: car: "🚗" diff --git a/src/utils.coffee b/src/utils.coffee index b34c33b..d6d2cb5 100644 --- a/src/utils.coffee +++ b/src/utils.coffee @@ -6,6 +6,9 @@ ### utils = + clamp: (num, min, max) -> + if num <= min then min else if num >= max then max else num + # Based on W. Randolph Franklin (WRF)'s Point Inclusion in Polygon Test # https://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html pointInPolygon: (polygon, point) ->