Skip to content

Commit

Permalink
add code comments; index change
Browse files Browse the repository at this point in the history
  • Loading branch information
peetucket committed Nov 16, 2023
1 parent 93da09f commit 849309c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/iiif/v3/presentation/nav_place.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def rect_for(coordinate_parts)
end

def features
coordinates.map.with_index do |coordinate, index|
coordinates.map.with_index(1) do |coordinate, index|
{
id: "#{base_uri}/iiif/feature/#{index + 1}",
id: "#{base_uri}/iiif/feature/#{index}",
type: 'Feature',
properties: {},
geometry: coordinate.is_a?(Rect) ? polygon_geometry(coordinate) : point_geometry(coordinate)
Expand Down Expand Up @@ -89,6 +89,12 @@ def polygon_geometry(rect)
}
end

# @param [BigDecimal] coordinate value from geocoord gem
# @return [String] string formatted with max 6 digits after the decimal point
# The to_f ensures removal of scientific notation of BigDecimal before converting to a string.
# examples:
# input value is BigDecimal("-23.9") or "0.239e2", output value is "-23.9" as string
# input value is BigDecimal('23.9424213434') or "0.239424213434e2", output value is ""23.942421" as string
def format(decimal)
decimal.truncate(6).to_f.to_s
end
Expand Down

0 comments on commit 849309c

Please sign in to comment.