All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.qozix.tileview.tiles.selector.TileSetSelectorClosest Maven / Gradle / Ivy

Go to download

The TileView widget is a subclass of ViewGroup that provides a mechanism to asynchronously display tile-based images, with additional functionality for 2D dragging, flinging, pinch or double-tap to zoom, adding overlaying Views (markers), built-in Hot Spot support, dynamic path drawing, multiple levels of detail, and support for any relative positioning or coordinate system.

The newest version!
package com.qozix.tileview.tiles.selector;

import com.qozix.tileview.detail.DetailLevel;
import com.qozix.tileview.detail.DetailLevelSet;

public class TileSetSelectorClosest implements TileSetSelector {

	@Override
	public DetailLevel find( double scale, DetailLevelSet levels ) {
		// fast-fail
		if ( levels.size() == 0 ) {
			return null;
		}

		// default to first item
		DetailLevel match = null;
		double diffToMatch = 0d;

		// loop through and find the "closest"
		for ( final DetailLevel thisLevel : levels ) {
			if ( match == null ) {
				// default to the first value found
				match = thisLevel;
				diffToMatch = Math.abs( scale - match.getScale() );
				continue;
			}

			// calculate the diff from current level to requested scale
			final double diffToCurrent = Math.abs( scale - thisLevel.getScale() );
			if ( diffToCurrent < diffToMatch ) {
				match = thisLevel;
				diffToMatch = diffToCurrent;
			}
		}

		return match;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy