Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/adi3120/Fazen2d/llms.txt

Use this file to discover all available pages before exploring further.

MathUtils is a small static utility class with a linear range mapping function and the mathematical constant pi. All members are static — no instance is needed. It is commonly used to convert between coordinate spaces, drive wave-based animations, and scale game values such as health or progress bars.
#include "include/headers/MathUtils.h"  // included automatically via Fazen.h

Members

MemberTypeValue / SignatureDescription
pistatic constexpr double3.141592653589793238Mathematical constant π
Mapstatic floatMap(float value, float x1, float x2, float y1, float y2)Linearly maps value from [y1, y2] to [x1, x2] (inverse of parameter-name convention)

static constexpr double pi

A compile-time constant equal to 3.141592653589793238. Use it with std::sin, std::cos, or any formula that requires radians.

static float Map(float value, float x1, float x2, float y1, float y2)

Linearly scales value from the range [y1, y2] back to the range [x1, x2]. Despite the parameter naming convention suggesting a forward [x1,x2] → [y1,y2] mapping, the implementation computes the inverse direction. Values outside [y1, y2] are extrapolated linearly.

Map() Formula

The implementation computes slope m and intercept b from the x/y ranges, then solves the inverse:
m = (y2 - y1) / (x2 - x1)
b = y1 - m * x1
result = (value - b) / m
Substituting b and simplifying:
result = (value - y1) * (x2 - x1) / (y2 - y1) + x1
When value equals y1 the result is x1; when value equals y2 the result is x2.

Parameters

value
float
required
The input value to map. Treated as a point within or outside the [y1, y2] range.
x1
float
required
The lower bound of the output range. Returned when value equals y1.
x2
float
required
The upper bound of the output range. Returned when value equals y2. Must not equal x1 (would produce a division by zero via slope m).
y1
float
required
The lower bound of the input range. When value equals y1, the result is x1.
y2
float
required
The upper bound of the input range. When value equals y2, the result is x2. Must not equal y1 (division by zero in the inverse step).

Usage Examples

// Convert a screen-space pixel X value (y-range) back to console cell index (x-range)
// e.g. pixel 480 in [0,960] maps to cell 40 in [0,80]
float cellX = MathUtils::Map(pixelX, 0, 80, 0, 960);

// Animate a sine wave: sin(t) is in [-1,1] (y-range), map to rows [5,35] (x-range)
float t = frameCount * 0.05f;
float y = MathUtils::Map(std::sin(t), 5.0f, 35.0f, -1.0f, 1.0f);
Point wave(50.0f, y, yellowF);
In the sine wave example, std::sin(t) is the input value drawn from the [y1, y2] range [-1, 1]. The output is scaled to the [x1, x2] range [5, 35], producing smooth oscillation between rows 5 and 35.

Build docs developers (and LLMs) love