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

Method drawShapes

ij/src/main/java/ij/macro/Functions.java:2620–2673  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2618 //Example 10 boxes: ArrayList has 10 elements, each holding a float[6] for coordinates
2619 //Example 10 rectangles: ArrayList has 10 elements, each holding a float[4] for the corners
2620 double drawShapes() {
2621 String type = getFirstString().toLowerCase();
2622 double[][] arr2D = null;
2623 int nBoxes = 0;
2624 int nCoords = 0;
2625 if (type.contains("rectangles")) {
2626 nCoords = 4;//lefts, tops, rights, bottoms
2627 } else if (type.contains("boxes")) {
2628 nCoords = 6;//centers, Q1s, Q2s, Q3s, Q4s, Q5s (Q= quartile border)
2629 } else {
2630 interp.error("Must contain 'rectangles' or 'boxes'");
2631 return Double.NaN;
2632 }
2633 double[] arr = null;
2634 for (int jj = 0; jj < nCoords; jj++) {
2635 interp.getToken();
2636 if (interp.token == ',') {
2637 if (!isArrayArg()) {
2638 interp.putTokenBack();
2639 double singleVal = getNextArg();
2640 arr = new double[]{singleVal};//only 1 box
2641 } else {
2642 interp.putTokenBack();
2643 arr = getNextArray();//>= 2 boxes
2644 }
2645 nBoxes = arr.length;
2646 if (jj > 0 && arr2D[0].length != nBoxes) {
2647 interp.error("Arrays must have same length (" + nBoxes + ")");
2648 return Double.NaN;
2649 }
2650 if (arr2D == null) {
2651 arr2D = new double[nCoords][nBoxes];
2652 }
2653 for (int boxNo = 0; boxNo < nBoxes; boxNo++) {
2654 arr2D[jj][boxNo] = arr[boxNo];
2655 }
2656 }
2657 }
2658 interp.getRightParen();
2659 float[][] floatArr = new float[nCoords][nBoxes];
2660 for (int row = 0; row < nCoords; row++) {
2661 floatArr[row] = Tools.toFloat(arr2D[row]);
2662 }
2663 ArrayList shapeData = new ArrayList();
2664 for (int box = 0; box < nBoxes; box++) {
2665 float[] coords = new float[nCoords];
2666 for (int coord = 0; coord < nCoords; coord++) {
2667 coords[coord] = (float) (arr2D[coord][box]);
2668 }
2669 shapeData.add(coords);
2670 }
2671 plot.drawShapes(type, shapeData);
2672 return Double.NaN;
2673 }
2674
2675 double setPlotColor(Plot plot) {
2676 interp.getLeftParen();

Callers 1

doPlotMethod · 0.95

Calls 11

getFirstStringMethod · 0.95
isArrayArgMethod · 0.95
getNextArgMethod · 0.95
getNextArrayMethod · 0.95
toFloatMethod · 0.95
putTokenBackMethod · 0.80
getRightParenMethod · 0.80
addMethod · 0.65
containsMethod · 0.45
errorMethod · 0.45
getTokenMethod · 0.45

Tested by

no test coverage detected