MPLABĀ® Harmony Graphics Suite
Data Structures | Typedefs | Enumerations | Functions
legato_math.h File Reference

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

#include "gfx/legato/common/legato_common.h"
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

LIB_EXPORT int32_t leMini (int32_t l, int32_t r)
 Calculate minimum of two integers. More...
 
LIB_EXPORT int32_t leMaxi (int32_t l, int32_t r)
 Calculate maximum of two integers. More...
 
LIB_EXPORT float leMinf (float l, float r)
 Calculate minimum of two floats. More...
 
LIB_EXPORT float leMaxf (float l, float r)
 Calculate maximum of two floats. More...
 
LIB_EXPORT int32_t leClampi (int32_t min, int32_t max, int32_t i)
 Calculates clamp of an integer. More...
 
LIB_EXPORT float leClampf (float min, float max, float f)
 Calculate clamp of a float. More...
 
LIB_EXPORT uint32_t lePercent (uint32_t l, uint32_t r)
 Calculate percent of number. More...
 
LIB_EXPORT uint32_t lePercentWholeRounded (uint32_t l, uint32_t r)
 Calculate percent whole rounded. More...
 
LIB_EXPORT uint32_t lePercentOf (uint32_t num, uint32_t percent)
 Calculate percent of a number. More...
 
LIB_EXPORT void lePercentOfDec (uint32_t num, uint32_t percent, uint32_t *whl, uint32_t *dec)
 Calculate percent of a decimal. More...
 
LIB_EXPORT uint32_t leScaleInteger (uint32_t num, uint32_t oldMax, uint32_t newMax)
 Calculate the scale of an integer. More...
 
LIB_EXPORT int32_t leScaleIntegerSigned (int32_t num, int32_t oldMax, int32_t newMax)
 Calculate the scale of signed integer. More...
 
LIB_EXPORT uint32_t leAbsoluteValue (int32_t val)
 Calculates the absolute value of a signed integer. More...
 
LIB_EXPORT 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...
 
LIB_EXPORT 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...
 
LIB_EXPORT leResult lePolarToXY (int32_t r, int32_t a, lePoint *p)
 Generate points in an arc. More...
 
LIB_EXPORT int32_t leNormalizeAngle (int32_t t)
 Normalize an angle between 0 - 360. More...
 
LIB_EXPORT int32_t leSin (int32_t v)
 Calculate sin of a number. More...
 
LIB_EXPORT int32_t leCos (int32_t v)
 Calculate cosine of a number. More...
 
LIB_EXPORT leResult leEllipsePoint (int32_t t, int32_t a, int32_t b, int32_t theta, lePoint *p)
 Calculates points in an arc. More...
 
LIB_EXPORT 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...
 
lePoint leRotatePoint (lePoint pos, lePoint org, int32_t ang)
 Rotates point. More...
 
leRect leRotatedRectBounds (leRect rect, int32_t ang)
 Calculate bounding rectangle. More...
 
float leSqrt (const float x)
 
lePoint lePointOnCircle (uint32_t radius, int32_t angle)
 
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)
 
leResolvedAngleRanges leResolveAngles (int32_t startAngle, int32_t spanAngle)
 
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()

LIB_EXPORT 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()

LIB_EXPORT 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()

LIB_EXPORT 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()

LIB_EXPORT 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()

LIB_EXPORT 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()

LIB_EXPORT 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()

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

Calculates points in an arc.

@bold 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()

LIB_EXPORT 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()

LIB_EXPORT 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()

LIB_EXPORT 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()

LIB_EXPORT 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()

LIB_EXPORT 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()

LIB_EXPORT 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()

LIB_EXPORT 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
Here is the caller graph for this function:

◆ lePercentOf()

LIB_EXPORT 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()

LIB_EXPORT 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()

LIB_EXPORT 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()

LIB_EXPORT 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()

leRect leRotatedRectBounds ( leRect  rect,
int32_t  ang 
)

Calculate bounding rectangle.

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

uint32_t whole = lePercentOf(l, percent);
Parameters
param1rect is area to rotate.
param3angle is the angle in degrees.
Returns
resultant percentage of the number.
Here is the call graph for this function:

◆ leRotatePoint()

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

Rotates point.

Rotates point around origin at angle degrees.

lePoint point;
lePoint origin;
int32_t angle;
lePoint rot = leRotatePoint(point, origin, angle);
Parameters
param1point is point to rotate.
param2origin of the rotation.
param3angle is the angle in degrees.
Returns
the rotated point.
Here is the caller graph for this function:

◆ leScaleInteger()

LIB_EXPORT 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()

LIB_EXPORT 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()

LIB_EXPORT 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.
leNormalizeAngle
LIB_EXPORT int32_t leNormalizeAngle(int32_t t)
Normalize an angle between 0 - 360.
Definition: legato_math.c:49
leClampf
LIB_EXPORT float leClampf(float min, float max, float f)
Calculate clamp of a float.
Definition: legato_math.c:185
leResult
leResult
This enum represents function call results.
Definition: legato_common.h:134
lePercentWholeRounded
LIB_EXPORT uint32_t lePercentWholeRounded(uint32_t l, uint32_t r)
Calculate percent whole rounded.
Definition: legato_math.c:204
leLerp
LIB_EXPORT 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.
Definition: legato_math.c:290
leEllipsePoint
LIB_EXPORT leResult leEllipsePoint(int32_t t, int32_t a, int32_t b, int32_t theta, lePoint *p)
Calculates points in an arc.
Definition: legato_math.c:132
leMaxf
LIB_EXPORT float leMaxf(float l, float r)
Calculate maximum of two floats.
Definition: legato_math.c:166
leCos
LIB_EXPORT int32_t leCos(int32_t v)
Calculate cosine of a number.
Definition: legato_math.c:93
lePercentOf
LIB_EXPORT uint32_t lePercentOf(uint32_t num, uint32_t percent)
Calculate percent of a number.
Definition: legato_math.c:218
leSin
LIB_EXPORT int32_t leSin(int32_t v)
Calculate sin of a number.
Definition: legato_math.c:64
lePercent
LIB_EXPORT uint32_t lePercent(uint32_t l, uint32_t r)
Calculate percent of number.
Definition: legato_math.c:199
leMaxi
LIB_EXPORT int32_t leMaxi(int32_t l, int32_t r)
Calculate maximum of two integers.
Definition: legato_math.c:156
leAtan
LIB_EXPORT double leAtan(double val)
Calculate atan of points.
Definition: legato_math.c:145
leMinf
LIB_EXPORT float leMinf(float l, float r)
Calculate minimum of two floats.
Definition: legato_math.c:161
leScaleIntegerSigned
LIB_EXPORT int32_t leScaleIntegerSigned(int32_t num, int32_t oldMax, int32_t newMax)
Calculate the scale of signed integer.
Definition: legato_math.c:245
leMini
LIB_EXPORT int32_t leMini(int32_t l, int32_t r)
Calculate minimum of two integers.
Definition: legato_math.c:151
leClampi
LIB_EXPORT int32_t leClampi(int32_t min, int32_t max, int32_t i)
Calculates clamp of an integer.
Definition: legato_math.c:171
lePolarToXY
LIB_EXPORT leResult lePolarToXY(int32_t r, int32_t a, lePoint *p)
Generate points in an arc.
Definition: legato_math.c:124
leRotatePoint
lePoint leRotatePoint(lePoint pos, lePoint org, int32_t ang)
Rotates point.
Definition: legato_math.c:454
leAbsoluteValue
LIB_EXPORT uint32_t leAbsoluteValue(int32_t val)
Calculates the absolute value of a signed integer.
Definition: legato_math.c:280
leSortPointsY
void leSortPointsY(lePoint *p1, lePoint *p2)
Sorts two points on the Y axis.
Definition: legato_math.c:426
leScaleInteger
LIB_EXPORT uint32_t leScaleInteger(uint32_t num, uint32_t oldMax, uint32_t newMax)
Calculate the scale of an integer.
Definition: legato_math.c:256
leDivideRounding
LIB_EXPORT int32_t leDivideRounding(int32_t num, int32_t denom)
Performs a linear interpolation of an integer based on a percentage between two signed points.
Definition: legato_math.c:328
leSortPointsX
void leSortPointsX(lePoint *p1, lePoint *p2)
Sorts two points on the X axis.
Definition: legato_math.c:414
leGetYGivenXOnLine
int32_t leGetYGivenXOnLine(lePoint p1, lePoint p2, int32_t x)
Project Y give X.
Definition: legato_math.c:446
lePoint
This structure represents a integer Cartesian point.
Definition: legato_common.h:357