🚤 clamping polygon points to visible area, reducing points afterwards

pull/7/head
Michael Straßburger 2016-09-28 18:18:16 +02:00
rodzic 05558f0cdf
commit a2232a53dd
3 zmienionych plików z 13 dodań i 2 usunięć

Wyświetl plik

@ -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) ->

Wyświetl plik

@ -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: "🚗"

Wyświetl plik

@ -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) ->