Skip to content

Instantly share code, notes, and snippets.

@aaronang
Created October 19, 2018 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronang/3f88dc854ea3c96c7515f8a7e6ae3ebc to your computer and use it in GitHub Desktop.
Save aaronang/3f88dc854ea3c96c7515f8a7e6ae3ebc to your computer and use it in GitHub Desktop.
Just experimenting with RegionTrees
module Playground
using RegionTrees
import StaticArrays: SVector
const Point = SVector{2, Float32}
root = Cell(SVector(0., 0), SVector(1., 1), [
Point(0, 0),
Point(.5, .5),
Point(.5, .2),
Point(.3, .2),
Point(.8, .75)
])
function getdata(cell, indices)
println("boundary: $(child_boundary(cell, indices)), indices: $(indices)")
boundary = child_boundary(cell, indices)
xmin = boundary.origin[1]
xmax = xmin + boundary.widths[1]
ymin = boundary.origin[2]
ymax = ymin + boundary.widths[2]
println("xmin: $xmin, xmax: $xmax")
println("ymin: $ymin, ymax: $ymax")
function xinside(p)
if indices[1] == 1
xmin <= p[1] <= xmax
else
xmin < p[1] <= xmax
end
end
function yinside(p)
if indices[2] == 1
ymin <= p[2] < ymax
else
ymin <= p[2] <= ymax
end
end
inside(p) = xinside(p) && yinside(p)
data = [p for p in cell.data if inside(p)]
println(data)
return data
end
println("=============")
split!(root, getdata)
end # module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment