Skip to content
Open
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
14 changes: 10 additions & 4 deletions lib/origin/selectable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,23 @@ def exists(criterion = nil)
# @note The only valid geometry shapes for a $geoIntersects are:
# :intersects_line, :intersects_point, and :intersects_polygon.
#
# @note The only valid geometry shape for a $geoWithin is :within_polygon
#
# @example Add a geo intersect criterion for a line.
# query.geo_spacial(:location.intersects_line => [[ 1, 10 ], [ 2, 10 ]])
#
# @example Add a geo intersect criterion for a point.
# query.geo_spacial(:location.intersects_point => [[ 1, 10 ]])
#
# @example Add a geo intersect criterion for a polygon.
# query.geo_spacial(:location.intersects_polygon => [[ 1, 10 ], [ 2, 10 ], [ 1, 10 ]])
# query.geo_spacial(:location.intersects_polygon => [[[ 1, 10 ], [ 2, 10 ], [ 1, 10 ]]])
#
# @example Add a geo within criterion for a polygon.
# query.geo_spacial(:location.within_polygon => [[ 1, 10 ], [ 2, 10 ], [ 1, 10 ]])
# query.geo_spacial(:location.within_polygon => [[[ 1, 10 ], [ 2, 10 ], [ 1, 10 ]]])
#
# @example Add a geo within criterian for a circle.
# query.geo_spacial(:location.within_circle => [[x, y], radius])
#
# @example Add a geo within criterian for a sphere. Radius specified in radians.
# query.geo_spacial(:location.within_sphere => [[x, y], radius])
#
# @param [ Hash ] criterion The criterion.
#
Expand All @@ -172,6 +176,8 @@ def geo_spacial(criterion = nil)
key :within_polygon, :override, "$geoWithin", "$geometry" do |value|
{ "type" => POLYGON, "coordinates" => value }
end
key :within_circle, :override, "$geoWithin", "$center"
key :within_sphere, :override, "$geoWithin", "$centerSphere"

# Add the $gt criterion to the selector.
#
Expand Down
40 changes: 40 additions & 0 deletions spec/origin/selectable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,46 @@ def localized?

it_behaves_like "a cloning selection"
end


context "when the geometry is a circle" do

let(:selection) do
query.geo_spacial(:location.within_circle => [[ 1, 10 ], 200])
end

it "adds the $center expression" do
expect(selection.selector).to eq({
"location" => {
"$geoWithin" => {
"$center" => [[1,10], 200]
}
}
})
end

it_behaves_like "a cloning selection"
end

context "when the geometry is a spherical circle" do

let(:selection) do
query.geo_spacial(:location.within_sphere => [[ 1, 10 ], 200])
end

it "adds the $center expression" do
expect(selection.selector).to eq({
"location" => {
"$geoWithin" => {
"$centerSphere" => [[1,10], 200]
}
}
})
end

it_behaves_like "a cloning selection"
end

end
end

Expand Down