-
Notifications
You must be signed in to change notification settings - Fork 7
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
[Nearest Neighbor] Code and basic test for nearest neighbor #28
base: main
Are you sure you want to change the base?
Changes from 1 commit
dc58d40
efce65a
de89e18
b3d6034
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
let mindist p e = | ||
let x0, y0, x1, y1 = (x0 e, y0 e, x1 e, y1 e) in | ||
let gete ind = match ind with 0 -> x0 | 1 -> y0 | 2 -> x1 | _ -> y1 in | ||
let dist i = | ||
if get p i < gete i then (gete i -. get p i) *. (gete i -. get p i) | ||
else if get p i > gete (i + 2) then | ||
(get p i -. gete (i + 2)) *. (get p i -. gete (i + 2)) | ||
else 0. | ||
in | ||
dist 0 +. dist 1 | ||
|
||
let minmaxdist p e = | ||
let x0, y0, x1, y1 = (x0 e, y0 e, x1 e, y1 e) in | ||
let gete ind = match ind with 0 -> x0 | 1 -> y0 | 2 -> x1 | _ -> y1 in | ||
let rm k = | ||
if get p k <= (gete k +. gete (k + 2)) /. 2. then gete k else gete (k + 2) | ||
in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this file committed by mistake? If so can it be removed ? |
||
|
||
let rM k = | ||
if get p k >= (gete k +. gete (k + 2)) /. 2. then gete k else gete (k + 2) | ||
in | ||
|
||
let farthest_distance_axis i = (get p i -. rM i) *. (get p i -. rM i) in | ||
let farthest_distance = | ||
farthest_distance_axis 0 +. farthest_distance_axis 1 | ||
in | ||
let max_dist_axis i = | ||
farthest_distance | ||
-. ((get p i -. rM i) *. (get p i -. rM i)) | ||
+. ((get p i -. rm i) *. (get p i -. rm i)) | ||
in | ||
min (max_dist_axis 0) (max_dist_axis 1) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,9 @@ module Line = struct | |
let y0 = Float.min arr.(1) arr.(3) in | ||
let y1 = Float.max arr.(1) arr.(3) in | ||
Rtree.Rectangle.v ~x0 ~y0 ~x1 ~y1 | ||
|
||
let mindist _a _b= 0. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do run a |
||
let minmaxdist _a _b= 0. | ||
end | ||
|
||
module R = Rtree.Make (Rtree.Rectangle) (Line) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these need to be exposed in the interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to test these functions as well. Is that not necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that they're a part of the
Value
signature then we need them here and can be tested individually. Could we add some documentation strings to them ?minmaxdist
is a little opaque I think ?