diff --git a/LICENSE b/LICENSE index 244ebdb..7aca136 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2019-2022 Anton Maminov +Copyright (c) 2019-2023 Anton Maminov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/shard.yml b/shard.yml index 04b8edc..1416dd4 100644 --- a/shard.yml +++ b/shard.yml @@ -8,6 +8,7 @@ dependencies: github: geocrystal/haversine convex_hull: github: geocrystal/convex_hull + version: ">= 0.6.0" geohash: github: geocrystal/geohash diff --git a/src/geo/coord.cr b/src/geo/coord.cr index 094fa4b..22c8e16 100644 --- a/src/geo/coord.cr +++ b/src/geo/coord.cr @@ -121,12 +121,17 @@ module Geo # pos.strfcoord('%latd %latm %0.5lats') # => "0 1 59.99880" # pos.strfcoord('%latd %latm %lats') # => "0 2 0" # ``` - def strfcoord(formatstr) + def strfcoord(formatstr) : String h = full_hash DIRECTIVES.reduce(formatstr) do |memo, (from, to)| memo.gsub(from) do - to = to.call($~) if to.is_a?(Proc) + to = + if to.is_a?(Proc) && from.is_a?(Regex) && (match_data = memo.match(from)) + to.call(match_data) + else + to.as(String) + end res = to % h diff --git a/src/geo/polygon.cr b/src/geo/polygon.cr index b818563..c711ff4 100644 --- a/src/geo/polygon.cr +++ b/src/geo/polygon.cr @@ -128,7 +128,7 @@ module Geo private def make_convex_hull(coords : Array(Geo::Coord)) points = @coords.map { |coord| {coord.lat, coord.lng} } convex_hull = ConvexHull::GrahamScan.new(points) - hull = convex_hull.convex_hull + hull = convex_hull.to_a hull.map { |point| Geo::Coord.new(point.x.as(Float32 | Float64), point.y.as(Float32 | Float64)) } end