Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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;
            }

            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;
    }
}