Here you can find the source of vectorDir(int vert, int horiz)
public static int vectorDir(int vert, int horiz)
//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"); } } }