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

it.unibo.alchemist.boundary.ui.impl.ExponentialZoomManager Maven / Gradle / Ivy

There is a newer version: 35.0.1
Show newest version
/*
 * Copyright (C) 2010-2022, Danilo Pianini and contributors
 * listed, for each module, in the respective subproject's build.gradle.kts file.
 *
 * This file is part of Alchemist, and is distributed under the terms of the
 * GNU General Public License, with a linking exception,
 * as described in the file LICENSE in the Alchemist distribution's top directory.
 */
package it.unibo.alchemist.boundary.ui.impl;

import it.unibo.alchemist.boundary.ui.api.ZoomManager;

/**
 * An ExpZoomManager converts the sliding of any physical/virtual
 * device/control into a zoom rate through an exponential function (in this way
 * I am sure to not see negative values ;-).
* Zoom = base ^ (amount of slides / normalization value). * */ public final class ExponentialZoomManager extends AbstractSlideInputManager implements ZoomManager { /** * DEF_BASE = "DEFault BASE".
* It is the default base for the exponential function. It is meant to be * greater than 1. Currently its value is {@value #DEF_BASE} that seems * pretty good to me. */ public static final double DEF_BASE = 1.1d; private double normal; private double base; /** * Calculates the initial amount of slides (i.e. value) to have * a zoom rate equal to z. * * @param z * is the desired zoom rate * @param b * is the base * @param n * is the normalization value * @return a double value representing the initial amount of * slides */ protected static double getSlideValueFromZoom(final double z, final double b, final double n) { if (z <= 0 || b <= 0) { throw new IllegalArgumentException("Not zoom nor the base can be zero or negative. (zoom=" + z + ", base=" + b + ")"); } return n * Math.log(z) / Math.log(b); } /** * Same of {@link #ExponentialZoomManager(double, double, double)} but normalization * value is 1. * * @param b * is the base of the exponential function * @param z * is the desired initial zoom rate */ public ExponentialZoomManager(final double z, final double b) { this(z, b, 1d); } /** * Initialize a new ExpZoomManager instance with the parameters * in input. * * @param z * is the desired initial zoom rate * @param b * is the base of the exponential function * @param n * is the normalization value */ public ExponentialZoomManager(final double z, final double b, final double n) { super(getSlideValueFromZoom(z, b, n), -Double.MAX_VALUE, Double.MAX_VALUE); normal = Math.abs(n); base = Math.abs(b); } /** * Allow any child class to see the base of the exponential. * * @return a double value representing the base of the * exponential */ protected double getBase() { return base; } /** * Allow any child class to see the normalization value. * * @return a double value representing the normalization value */ protected double getNormal() { return normal; } @Override public double getZoom() { final double val = getValue(); if (val == 0) { return 1d; } else if (val < 0) { return Math.pow(1 / base, -val / normal); } else { return Math.pow(base, val / normal); } } /** * Allow any child class to modify the base of the exponential. * * @param b * is the double value representing the base of the * exponential */ protected void setBase(final double b) { base = b; } /** * Allow any child class to modify the normalization value. * * @param n * is the double value representing the * normalization value */ protected void setNormal(final double n) { normal = n; } @Override public void setZoom(final double rate) { setValue(getSlideValueFromZoom(rate, base, normal)); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy