# Renderer
Date: 2020-11-15

de.hems.trafficsim

## Class Renderer

- java.lang.Object
- - de.hems.trafficsim.Renderer

    public class Renderer
    extends java.lang.Object

User interface class rendering the track history on a SurfaceView.

### Field Summary

Fields
`protected int` `height` height of the surface to draw to
`protected android.view.SurfaceHolder` `holder` holder of the surface the renderer draws to
`protected android.graphics.Paint` `paint` Paint instance of the renderer
`protected int` `pixelPerLine` height of a rectangle representing one vehicle
`protected int` `pixelPerVehicle` width of a rectangle representing one vehicle
`protected float` `tooShortPerHeight` amount of pixels per height which are lost by rounding
`protected float` `tooShortPerTrackLength` amount of pixels per track position which are lost by rounding
`protected Track` `track` the track to render
`protected int` `width` width of the surface to draw to

### Constructor Summary

Constructors
Constructor and Description
`Renderer(Track track, android.view.SurfaceHolder holder)` Constuctor for a Renderer.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected void` `draw()` Draws the current state of the track history to the Surface.
`protected int` `getColor(float curVelocity, float maxVelocity)` Utility function which calculates a color from the relation between the current speed of a vehicle and it's maximum speed (from red over yellow to green).
`void` `setSize(int width, int height)` Updates the dimension information of the renderer.
`void` `setTrack(Track track)` Updates the track of the Surface.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### track

    protected Track track

the track to render

#### pixelPerVehicle

    protected int pixelPerVehicle

width of a rectangle representing one vehicle

#### pixelPerLine

    protected int pixelPerLine

height of a rectangle representing one vehicle

#### tooShortPerTrackLength

    protected float tooShortPerTrackLength

amount of pixels per track position which are lost by rounding

#### tooShortPerHeight

    protected float tooShortPerHeight

amount of pixels per height which are lost by rounding

#### paint

    protected android.graphics.Paint paint

Paint instance of the renderer

#### holder

    protected android.view.SurfaceHolder holder

holder of the surface the renderer draws to

#### width

    protected int width

width of the surface to draw to

#### height

    protected int height

height of the surface to draw to

### Constructor Detail

#### Renderer

    public Renderer(Track track,
                    android.view.SurfaceHolder holder)

Constuctor for a Renderer.

Parameters:
  `track` - the track to render
  `holder` - the holder of the surface to draw to

### Method Detail

#### setSize

    public void setSize(int width,
                        int height)

Updates the dimension information of the renderer.

Parameters:
  `width` - the width of the SurfaceView
  `height` - the height of the SurfaceView

#### setTrack

    public void setTrack(Track track)

Updates the track of the Surface.

Parameters:
  `track` - the new track to render

#### getColor

    protected int getColor(float curVelocity,
                           float maxVelocity)

Utility function which calculates a color from the relation between the current speed of a vehicle and it's maximum speed (from red over yellow to green).

Parameters:
  `curVelocity` - current velocity of the vehicle
  `maxVelocity` - maximum velocity of the vehilce
Returns:
  color encoded as Android color integer

#### draw

    protected void draw()

Draws the current state of the track history to the Surface.