Open
Description
Summary
The eql?
method in the ProjectedWindow
class contains a critical bug where an assignment operator (=
) is used instead of a comparison operator (==
) when comparing the y_min
values.
Location
File: lib/rgeo/geographic/projected_window.rb
Line: ~68
Method: eql?
Bug Details
def eql?(other) # :nodoc:
return false unless other.is_a?(ProjectedWindow)
@factory == other.factory && @x_min == other.x_min && @x_max == other.x_max &&
@y_min = other.y_min && @y_max = other.y_max # BUG: should be ==
end
The issue is on the line with @y_min = other.y_min
which should be @y_min == other.y_min
.
Expected Behavior
The eql?
method should compare two ProjectedWindow
objects for equality without modifying either object, returning true
if all corresponding attributes are equal and false
otherwise.
Actual Behavior
- Incorrect return value: The method returns the value of
other.y_min
instead of a proper boolean comparison result - Side effect: The method modifies the current object's
@y_min
value during comparison, which is unexpected behavior for an equality check - Broken equality logic: The comparison logic is fundamentally broken due to the assignment
Steps to Reproduce
require 'rgeo'
# Create a geographic factory
factory = RGeo::Geographic.spherical_factory(srid: 4326)
# Create two identical projected windows
window1 = RGeo::Geographic::ProjectedWindow.new(factory, 0, 0, 10, 10)
window2 = RGeo::Geographic::ProjectedWindow.new(factory, 0, 0, 10, 10)
# Store original y_min value
original_y_min = window1.y_min
# Call eql? - this should not modify window1
result = window1.eql?(window2)
# Check if window1 was unexpectedly modified
puts "Original y_min: #{original_y_min}"
puts "Current y_min: #{window1.y_min}"
puts "Equality result: #{result}"
puts "Window1 was modified: #{original_y_min != window1.y_min}"
Suggested Fix
Change line ~68 from:
@y_min = other.y_min && @y_max = other.y_max
to:
@y_min == other.y_min && @y_max == other.y_max
Metadata
Metadata
Assignees
Labels
No labels