MPLABĀ® Harmony Graphics Suite  GFX v3.13.0
Legato API Documentation
legato_math.h File Reference

Defines common math functions for general use. More...

Include dependency graph for legato_math.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  leArcQuadrantQuery
 
struct  leResolvedAngleRanges
 

Typedefs

typedef struct leResolvedAngleRanges leResolvedAngleRanges
 

Enumerations

enum  LE_TRIG_FUNCTION_TYPE { LE_TRIG_SINE_TYPE, LE_TRIG_COSINE_TYPE }
 Used to define the types of trig functions. More...
 
enum  LE_QUADRANT { LE_Q1, LE_Q2, LE_Q3, LE_Q4 }
 Used to define the basic four quandrants of a coordinate plane. More...
 
enum  leArcDir { LE_CCW, LE_CW }
 Used to define arc direction. More...
 

Functions

int32_t leMini (int32_t l, int32_t r)
 Calculate minimum of two integers. More...
 
int32_t leMaxi (int32_t l, int32_t r)
 Calculate maximum of two integers. More...
 
float leMinf (float l, float r)
 Calculate minimum of two floats. More...
 
float leMaxf (float l, float r)
 Calculate maximum of two floats. More...
 
int32_t leClampi (int32_t min, int32_t max, int32_t i)
 Calculates clamp of an integer. More...
 
float leClampf (float min, float max, float f)
 Calculate clamp of a float. More...
 
uint32_t lePercent (uint32_t l, uint32_t r)
 Calculate percent of number. More...
 
uint32_t lePercentWholeRounded (uint32_t l, uint32_t r)
 Calculate percent whole rounded. More...
 
uint32_t lePercentOf (uint32_t num, uint32_t percent)
 Calculate percent of a number. More...
 
void lePercentOfDec (uint32_t num, uint32_t percent, uint32_t *whl, uint32_t *dec)
 Calculate percent of a decimal. More...
 
uint32_t leScaleInteger (uint32_t num, uint32_t oldMax, uint32_t newMax)
 Calculate the scale of an integer. More...
 
int32_t leScaleIntegerSigned (int32_t num, int32_t oldMax, int32_t newMax)
 Calculate the scale of signed integer. More...
 
uint32_t leAbsoluteValue (int32_t val)
 Calculates the absolute value of a signed integer. More...
 
int32_t leLerp (int32_t x, int32_t y, uint32_t per)
 Calculates a linear interpolation of an integer based on a percentage between two signed points. More...
 
int32_t leDivideRounding (int32_t num, int32_t denom)
 Performs a linear interpolation of an integer based on a percentage between two signed points. More...
 
leResult lePolarToXY (int32_t r, int32_t a, lePoint *p)
 Generate points in an arc. More...
 
int32_t leNormalizeAngle (int32_t t)
 Normalize an angle between 0 - 360. More...
 
int32_t leSin (int32_t v)
 Calculate sin of a number. More...
 
int32_t leCos (int32_t v)
 Calculate cosine of a number. More...
 
leResult leEllipsePoint (int32_t t, int32_t a, int32_t b, int32_t theta, lePoint *p)
 Calculates points in an arc. More...
 
double leAtan (double val)
 Calculate atan of points. More...
 
leBool lePointOnLineSide (lePoint *pt, lePoint *linePt, lePoint *sign)
 
void leSortPointsX (lePoint *p1, lePoint *p2)
 Sorts two points on the X axis. More...
 
void leSortPointsY (lePoint *p1, lePoint *p2)
 Sorts two points on the Y axis. More...
 
int32_t leGetXGivenYOnLine (lePoint p1, lePoint p2, int32_t y)
 Project point. More...
 
int32_t leGetYGivenXOnLine (lePoint p1, lePoint p2, int32_t x)
 Project Y give X. More...
 
void leRotatePoint (lePoint pos, lePoint org, int32_t ang, lePoint *res)
 Rotates point. More...
 
void leRotatedRectBounds (leRect rect, int32_t ang, leRect *res)
 Calculate bounding rectangle. More...
 
float leSqrt (const float x)
 
void lePointOnCircle (uint32_t radius, int32_t angle, lePoint *res)
 
uint32_t leDegreesFromPercent (uint32_t percent, int32_t centerAngle, int32_t startAngle)
 
uint32_t lePercentFromDegrees (uint32_t degrees, int32_t centerAngle, int32_t startAngle)
 
void leNormalizeAngles (int32_t startAngle, int32_t spanAngle, int32_t *normalizedStartAngle, int32_t *normalizedEndAngle)
 
void leResolveAngles (int32_t startAngle, int32_t spanAngle, leResolvedAngleRanges *res)
 
float leRound (float flt)
 

Detailed Description

Defines common math functions for general use.

This is an array implementation that is used internally by the Legato user interface library.

Enumeration Type Documentation

◆ LE_QUADRANT

Used to define the basic four quandrants of a coordinate plane.

◆ LE_TRIG_FUNCTION_TYPE

Used to define the types of trig functions.

Trigonomtry is used in Legato.

◆ leArcDir

enum leArcDir

Used to define arc direction.

The parameters CW and CCW enable you to define the direction of the arc.

Enumerator
LE_CCW 

counter clock wise.

LE_CW 

clock wise.

Function Documentation

◆ leAbsoluteValue()

uint32_t leAbsoluteValue ( int32_t  val)

Calculates the absolute value of a signed integer.

Calculates the absolute value of val.

uint32_t absl = leAbsoluteValue(val);
Parameters
param1val is an integer.
Returns
the absolute value

◆ leAtan()

double leAtan ( double  val)

Calculate atan of points.

Calculate atan of x and y.

double val;
double angle = leAtan(val);
Parameters
param1val is value.
Returns
the angle in radians

◆ leClampf()

float leClampf ( float  min,
float  max,
float  f 
)

Calculate clamp of a float.

Calculates the clamp value of i constrained to the range min to max.

float val = leClampf(min, max, i);
Parameters
param1min is an float.
param2max is an float.
param3f is an float.
Returns
a clamp integer

◆ leClampi()

int32_t leClampi ( int32_t  min,
int32_t  max,
int32_t  i 
)

Calculates clamp of an integer.

Calculates the clamp value of i constrained to the range min to max.

int32_t val = leClampi(min, max, i);
Parameters
param1min is an integer.
param2max is an integer.
param3i is an integer.
Returns
a clamp integer

◆ leCos()

int32_t leCos ( int32_t  v)

Calculate cosine of a number.

Calculates cosine of angle.

Remarks
- result of cosine fixed point value (times 256), calling function needs to divide by 256 to get good result. ex. "a * cos(v)" would be "a * leCos(v) / 256";
int32_t val = leCos(v);
Parameters
param1v is the value in degrees.
Returns
cosine fixed point value
Here is the call graph for this function:
Here is the caller graph for this function:

◆ leDivideRounding()

int32_t leDivideRounding ( int32_t  num,
int32_t  denom 
)

Performs a linear interpolation of an integer based on a percentage between two signed points.

Calculates integer division of num divided by denom.

int32_t val = leDivideRounding(num, denom);
Parameters
param1num is an integer.
param2denom is the denom.
param3per is the percent to apply.
Returns
equivalent to int32_t( ((float)num)/((float)denom) + 0.5 ) without using floating point

◆ leEllipsePoint()

leResult leEllipsePoint ( int32_t  t,
int32_t  a,
int32_t  b,
int32_t  theta,
lePoint p 
)

Calculates points in an arc.

Help

Generates points in an arc at radius and angle.

leEllipsePoint(angle, endAngleArc0, dir, points);
Parameters
param1startAngleArc0 is point to rotate.
param2endAngleArc0 of the rotation.
param2dir of the rotation.
param2quadrant of the rotation.
Returns
void.
Here is the call graph for this function:

◆ leGetXGivenYOnLine()

int32_t leGetXGivenYOnLine ( lePoint  p1,
lePoint  p2,
int32_t  y 
)

Project point.

Project point p1 onto p2 on y coordinate.

int32_t y;
int32_t x = leGetYGivenXOnLine(p1, p2, y);
Parameters
param1p1 is point to rotate.
param2p2 of the rotation.
param3y is the angle in degrees.
Returns
the x coordinate.

◆ leGetYGivenXOnLine()

int32_t leGetYGivenXOnLine ( lePoint  p1,
lePoint  p2,
int32_t  x 
)

Project Y give X.

Project point p1 onto p2 on x coordinate.

int32_t x;
int32_t y = leGetYGivenXOnLine(p1, p2, x);
Parameters
param1p1 is point to rotate.
param2p2 of the rotation.
param3x is the angle in degrees.
Returns
the y coordinate.

◆ leLerp()

int32_t leLerp ( int32_t  x,
int32_t  y,
uint32_t  per 
)

Calculates a linear interpolation of an integer based on a percentage between two signed points.

Calculates a linear interpolation between x and y based on per.

uint32_t scale = leLerp(l, percent);
Parameters
param1x is point.
param2y is point.
param2per is the percent to apply.
Returns
the interpolated value
Here is the call graph for this function:

◆ leMaxf()

float leMaxf ( float  l,
float  r 
)

Calculate maximum of two floats.

Calculates the maximum of two floats l and r.

float larger = leMaxf(l, r);
Parameters
param1l is an float.
param2r is an float.
Returns
the maximum of l and r.

◆ leMaxi()

int32_t leMaxi ( int32_t  l,
int32_t  r 
)

Calculate maximum of two integers.

Calculates the maximum of integers l and r.

uint32_t larger = leMaxi(l, r);
Parameters
param1l is an integer.
param2r is an integer.
Returns
the maximum of l and r.
Here is the caller graph for this function:

◆ leMinf()

float leMinf ( float  l,
float  r 
)

Calculate minimum of two floats.

Calculates the minimum of two floats l and r.

float smaller = leMinf(l, r);
Parameters
param1l is an float.
param2r is an float.
Returns
the minimum of l and r.

◆ leMini()

int32_t leMini ( int32_t  l,
int32_t  r 
)

Calculate minimum of two integers.

Calculates the lessor of integers l and r.

uint32_t smaller = leMini(l, r);
Parameters
param1l is an integer.
param2r is an integer.
Returns
the lessor of l and r.
Here is the caller graph for this function:

◆ leNormalizeAngle()

int32_t leNormalizeAngle ( int32_t  t)

Normalize an angle between 0 - 360.

Normalizes angle. Example: t = -5, return value is 355 t = 450, return value is 90

int32_t val = leNormalizeAngle(angle);
Parameters
param1x is an integer.
param2y is the percent to apply.
param2per is the percent to apply.
Returns
normalize an angle in degrees.
Here is the caller graph for this function:

◆ lePercent()

uint32_t lePercent ( uint32_t  l,
uint32_t  r 
)

Calculate percent of number.

Calculates the decimal percent of l and r. Integer based. Accuracy for higher numbers is not guaranteed.The result is the decimal percentage multiplied by 100.

uint32_t pc = lePercent(l, r);
Parameters
param1l is an integer.
param2r is an integer.
Returns
percentage represented as a whole number

◆ lePercentOf()

uint32_t lePercentOf ( uint32_t  num,
uint32_t  percent 
)

Calculate percent of a number.

Calculate the whole number percentage of num and percent.

uint32_t whole = lePercentOf(l, percent);
Parameters
param1num is an integer.
param2percent is the percent to apply.
Returns
the percentage of the number.
Here is the caller graph for this function:

◆ lePercentOfDec()

void lePercentOfDec ( uint32_t  num,
uint32_t  percent,
uint32_t *  whl,
uint32_t *  dec 
)

Calculate percent of a decimal.

Calculates the whole number percent of num and percent and stores the result in whl and dec

