Returns the x, y coordinates at the cursor position or the nearest point as a String
(int x, int y)
| 4146 | |
| 4147 | /** Returns the x, y coordinates at the cursor position or the nearest point as a String */ |
| 4148 | @AstroImageJ(reason = "Fix coordinate lookup for scaled coordinates", modified = true) |
| 4149 | String getCoordinates(int x, int y) { |
| 4150 | if (frame==null) return ""; |
| 4151 | String text = ""; |
| 4152 | if ((isAijPlot() ? !frame.contains(x / Prefs.getGuiScale(), y / Prefs.getGuiScale()) : !frame.contains(x, y))) |
| 4153 | return text; |
| 4154 | double xv = descaleX(x); // cursor location |
| 4155 | double yv = descaleY(y); |
| 4156 | boolean yIsValue = false; |
| 4157 | if (!hasMultiplePlots()) { |
| 4158 | PlotObject p = getMainCurveObject(); // display x and f(x) instead of cursor y |
| 4159 | if (p != null) { |
| 4160 | double bestDx = Double.MAX_VALUE; |
| 4161 | double xBest = 0, yBest = 0; |
| 4162 | for (int i=0; i<Math.min(p.xValues.length, p.yValues.length); i++) { |
| 4163 | double xp = p.xValues[i]; |
| 4164 | if (Math.abs(xp-xv) < bestDx) { |
| 4165 | bestDx = Math.abs(xp-xv); |
| 4166 | xBest = xp; |
| 4167 | yBest = p.yValues[i]; |
| 4168 | } |
| 4169 | } |
| 4170 | if (Math.abs(scaleXtoPxl(xBest)-x) < 50) { //ignore points more than 50 pixels away in x |
| 4171 | xv = xBest; |
| 4172 | yv = yBest; |
| 4173 | yIsValue = true; |
| 4174 | } |
| 4175 | } |
| 4176 | } |
| 4177 | if (!Double.isNaN(xv)) { |
| 4178 | int significantDigits = logXAxis ? -2 : getDigits(xv, 0.001*(xMax-xMin), 6, 0); |
| 4179 | text = "X=" + IJ.d2s(xv, significantDigits)+", Y"; |
| 4180 | if (yIsValue) text += "(X)"; |
| 4181 | significantDigits = logYAxis ? -2 : getDigits(yv, 0.001*(yMax-yMin), 6, 0); |
| 4182 | text +="="+ IJ.d2s(yv, significantDigits); |
| 4183 | } |
| 4184 | return text; |
| 4185 | //}catch(Exception e){IJ.handleException(e);return "ERR";} |
| 4186 | } |
| 4187 | |
| 4188 | |
| 4189 | /** Returns a reference to the PlotObject having the data passed with the constructor or (if that was null) |
no test coverage detected