MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / getCoordinates

Method getCoordinates

ij/src/main/java/ij/gui/Plot.java:4148–4186  ·  view source on GitHub ↗

Returns the x, y coordinates at the cursor position or the nearest point as a String

(int x, int y)

Source from the content-addressed store, hash-verified

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)

Callers 1

mouseMovedMethod · 0.45

Calls 12

isAijPlotMethod · 0.95
getGuiScaleMethod · 0.95
descaleXMethod · 0.95
descaleYMethod · 0.95
hasMultiplePlotsMethod · 0.95
getMainCurveObjectMethod · 0.95
scaleXtoPxlMethod · 0.95
getDigitsMethod · 0.95
d2sMethod · 0.95
containsMethod · 0.45
minMethod · 0.45
absMethod · 0.45

Tested by

no test coverage detected