Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tackle NonLocalExitFromIterator and BlockNesting rubocop todos #356

Merged
merged 3 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 0 additions & 11 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,11 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
Lint/NonLocalExitFromIterator:
Exclude:
- 'lib/rgeo/geos/ffi_factory.rb'

# Offense count: 141
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 180

# Offense count: 4
# Configuration parameters: CountBlocks.
Metrics/BlockNesting:
Exclude:
- 'lib/rgeo/feature/types.rb'

# Offense count: 60
Style/Documentation:
Enabled: false
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

**Minor Changes**

* Fix Lint/NonLocalExitFromIterator and Metrics/BlockNesting from rubocop_todos. (@teckwan) #356
* Fix Naming/VariableNumber from rubocop_todos. (@haroon26) #351
* Fix Lint/MissingSuper from rubocop_todos. (@haroon26) #352
* Drop support for Ruby 2.6. (@seuros) #353
Expand Down
24 changes: 9 additions & 15 deletions lib/rgeo/feature/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,15 @@ def cast(obj, *params)
if nfactory == factory
force_new ? obj.dup : obj
elsif type == Point
cs = ncs = nil
if project
cs = factory.coord_sys
ncs = nfactory.coord_sys
end
hasz = factory.property(:has_z_coordinate)
nhasz = nfactory.property(:has_z_coordinate)
if cs && ncs
coords = cs.transform_coords(ncs, obj.x, obj.y, hasz ? obj.z : nil)
coords << (hasz ? obj.z : 0.0) if nhasz && coords.size < 3
else
coords = [obj.x, obj.y]
coords << (hasz ? obj.z : 0.0) if nhasz
end
coords << (factory.property(:has_m_coordinate) ? obj.m : 0.0) if nfactory.property(:has_m_coordinate)
z = factory.property(:has_z_coordinate) ? obj.z : nil
coords = if project && (cs = factory.coord_sys) && (ncs = nfactory.coord_sys)
cs.transform_coords(ncs, obj.x, obj.y, z)
else
[obj.x, obj.y]
end
coords << (z || 0.0) if nfactory.property(:has_z_coordinate) && coords.size < 3
m = factory.property(:has_m_coordinate) ? obj.m : nil
coords << (m || 0.0) if nfactory.property(:has_m_coordinate)
nfactory.point(*coords)
elsif type == Line
nfactory.line(cast(obj.start_point, nfactory, opts), cast(obj.end_point, nfactory, opts))
Expand Down
14 changes: 6 additions & 8 deletions lib/rgeo/geos/ffi_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,8 @@ def polygon(outer_ring, inner_rings = nil)
inner_rings = inner_rings.to_a unless inner_rings.is_a?(Array)
return unless RGeo::Feature::LineString.check_type(outer_ring)
outer_ring = create_fg_linear_ring(outer_ring.points)
inner_rings = inner_rings.map do |r|
return unless RGeo::Feature::LineString.check_type(r)
create_fg_linear_ring(r.points)
end
return unless inner_rings.all? { |r| RGeo::Feature::LineString.check_type(r) }
inner_rings = inner_rings.map { |r| create_fg_linear_ring(r.points) }
inner_rings.compact!
fg_geom = ::Geos::Utils.create_polygon(outer_ring, *inner_rings)
FFIPolygonImpl.new(self, fg_geom, nil)
Expand Down Expand Up @@ -327,16 +325,16 @@ def collection(elems)
def multi_point(elems)
elems = elems.to_a unless elems.is_a?(Array)
elems = elems.map do |elem|
elem = RGeo::Feature.cast(
RGeo::Feature.cast(
elem,
self,
RGeo::Feature::Point,
:force_new,
:keep_subtype
)
return unless elem
elem.detach_fg_geom
end
return unless elems.all?
elems = elems.map(&:detach_fg_geom)
klasses = Array.new(elems.size, FFIPointImpl)
fg_geom = ::Geos::Utils.create_collection(::Geos::GeomTypes::GEOS_MULTIPOINT, elems)
FFIMultiPointImpl.new(self, fg_geom, klasses)
Expand Down Expand Up @@ -485,8 +483,8 @@ def create_fg_linear_ring(points)
size += 1
end
cs = ::Geos::CoordinateSequence.new(size, 3)
return unless points.all? { |p| RGeo::Feature::Point.check_type(p) }
points.each_with_index do |p, i|
return unless RGeo::Feature::Point.check_type(p)
cs.set_x(i, p.x)
cs.set_y(i, p.y)
if @has_z
Expand Down