The minimum of the maximum possible distance from the query to the rectangle @param p the query point @param r the rectangle compute the distance to @return the minimum of the maximum distance from the point to the rectangle
(Vec p, Rectangle r)
| 886 | * @return the minimum of the maximum distance from the point to the rectangle |
| 887 | */ |
| 888 | @SuppressWarnings("unused") |
| 889 | private double minMaxDist(Vec p, Rectangle r) |
| 890 | { |
| 891 | if(r.contains(p)) |
| 892 | return 0; |
| 893 | /* |
| 894 | * MinMaxDist is usualy describe with the minimum over another loop, explicisty as the euclidant distance |
| 895 | * Instead, we prepare a single vector for each loop (k), and set its values accordinly (with index k being an exception in the value set) |
| 896 | * We then compute the distance metric and select the min for each k |
| 897 | */ |
| 898 | |
| 899 | double minDist = Double.MAX_VALUE; |
| 900 | for(int k = 0; k < dim; k++) |
| 901 | { |
| 902 | //setUp vector |
| 903 | for(int j = 0; j < dim; j++) |
| 904 | { |
| 905 | double pj = p.get(j); |
| 906 | double sj = r.lB.get(j); |
| 907 | double tj = r.uB.get(j); |
| 908 | if (j == k)//rm_k |
| 909 | if (pj <= (sj + tj) * 0.5) |
| 910 | dcScratch.set(j, sj); |
| 911 | else |
| 912 | dcScratch.set(j, tj); |
| 913 | else |
| 914 | { |
| 915 | if(pj >= (sj+tj)*0.5) |
| 916 | dcScratch.set(j, sj); |
| 917 | else |
| 918 | dcScratch.set(j, tj); |
| 919 | } |
| 920 | } |
| 921 | //Now just compute distance |
| 922 | double dist = dm.dist(p, dcScratch); |
| 923 | minDist = Math.min(dist, minDist); |
| 924 | } |
| 925 | |
| 926 | return minDist; |
| 927 | } |
| 928 | |
| 929 | /** |
| 930 | * The maximal distance possible between the query point and the edge of the given rectangle farthest from the point. |