mirror of
https://github.com/rastapasta/mapscii.git
synced 2025-03-19 16:36:55 +01:00
🚤 clamping polygon points to visible area, reducing points afterwards
This commit is contained in:
parent
05558f0cdf
commit
a2232a53dd
@ -16,6 +16,7 @@ glMatrix = require 'gl-matrix'
|
|||||||
earcut = require 'earcut'
|
earcut = require 'earcut'
|
||||||
|
|
||||||
BrailleBuffer = require './BrailleBuffer'
|
BrailleBuffer = require './BrailleBuffer'
|
||||||
|
utils = require './utils'
|
||||||
|
|
||||||
vec2 = glMatrix.vec2
|
vec2 = glMatrix.vec2
|
||||||
mat2d = glMatrix.mat2d
|
mat2d = glMatrix.mat2d
|
||||||
@ -56,8 +57,15 @@ module.exports = class Canvas
|
|||||||
# TODO: support for polygon holes
|
# TODO: support for polygon holes
|
||||||
polygon: (points, color) ->
|
polygon: (points, color) ->
|
||||||
vertices = []
|
vertices = []
|
||||||
|
lastPoint = [-1, -1]
|
||||||
for point in points
|
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
|
triangles = earcut vertices
|
||||||
extract = (pointId) ->
|
extract = (pointId) ->
|
||||||
|
@ -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: "🚗"
|
||||||
|
@ -6,6 +6,9 @@
|
|||||||
###
|
###
|
||||||
|
|
||||||
utils =
|
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
|
# Based on W. Randolph Franklin (WRF)'s Point Inclusion in Polygon Test
|
||||||
# https://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
# https://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
||||||
pointInPolygon: (polygon, point) ->
|
pointInPolygon: (polygon, point) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user