Created
October 19, 2018 17:11
-
-
Save aaronang/3f88dc854ea3c96c7515f8a7e6ae3ebc to your computer and use it in GitHub Desktop.
Just experimenting with RegionTrees
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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