Java Vector vectorDir(int vert, int horiz)

Here you can find the source of vectorDir(int vert, int horiz)

Description

vector Dir

License

Open Source License

Declaration

public static int vectorDir(int vert, int horiz) 

Method Source Code

//package com.java2s;
//it under the terms of the GNU Affero General Public License as published by

public class Main {
    private static final int VERTICAL_COMPONENT[] = { 0, 1, 1, 0, 5, 5, 5, 0, 1 };
    private static final int HORIZONTAL_COMPONENT[] = { 0, 0, 3, 3, 3, 0, 7, 7, 7 };
    /** Lookup table with combined v/h directions using {@code h+v%3} as index. */
    private static final int VECTOR_LOOKUP[] = { 0, 1, 5, 3, 2, 4, -1, 7, 8, 6 };

    public static int vectorDir(int vert, int horiz) {
        int v = verticalDir(vert);
        int h = horizontalDir(horiz);
        if (vert != v && horiz != h) {
            throw new IllegalArgumentException("Invalid directions");
        }/*  www.  j  av  a 2s . c  om*/
        return VECTOR_LOOKUP[h + v % 3];
    }

    /**
     * Extracts the vertical component of the direction
     * @return NORTH, SOUTH or CENTER
     */
    public static int verticalDir(int direction) {
        checkDirection(direction);
        return VERTICAL_COMPONENT[direction];
    }

    /**
     * Extracts the horizontal component of the direction.
     * @return WEST, EAST or CENTER.
     */
    public static int horizontalDir(int direction) {
        checkDirection(direction);
        return HORIZONTAL_COMPONENT[direction];
    }

    private static void checkDirection(int direction) {
        if (direction < 0 || direction > 8) {
            throw new IllegalArgumentException("Argument (" + direction + ") must be a Swing direction constant");
        }
    }
}

Related

  1. vector_norm(double[] vec)
  2. vector_sum(double[] v, double[] w)
  3. vectorAbsoluteValue(double X, double Y, double Z)
  4. vectorCos(int[] d1, int[] d2)
  5. vectorDiff(final double[] vecOne, final double[] vecTwo)
  6. vectorDistance(double[] vec1, double[] vec2, double power)
  7. vectorIndexToUpperTriangularIndices(int numberOfRows, int index)
  8. vectorKLDivergence(double v1[], double v2[])
  9. vectorL2Norm(double[] v)