public static boolean equalXValues(DiagramGraph g1, DiagramGraph g2) { if (g1.getNumValues() != g2.getNumValues()) { return false; } for (int i = 0; i < g1.getNumValues(); i++) { if (Math.abs(g1.getXValueAt(i) - g2.getXValueAt(i)) > 1.0e-10) { return false; } } return true; }
public static boolean equalXValues(DiagramGraph g1, DiagramGraph g2) { if (g1.getNumValues() != g2.getNumValues()) { return false; } for (int i = 0; i < g1.getNumValues(); i++) { if (Math.abs(g1.getXValueAt(i) - g2.getXValueAt(i)) > 1.0e-10) { return false; } } return true; }
private static void writeGraphGroup(List<DiagramGraph> graphGroup, Writer writer) throws IOException { DiagramGraph graph0 = graphGroup.get(0); writer.write(graph0.getXName()); for (DiagramGraph graph : graphGroup) { writer.write((int) '\t'); writer.write(graph.getYName()); } writer.write((int) '\n'); int numValues = graph0.getNumValues(); for (int i = 0; i < numValues; i++) { writer.write(String.valueOf(graph0.getXValueAt(i))); for (DiagramGraph graph : graphGroup) { writer.write((int) '\t'); writer.write(String.valueOf(graph.getYValueAt(i))); } writer.write((int) '\n'); } }
public double getY(DiagramGraph graph, double x) { int n = graph.getNumValues(); double x1, y1, x2 = 0, y2 = 0; for (int i = 0; i < n; i++) { x1 = x2; y1 = y2; x2 = graph.getXValueAt(i); y2 = graph.getYValueAt(i); if (i > 0) { if (x >= x1 && x <= x2) { return y1 + (x - x1) / (x2 - x1) * (y2 - y1); } } } throw new IllegalArgumentException("x out of bounds: " + x); }
private void writeGraphGroup(List<DiagramGraph> graphGroup, Writer writer) throws IOException { DiagramGraph graph0 = graphGroup.get(0); writer.write("Date"); writer.write((int) '\t'); writer.write(graph0.getXName()); for (DiagramGraph graph : graphGroup) { writer.write((int) '\t'); writer.write(graph.getYName()); } writer.write((int) '\n'); int numValues = graph0.getNumValues(); for (int i = 0; i < numValues; i++) { writer.write(toDate(graph0.getXValueAt(i))); writer.write((int) '\t'); writer.write(String.valueOf(graph0.getXValueAt(i))); for (DiagramGraph graph : graphGroup) { writer.write((int) '\t'); writer.write(String.valueOf(graph.getYValueAt(i))); } writer.write((int) '\n'); } }
public DiagramGraph getClosestGraph(int x, int y) { double minDist = Double.MAX_VALUE; Point2D.Double a = new Point2D.Double(); Point2D.Double b1 = new Point2D.Double(); Point2D.Double b2 = new Point2D.Double(); DiagramGraph closestGraph = null; for (DiagramGraph graph : getGraphs()) { double minDistGraph = Double.MAX_VALUE; int n = graph.getNumValues(); for (int i = 0; i < n; i++) { a.setLocation(graph.getXValueAt(i), graph.getYValueAt(i)); b1.setLocation(b2); transform.transformA2B(a, b2); if (i > 0) { Line2D.Double segment = new Line2D.Double(b1, b2); double v = segment.ptSegDist(x, y); if (v < minDistGraph) { minDistGraph = v; } } } if (minDistGraph < minDist) { minDist = minDistGraph; closestGraph = graph; } } return closestGraph; }
private Endmember[] convertGraphsToEndmembers(DiagramGraph[] diagramGraphs) { Endmember[] endmembers = new Endmember[diagramGraphs.length]; for (int i = 0; i < diagramGraphs.length; i++) { DiagramGraph diagramGraph = diagramGraphs[i]; int numValues = diagramGraph.getNumValues(); double[] wavelengths = new double[numValues]; double[] radiations = new double[numValues]; for (int j = 0; j < numValues; j++) { wavelengths[j] = diagramGraph.getXValueAt(j); radiations[j] = diagramGraph.getYValueAt(j); } endmembers[i] = new Endmember(diagramGraph.getYName(), wavelengths, radiations); } return endmembers; } }
int n = graph.getNumValues(); for (int i = 0; i < n; i++) { double xa = graph.getXValueAt(i); double ya = graph.getYValueAt(i); if (!Double.isNaN(ya)) { if (graph.getStyle().isShowingPoints()) { for (int i = 0; i < n; i++) { double xa = graph.getXValueAt(i); double ya = graph.getYValueAt(i); if (!Double.isNaN(ya)) {
private void assertEqualGraphs(DiagramGraph expectedGraph, DiagramGraph actualGraph) { assertNotNull(actualGraph); assertEquals(expectedGraph.getXName(), actualGraph.getXName()); assertEquals(expectedGraph.getYName(), actualGraph.getYName()); assertEquals(expectedGraph.getNumValues(), actualGraph.getNumValues()); for (int i = 0; i < expectedGraph.getNumValues(); i++) { assertEquals(expectedGraph.getXValueAt(i), actualGraph.getXValueAt(i), 1e-10); assertEquals(expectedGraph.getYValueAt(i), actualGraph.getYValueAt(i), 1e-10); } }