Java Distance Calculate distanceCircle(int i0, int i1, int dir, int size)

Here you can find the source of distanceCircle(int i0, int i1, int dir, int size)

Description

dist = (dir > 0 ) i1-i0 ?

License

Open Source License

Parameter

Parameter Description
i0 First point.
i1 Second point.
dir 0 > counting down, 0 < counting up
size a parameter

Declaration

public static int distanceCircle(int i0, int i1, int dir, int size) 

Method Source Code

//package com.java2s;
/*//from w  w w  .j a v  a2  s  . c  om
 * Copyright (c) 2011-2013, Peter Abeles. All Rights Reserved.
 *
 * This file is part of BoofCV (http://boofcv.org).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     *
     * dist = (dir > 0 ) i1-i0 ? i0-i1;
     * if( dist < 0 )
     *    distance = size+distance;
     *
     * @param i0 First point.
     * @param i1 Second point.
     * @param dir 0 > counting down, 0 < counting up
     * @param size
     * @return
     */
    public static int distanceCircle(int i0, int i1, int dir, int size) {

        int distance = (dir > 0) ? i1 - i0 : i0 - i1;

        if (distance < 0)
            distance = size + distance;

        return distance;
    }

    /**
     * Distance between two elements in a circular list.  The closest distance in either direction
     * is returned.
     *
     * @param i0
     * @param i1
     * @param size
     * @return
     */
    public static int distanceCircle(int i0, int i1, int size) {

        int distanceA = distanceCircle(i0, i1, 1, size);
        int distanceB = distanceCircle(i0, i1, -1, size);

        return Math.min(distanceA, distanceB);
    }
}

Related

  1. distanceBetweenPoints(double ax, double ay, double bx, double by)
  2. DistanceBetweenPoints(double x1, double y1, double x2, double y2)
  3. distanceBetweenPoints(float vx, float vy, float wx, float wy)
  4. distanceBetweenPoints(float[] xyz1, float[] xyz2)
  5. distanceByLBS(double lo1, double la1, double lo2, double la2)
  6. distanceCorrelation(final double[][] x, final double[][] y)
  7. distanceDamerauLevenshtein(CharSequence source, CharSequence target)
  8. distanceFast(double lat1, double lon1, double lat2, double lon2)
  9. distanceFrom(double lat1, double long1, double lat2, double long2)