uint32_t whole = lePercentOf(num, percent, whl, dec);
Parameters
param1l is an integer.
param2percent is the percent to apply.
Returns
resultant percentage of the number.

◆ lePercentWholeRounded()

uint32_t lePercentWholeRounded ( uint32_t  l,
uint32_t  r 
)

Calculate percent whole rounded.

Calculates the whole number integer based percent of l and r. The difference between this and lePercent is that the decimal portion of the whole number is rounded off.

See also
lePercent
Note
Accuracy for higher numbers is not guaranteed.
uint32_t pc = lePercentWholeRounded(l, r);
Parameters
param1l is an integer.
param2r is an integer.
Returns
percentage represented as a whole number.

◆ lePolarToXY()

leResult lePolarToXY ( int32_t  r,
int32_t  a,
lePoint p 
)

Generate points in an arc.

Generates points in an arc using radius and angle.

leResult res = lePolarToXY(l, percent);
Parameters
param1radius is the radius of arc.
param2angle is the angle of arc.
param3points is the position to query.
Returns
resultant percentage of the number.
Here is the call graph for this function:

◆ leRotatedRectBounds()

void leRotatedRectBounds ( leRect  rect,
int32_t  ang,
leRect res 
)

Calculate bounding rectangle.

Calculates the bounding rectangle for the area rect rotated about origin at angle.

uint32_t whole = lePercentOf(l, percent);
Parameters
rectarea to rotate.
angthe angle in degrees.
resthe resultant rectangle
Returns
void
Here is the call graph for this function:

◆ leRotatePoint()

void leRotatePoint ( lePoint  pos,
lePoint  org,
int32_t  ang,
lePoint res 
)

Rotates point.

Rotates point around origin at angle degrees.

lePoint point;
lePoint origin;
int32_t angle;
lePoint res;
leRotatePoint(point, origin, angle, &res);
Parameters
param1point is point to rotate.
param2origin of the rotation.
param3angle is the angle in degrees.
param4the resulting point
Returns
void
Here is the caller graph for this function:

◆ leScaleInteger()

uint32_t leScaleInteger ( uint32_t  num,
uint32_t  oldMax,
uint32_t  newMax 
)

Calculate the scale of an integer.

Calculates the scale of num from oldMax to newMax

Note
one number range of 0 -> n0 to another range 0 -> n1 based on percentages.
uint32_t scale = leScaleInteger(num, oldMax, newMax);
Parameters
param1num is an integer.
param2oldMax is the old range maximum.
param3newMax is the new range maximum.
Returns
resultant percentage of the number.

◆ leScaleIntegerSigned()

int32_t leScaleIntegerSigned ( int32_t  num,
int32_t  oldMax,
int32_t  newMax 
)

Calculate the scale of signed integer.

Calculates the scale of num in range oldMax to range newMax.

uint32_t scale = leScaleIntegerSigned(l, percent);
Parameters
param1num is an integer.
param2oldMax is an integer.
param3newMax is the percent to apply.
Returns
resultant percentage of the number.

◆ leSin()

int32_t leSin ( int32_t  v)

Calculate sin of a number.

Calculates sin of angle.

Remarks
- result of sine fixed point value (times 256), calling function needs to divide by 256 to get good result. ex. "a * sin(v)" would be "a * leSin(v) / 256";
int32_t val = leSin(v);
Parameters
param1v is the value in degrees.
Returns
sine fixed point value
Here is the call graph for this function:
Here is the caller graph for this function:

◆ leSortPointsX()

void leSortPointsX ( lePoint p1,
lePoint p2 
)

Sorts two points on the X axis.

Sort points p1 and p2 on the X axis.

leSortPointsX(p1, p2);
Parameters
param1p1 is point.
param2p2 is point.
Returns
void.

◆ leSortPointsY()

void leSortPointsY ( lePoint p1,
lePoint p2 
)

Sorts two points on the Y axis.

Sort points p1 and p2 on the Y axis.

leSortPointsY(p1, p2);
Parameters
param1p1 is a point.
param2p2 is a point.
Returns
void.