Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/skywatch/brief/analysis/adverse_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def self.covers?(product, lat, lon)
return false if polygon.nil?

polygon.contains?(Skywatch::Shared::Geometry.point(lat, lon))
rescue RGeo::Error::InvalidGeometry
false
end

def self.within(items, lat:, lon:, radius_nm:)
Expand Down
2 changes: 2 additions & 0 deletions lib/skywatch/nimbus/models/outlook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def covers?(lat:, lon:)
return false if geometry.nil?

geometry.contains?(FACTORY.point(lon, lat))
rescue RGeo::Error::InvalidGeometry
false
end

def to_h # rubocop:disable Metrics/MethodLength
Expand Down
13 changes: 13 additions & 0 deletions spec/brief/analysis/adverse_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@
degenerate = Skywatch::Briefer::Models::Sigmet.new(coords: [])
expect(described_class.covers?(degenerate, 40.875, -74.282)).to be false
end

it 'returns false when the polygon is self-intersecting (RGeo InvalidGeometry)' do
# Bowtie ring: edges cross — RGeo raises Self-intersection on contains?
bowtie = Skywatch::Briefer::Models::Sigmet.new(coords: [
Skywatch::Shared::Position.new(lat: 40.0, lon: -74.0),
Skywatch::Shared::Position.new(lat: 41.0, lon: -73.0),
Skywatch::Shared::Position.new(lat: 40.0, lon: -73.0),
Skywatch::Shared::Position.new(lat: 41.0, lon: -74.0),
Skywatch::Shared::Position.new(lat: 40.0, lon: -74.0)
])
expect { described_class.covers?(bowtie, 40.5, -73.5) }.not_to raise_error
expect(described_class.covers?(bowtie, 40.5, -73.5)).to be false
end
end

describe '.within' do
Expand Down
14 changes: 14 additions & 0 deletions spec/nimbus/models/outlook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@
expect(mrgl.covers?(lat: 41.4, lon: -74.9)).to be(true)
expect(slgt.covers?(lat: 41.4, lon: -74.9)).to be(false)
end

it 'returns false when the geometry is self-intersecting (RGeo InvalidGeometry)' do
factory = described_class::FACTORY
bowtie_ring = factory.linear_ring([
factory.point(-74.0, 40.0),
factory.point(-73.0, 41.0),
factory.point(-73.0, 40.0),
factory.point(-74.0, 41.0),
factory.point(-74.0, 40.0)
])
bad = described_class.new(**attrs, geometry: factory.polygon(bowtie_ring))
expect { bad.covers?(lat: 40.5, lon: -73.5) }.not_to raise_error
expect(bad.covers?(lat: 40.5, lon: -73.5)).to be(false)
end
end

describe '#to_h' do
Expand Down