MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / findNearestXIndex

Method findNearestXIndex

src/test/PerformanceTests.java:64–85  ·  view source on GitHub ↗
(double x, double[] xpoints, double[] ypoints, int len, double min,
			double max)

Source from the content-addressed store, hash-verified

62 }
63
64 public static int findNearestXIndex(double x, double[] xpoints, double[] ypoints, int len, double min,
65 double max) {
66
67 x = Math.min(max, Math.max(min, x));
68
69 int imin = -1;
70 double dxmin = Double.MAX_VALUE;
71 for (int i = 0; i < len; i++) {
72 if (Double.isNaN(ypoints[i]))
73 continue;
74 double dx = Math.abs(x - xpoints[i]);
75 if (dx < dxmin) {
76 dxmin = dx;
77 imin = i;
78 }
79 }
80 if (xpoints[imin] < min)
81 imin++;
82 if (imin == len || xpoints[imin] > max)
83 imin = len - 1;
84 return imin;
85 }
86
87 public static int findNearestXIndex0(double x, double[] xpoints, double[] ypoints, int len, double min, double max) {
88

Callers 1

Calls 4

minMethod · 0.80
maxMethod · 0.80
isNaNMethod · 0.80
absMethod · 0.80

Tested by

no test coverage detected