Java Distance Calculate dist(int i, int j, int width)

Here you can find the source of dist(int i, int j, int width)

Description

dist

License

Open Source License

Declaration

public static int dist(int i, int j, int width) 

Method Source Code

//package com.java2s;
/**//from  w w  w.  j  av a 2 s . co  m
 * Bot for the 7th programming contest of freiesMagazin.
 * Copyright (c) 2014 Martin Scharm -- <software@binfalse.de>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static int dist(int i, int j, int width) {
        int dX = abs(i % width - j % width);
        int dY = abs(i / width - j / width);
        return dX + dY;

    }

    /**
     * Absolute value of an int.
     * 
     * @param a
     *          the int
     * @return a or -a
     */
    public static final int abs(int a) {
        return a < 0 ? -a : a;
    }
}

Related

  1. dist(float x1, float y1, float x2, float y2)
  2. dist(float x1, float y1, float x2, float y2)
  3. dist(float x1, float y1, float x2, float y2)
  4. dist(float x1, float y1, float x2, float y2, float xp, float yp)
  5. dist(float x1, float y1, float z1, float x2, float y2, float z2)
  6. dist(int p1, int p2)
  7. dist(int x1, int y1, int x2, int y2)
  8. dist14(double d12, double d23, double d34, double theta123, double theta234, double phi)
  9. dist2Degrees(double dist, double radius)