Java List Size getSize(List positions)

Here you can find the source of getSize(List positions)

Description

get Size

License

Open Source License

Declaration

public static double[] getSize(List<int[]> positions) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.List;

public class Main {
    private double[] size;

    public static double[] getSize(List<int[]> positions) {
        if (positions.size() > 0) {
            int[] min = getExtremeCoords(positions, true);
            int[] max = getExtremeCoords(positions, false);

            double[] result = new double[min.length];
            for (int i = 0; i < min.length; i++) {
                result[i] = (float) (max[i] - min[i] + 1) * 0.5f;
            }//w  w w  . j ava  2s. c  o  m

            return result;
        }

        return null;
    }

    public static int[] getExtremeCoords(List<int[]> positions, boolean min) {
        if (positions.size() > 0) {
            int[] selectedPos = positions.get(0).clone();

            for (int n = 1; n < positions.size(); n++) {
                int[] position = positions.get(n);

                for (int i = 0; i < selectedPos.length; i++) {
                    selectedPos[i] = min ? Math.min(position[i],
                            selectedPos[i]) : Math.max(position[i],
                            selectedPos[i]);
                }
            }

            return selectedPos;
        }

        return null;
    }
}

Related

  1. getSize(List list)
  2. getSize(List list)
  3. getSize(List sourceList)
  4. getSize(List sourceList)
  5. size(List list)
  6. size(Object[] list)