This simply adds braces to clarify which mathematical operator comes
first.
Layout/LineLength:
Max: 270
Layout/LineLength:
Max: 270
-# Offense count: 62
-# Cop supports --auto-correct.
-Lint/AmbiguousOperatorPrecedence:
- Exclude:
- - 'app/controllers/geocoder_controller.rb'
- - 'app/models/user.rb'
- - 'lib/bounding_box.rb'
- - 'lib/osm.rb'
- - 'lib/rich_text.rb'
- - 'lib/short_link.rb'
- - 'test/controllers/api/old_nodes_controller_test.rb'
- - 'test/lib/short_link_test.rb'
-
# Offense count: 34
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
# Offense count: 34
# Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition:
def ddm_to_decdeg(captures)
begin
Float(captures[0])
def ddm_to_decdeg(captures)
begin
Float(captures[0])
- lat = captures[3].casecmp("s").zero? ? -(captures[0].to_f + captures[1].to_f / 60) : captures[0].to_f + captures[1].to_f / 60
- lon = captures[7].casecmp("w").zero? ? -(captures[4].to_f + captures[5].to_f / 60) : captures[4].to_f + captures[5].to_f / 60
+ lat = captures[3].casecmp("s").zero? ? -(captures[0].to_f + (captures[1].to_f / 60)) : captures[0].to_f + (captures[1].to_f / 60)
+ lon = captures[7].casecmp("w").zero? ? -(captures[4].to_f + (captures[5].to_f / 60)) : captures[4].to_f + (captures[5].to_f / 60)
- lat = captures[0].casecmp("s").zero? ? -(captures[1].to_f + captures[2].to_f / 60) : captures[1].to_f + captures[2].to_f / 60
- lon = captures[4].casecmp("w").zero? ? -(captures[5].to_f + captures[6].to_f / 60) : captures[5].to_f + captures[6].to_f / 60
+ lat = captures[0].casecmp("s").zero? ? -(captures[1].to_f + (captures[2].to_f / 60)) : captures[1].to_f + (captures[2].to_f / 60)
+ lon = captures[4].casecmp("w").zero? ? -(captures[5].to_f + (captures[6].to_f / 60)) : captures[5].to_f + (captures[6].to_f / 60)
end
{ :lat => lat, :lon => lon }
end
end
{ :lat => lat, :lon => lon }
end
def dms_to_decdeg(captures)
begin
Float(captures[0])
def dms_to_decdeg(captures)
begin
Float(captures[0])
- lat = captures[4].casecmp("s").zero? ? -(captures[0].to_f + (captures[1].to_f + captures[2].to_f / 60) / 60) : captures[0].to_f + (captures[1].to_f + captures[2].to_f / 60) / 60
- lon = captures[9].casecmp("w").zero? ? -(captures[5].to_f + (captures[6].to_f + captures[7].to_f / 60) / 60) : captures[5].to_f + (captures[6].to_f + captures[7].to_f / 60) / 60
+ lat = captures[4].casecmp("s").zero? ? -(captures[0].to_f + ((captures[1].to_f + (captures[2].to_f / 60)) / 60)) : captures[0].to_f + ((captures[1].to_f + (captures[2].to_f / 60)) / 60)
+ lon = captures[9].casecmp("w").zero? ? -(captures[5].to_f + ((captures[6].to_f + (captures[7].to_f / 60)) / 60)) : captures[5].to_f + ((captures[6].to_f + (captures[7].to_f / 60)) / 60)
- lat = captures[0].casecmp("s").zero? ? -(captures[1].to_f + (captures[2].to_f + captures[3].to_f / 60) / 60) : captures[1].to_f + (captures[2].to_f + captures[3].to_f / 60) / 60
- lon = captures[5].casecmp("w").zero? ? -(captures[6].to_f + (captures[7].to_f + captures[8].to_f / 60) / 60) : captures[6].to_f + (captures[7].to_f + captures[8].to_f / 60) / 60
+ lat = captures[0].casecmp("s").zero? ? -(captures[1].to_f + ((captures[2].to_f + (captures[3].to_f / 60)) / 60)) : captures[1].to_f + ((captures[2].to_f + (captures[3].to_f / 60)) / 60)
+ lon = captures[5].casecmp("w").zero? ? -(captures[6].to_f + ((captures[7].to_f + (captures[8].to_f / 60)) / 60)) : captures[6].to_f + ((captures[7].to_f + (captures[8].to_f / 60)) / 60)
end
{ :lat => lat, :lon => lon }
end
end
{ :lat => lat, :lon => lon }
end
account_age_in_hours = account_age_in_seconds / 3600
recent_messages = messages.where("sent_on >= ?", Time.now.utc - 3600).count
active_reports = issues.with_status(:open).sum(:reports_count)
account_age_in_hours = account_age_in_seconds / 3600
recent_messages = messages.where("sent_on >= ?", Time.now.utc - 3600).count
active_reports = issues.with_status(:open).sum(:reports_count)
- max_messages = account_age_in_hours.ceil + recent_messages - active_reports * 10
+ max_messages = account_age_in_hours.ceil + recent_messages - (active_reports * 10)
max_messages.clamp(0, Settings.max_messages_per_hour)
end
max_messages.clamp(0, Settings.max_messages_per_hour)
end
account_age_in_hours = account_age_in_seconds / 3600
recent_friends = Friendship.where(:befriendee => self).where("created_at >= ?", Time.now.utc - 3600).count
active_reports = issues.with_status(:open).sum(:reports_count)
account_age_in_hours = account_age_in_seconds / 3600
recent_friends = Friendship.where(:befriendee => self).where("created_at >= ?", Time.now.utc - 3600).count
active_reports = issues.with_status(:open).sum(:reports_count)
- max_friends = account_age_in_hours.ceil + recent_friends - active_reports * 10
+ max_friends = account_age_in_hours.ceil + recent_friends - (active_reports * 10)
max_friends.clamp(0, Settings.max_friends_per_hour)
end
max_friends.clamp(0, Settings.max_friends_per_hour)
end
if bbox.complete?
if bbox.min_lon < min_lon
@min_lon = [-SCALED_LON_LIMIT,
if bbox.complete?
if bbox.min_lon < min_lon
@min_lon = [-SCALED_LON_LIMIT,
- bbox.min_lon + margin * (min_lon - max_lon)].max
+ bbox.min_lon + (margin * (min_lon - max_lon))].max
end
if bbox.min_lat < min_lat
@min_lat = [-SCALED_LAT_LIMIT,
end
if bbox.min_lat < min_lat
@min_lat = [-SCALED_LAT_LIMIT,
- bbox.min_lat + margin * (min_lat - max_lat)].max
+ bbox.min_lat + (margin * (min_lat - max_lat))].max
end
if bbox.max_lon > max_lon
@max_lon = [+SCALED_LON_LIMIT,
end
if bbox.max_lon > max_lon
@max_lon = [+SCALED_LON_LIMIT,
- bbox.max_lon + margin * (max_lon - min_lon)].min
+ bbox.max_lon + (margin * (max_lon - min_lon))].min
end
if bbox.max_lat > max_lat
@max_lat = [+SCALED_LAT_LIMIT,
end
if bbox.max_lat > max_lat
@max_lat = [+SCALED_LAT_LIMIT,
- bbox.max_lat + margin * (max_lat - min_lat)].min
+ bbox.max_lat + (margin * (max_lat - min_lat))].min
end
def slippy_width(zoom)
end
def slippy_width(zoom)
- width * 256.0 * 2.0**zoom / 360.0
+ width * 256.0 * (2.0**zoom) / 360.0
end
def slippy_height(zoom)
min = min_lat * Math::PI / 180.0
max = max_lat * Math::PI / 180.0
end
def slippy_height(zoom)
min = min_lat * Math::PI / 180.0
max = max_lat * Math::PI / 180.0
- Math.log((Math.tan(max) + 1.0 / Math.cos(max)) /
- (Math.tan(min) + 1.0 / Math.cos(min))) *
- (128.0 * 2.0**zoom / Math::PI)
+ Math.log((Math.tan(max) + (1.0 / Math.cos(max))) /
+ (Math.tan(min) + (1.0 / Math.cos(min)))) *
+ (128.0 * (2.0**zoom) / Math::PI)
end
# there are two forms used for bounds with and without an underscore,
end
# there are two forms used for bounds with and without an underscore,
yscale = ysize / height
scale = [xscale, yscale].max
yscale = ysize / height
scale = [xscale, yscale].max
- xpad = width * scale - xsize
- ypad = height * scale - ysize
+ xpad = (width * scale) - xsize
+ ypad = (height * scale) - ysize
@width = width
@height = height
@width = width
@height = height
- @tx = xsheet(min_lon) - xpad / 2
- @ty = ysheet(min_lat) - ypad / 2
+ @tx = xsheet(min_lon) - (xpad / 2)
+ @ty = ysheet(min_lat) - (ypad / 2)
- @bx = xsheet(max_lon) + xpad / 2
- @by = ysheet(max_lat) + ypad / 2
+ @bx = xsheet(max_lon) + (xpad / 2)
+ @by = ysheet(max_lat) + (ypad / 2)
end
# the following two functions will give you the x/y on the entire sheet
def ysheet(lat)
end
# the following two functions will give you the x/y on the entire sheet
def ysheet(lat)
- log(tan(PI / 4 + (lat * PI / 180 / 2))) / (PI / 180)
+ log(tan((PI / 4) + (lat * PI / 180 / 2))) / (PI / 180)
def distance(lat, lon)
lat = lat * PI / 180
lon = lon * PI / 180
def distance(lat, lon)
lat = lat * PI / 180
lon = lon * PI / 180
- 6372.795 * 2 * asin(sqrt(sin((lat - @lat) / 2)**2 + cos(@lat) * cos(lat) * sin((lon - @lon) / 2)**2))
+ 6372.795 * 2 * asin(sqrt((sin((lat - @lat) / 2)**2) + (cos(@lat) * cos(lat) * (sin((lon - @lon) / 2)**2))))
end
# get the worst case bounds for a given radius from the base position
end
# get the worst case bounds for a given radius from the base position
latradius = 2 * asin(sqrt(sin(radius / 6372.795 / 2)**2))
begin
latradius = 2 * asin(sqrt(sin(radius / 6372.795 / 2)**2))
begin
- lonradius = 2 * asin(sqrt(sin(radius / 6372.795 / 2)**2 / cos(@lat)**2))
+ lonradius = 2 * asin(sqrt((sin(radius / 6372.795 / 2)**2) / (cos(@lat)**2)))
rescue Errno::EDOM, Math::DomainError
lonradius = PI
end
rescue Errno::EDOM, Math::DomainError
lonradius = PI
end
doc.content.include?(phrase)
end
doc.content.include?(phrase)
end
- [link_proportion - 0.2, 0.0].max * 200 +
- link_count * 40 +
- spammy_phrases * 40
+ ([link_proportion - 0.2, 0.0].max * 200) +
+ (link_count * 40) +
+ (spammy_phrases * 40)
y <<= (32 - z)
# project the parameters back to their coordinate ranges.
y <<= (32 - z)
# project the parameters back to their coordinate ranges.
- [(x * 360.0 / 2**32) - 180.0,
- (y * 180.0 / 2**32) - 90.0,
+ [(x * 360.0 / (2**32)) - 180.0,
+ (y * 180.0 / (2**32)) - 90.0,
z - 8 - (z_offset % 3)]
end
##
# given a location and zoom, return a short string representing it.
def encode(lon, lat, z)
z - 8 - (z_offset % 3)]
end
##
# given a location and zoom, return a short string representing it.
def encode(lon, lat, z)
- code = interleave_bits(((lon + 180.0) * 2**32 / 360.0).to_i,
- ((lat + 90.0) * 2**32 / 180.0).to_i)
+ code = interleave_bits(((lon + 180.0) * (2**32) / 360.0).to_i,
+ ((lat + 90.0) * (2**32) / 180.0).to_i)
str = ""
# add eight to the zoom level, which approximates an accuracy of
# one pixel in a tile.
((z + 8) / 3.0).ceil.times do |i|
str = ""
# add eight to the zoom level, which approximates an accuracy of
# one pixel in a tile.
((z + 8) / 3.0).ceil.times do |i|
- digit = (code >> (58 - 6 * i)) & 0x3f
+ digit = (code >> (58 - (6 * i))) & 0x3f
str << ARRAY[digit]
end
# append characters onto the end of the string to represent
str << ARRAY[digit]
end
# append characters onto the end of the string to represent
# randomly move the node about
3.times do
# move the node somewhere else
# randomly move the node about
3.times do
# move the node somewhere else
- xml_node["lat"] = precision(rand * 180 - 90).to_s
- xml_node["lon"] = precision(rand * 360 - 180).to_s
+ xml_node["lat"] = precision((rand * 180) - 90).to_s
+ xml_node["lon"] = precision((rand * 360) - 180).to_s
with_controller(NodesController.new) do
put api_node_path(:id => nodeid), :params => xml_doc.to_s, :headers => auth_header
assert_response :forbidden, "Should have rejected node update"
with_controller(NodesController.new) do
put api_node_path(:id => nodeid), :params => xml_doc.to_s, :headers => auth_header
assert_response :forbidden, "Should have rejected node update"
# randomly move the node about
3.times do
# move the node somewhere else
# randomly move the node about
3.times do
# move the node somewhere else
- xml_node["lat"] = precision(rand * 180 - 90).to_s
- xml_node["lon"] = precision(rand * 360 - 180).to_s
+ xml_node["lat"] = precision((rand * 180) - 90).to_s
+ xml_node["lon"] = precision((rand * 360) - 180).to_s
with_controller(NodesController.new) do
put api_node_path(:id => nodeid), :params => xml_doc.to_s, :headers => auth_header
assert_response :success
with_controller(NodesController.new) do
put api_node_path(:id => nodeid), :params => xml_doc.to_s, :headers => auth_header
assert_response :success
def test_encode_decode
cases = []
1000.times do
def test_encode_decode
cases = []
1000.times do
- cases << [180.0 * rand - 90.0, 360.0 * rand - 180.0, (18 * rand).to_i]
+ cases << [(180.0 * rand) - 90.0, (360.0 * rand) - 180.0, (18 * rand).to_i]
end
cases.each do |lat, lon, zoom|
end
cases.each do |lat, lon, zoom|
# one pixel (i.e: zoom + 8). the sqrt(5) is because each position
# has an extra bit of accuracy in the lat coordinate, due to the
# smaller range.
# one pixel (i.e: zoom + 8). the sqrt(5) is because each position
# has an extra bit of accuracy in the lat coordinate, due to the
# smaller range.
- distance = Math.sqrt((lat - lat2)**2 + (lon - lon2)**2)
+ distance = Math.sqrt(((lat - lat2)**2) + ((lon - lon2)**2))
max_distance = 360.0 / (1 << (zoom + 8)) * 0.5 * Math.sqrt(5)
assert max_distance > distance, "Maximum expected error exceeded: #{max_distance} <= #{distance} for (#{lat}, #{lon}, #{zoom})."
end
max_distance = 360.0 / (1 << (zoom + 8)) * 0.5 * Math.sqrt(5)
assert max_distance > distance, "Maximum expected error exceeded: #{max_distance} <= #{distance} for (#{lat}, #{lon}, #{zoom})."
end