Here you can find the source of distanceCircle(int i0, int i1, int dir, int size)
Parameter | Description |
---|---|
i0 | First point. |
i1 | Second point. |
dir | 0 > counting down, 0 < counting up |
size | a parameter |
public static int distanceCircle(int i0, int i1, int dir, int size)
//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); } }