Class RenderableScale


  • public class RenderableScale
    extends Object
    A helper class for transforming between screen coordinates and world coordinates. The x-axis and y-axis can be scaled independently from each other, causing expansion or compression of the y-axis relative to the x-axis.

    Copyright (c) 2020-2023 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information DSOL Manual. The DSOL project is distributed under a three-clause BSD-style license, which can be found at DSOL License.

    Author:
    Alexander Verbraeck
    • Constructor Detail

      • RenderableScale

        public RenderableScale​(double yScaleRatio,
                               double objectScaleFactor)
        Construct a translator between world coordinates and screen coordinates that uses a different scale factor for x and y.
        Parameters:
        yScaleRatio - double; the Y-scale ratio with respect to the X-scale (when yScale < 1 it results in a condensed Y-axis, where yScale > 1 results in an expanded Y-axis
        objectScaleFactor - double; the scale factor for the object, e.g., to get 1 pixel unit to equal 1 meter on a map. A scale factor smaller than 1 means that the object will be drawn smaller on the screen.
        Throws:
        IllegalArgumentException - when yScale <= 0
      • RenderableScale

        public RenderableScale​(double yScaleRatio)
        Construct a translator between world coordinates and screen coordinates that uses a different scale factor for x and y.
        Parameters:
        yScaleRatio - double; the Y-scale ratio with respect to the X-scale (when yScale < 1 it results in a condensed Y-axis, where yScale > 1 results in an expanded Y-axis
        Throws:
        IllegalArgumentException - when yScale <= 0
      • RenderableScale

        public RenderableScale()
        Construct a translator between world coordinates and screen coordinates that uses an X/Y ratio of 1.
        Throws:
        IllegalArgumentException - when yScale <= 0
    • Method Detail

      • getXScale

        public double getXScale​(Bounds2d extent,
                                Dimension screen)
        Returns the X-scale of a screen compared to an extent. If the height or the width of the screen are < 0 Double.NaN is returned.
        Parameters:
        extent - Rectangle2D; the extent of this animation
        screen - Dimension; the screen dimensions
        Returns:
        double; the scale. Can return Double.NaN
      • getYScale

        public double getYScale​(Bounds2d extent,
                                Dimension screen)
        Returns the Y-scale of a screen compared to an extent. If the height or the width of the screen are < 0 Double.NaN is returned.
        Parameters:
        extent - Rectangle2D; the extent of this animation
        screen - Dimension; the screen dimensions
        Returns:
        double; the scale. Can return Double.NaN
      • computeVisibleExtent

        public Bounds2d computeVisibleExtent​(Bounds2d extent,
                                             Dimension screen)
        computes the visible extent.
        Parameters:
        extent - Rectangle2D; the extent
        screen - Dimension; the screen
        Returns:
        a new extent or null if parameters are null or screen is invalid (width / height <= 0)
      • getScreenCoordinates

        public Point2D getScreenCoordinates​(Point<?> worldCoordinates,
                                            Bounds2d extent,
                                            Dimension screen)
        returns the frame xy-coordinates of a point in world coordinates. If parameters are invalid (i.e. screen.size <= 0) a null value is returned. If parameter combinations (i.e !extent.contains(point)) are invalid a null value is returned.
        Parameters:
        worldCoordinates - Point<?, ?>; the world coordinates
        extent - Bounds2d; the extent of this animation
        screen - Dimension; the screen dimentsions
        Returns:
        Point2D (x,y) on screen. Can be null.
      • getWorldCoordinates

        public Point2d getWorldCoordinates​(Point2D screenCoordinates,
                                           Bounds2d extent,
                                           Dimension screen)
        returns the frame xy-coordinates of a point in screen coordinates. If parameters are invalid (i.e. screen.size < 0) a null value is returned. If parameter combinations (i.e !screen.contains(point)) are invalid a null value is returned.
        Parameters:
        screenCoordinates - Point2D; the screen coordinates
        extent - Bounds2d; the extent of this animation
        screen - Dimension; the screen dimensions
        Returns:
        Point2d (x,y) in the 2D or 3D world
      • getYScaleRatio

        public double getYScaleRatio()
        Return the y-scale ratio. A number larger than 1 means the y-axis is compressed.
        Returns:
        double; the y-scale ratio. A number larger than 1 means the y-axis is compressed
      • getObjectScaleFactor

        public double getObjectScaleFactor()
        Return the scale factor for the object, e.g., to get 1 pixel unit to equal 1 meter on a map. A scale factor smaller than 1 means that the object will be drawn smaller on the screen.
        Returns:
        double; the scale factor for the object, e.g., to get 1 pixel unit to equal 1 meter on a map