InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PMReal Class Reference

#include <PMReal.h>

Public Types

typedef base_type data_type
 

Public Member Functions

constexpr PMReal () noexcept
 
constexpr PMReal (const PMReal &) noexcept=default
 
constexpr PMReal (PMReal &&) noexcept=default
 
constexpr PMReal (double d) noexcept
 
PMRealoperator= (const PMReal &) noexcept=default
 
PMRealoperator= (PMReal &&) noexcept=default
 
PMRealoperator+= (const PMReal &a)
 
PMRealoperator-= (const PMReal &a)
 
PMRealoperator*= (const PMReal &a)
 
PMRealoperator/= (const PMReal &a)
 

Friends

PMReal ToPMReal (Fixed fx)
 
double ToDouble (const PMReal &r) noexcept
 
float ToFloat (const PMReal &r)
 
Fixed ToFixed (const PMReal &r)
 
int16 ToInt16 (const PMReal &r)
 
uint16 ToUInt16 (const PMReal &r)
 
int32 ToInt32 (const PMReal &r)
 
uint32 ToUInt32 (const PMReal &r)
 
PMReal operator- (const PMReal &a)
 
PMReal operator+ (const PMReal &a, const PMReal &b)
 
PMReal operator- (const PMReal &a, const PMReal &b)
 
PMReal operator* (const PMReal &a, const PMReal &b)
 
PMReal operator/ (const PMReal &a, const PMReal &b)
 
PMReal Round (const PMReal &a)
 
PMReal Floor (const PMReal &a)
 
PMReal Ceiling (const PMReal &a)
 
PMReal abs (const PMReal &a)
 
PMReal NearestMultiple (const PMReal &a, const PMReal &factor)
 
PMReal Mod (const PMReal &a, const PMReal &b)
 
bool16 operator== (const PMReal &a, const PMReal &b) noexcept
 
bool16 operator!= (const PMReal &a, const PMReal &b) noexcept
 
bool16 operator< (const PMReal &a, const PMReal &b) noexcept
 
bool16 operator> (const PMReal &a, const PMReal &b) noexcept
 
bool16 operator<= (const PMReal &a, const PMReal &b) noexcept
 
bool16 operator>= (const PMReal &a, const PMReal &b) noexcept
 
bool16 AnglesEqual (const PMReal &a, const PMReal &b) noexcept
 
bool16 EqualsWithEpsilon (const PMReal &a, const PMReal &b, double epsilon) noexcept
 

Detailed Description

Simple wrapper class for a floating point value in InDesign. Analogous to a built-in C/C++ double.

NOTE: Implicit type casting

Implicit type casting has not been added to PMReal on purpose. Leaving out implicit type casting allows the compiler to make unambigous choices for math operations containing mixed types. Additionally, implicit type casting can be hazardous to your coding health, so instead we have provided explicit functions for conversion.

NOTE: Constructor conversions

We only have one constructor taking a double to avoid ambiguous calls. This does mean that implicit conversion happens when going to a PMReal. Be careful in your code. To make the class at all useable it had to implicit conversion one direction or the other and we chose the constructor.

NOTE: Why a class?

Why are we using a class and not a double? Primarily to hide the epsilon comparisons behind operator definitions. It may also help us out in the future if we have to add anything – It will be easier to add to this class than change from a typedef.

Constructor & Destructor Documentation

constexpr PMReal::PMReal ()
inlinenoexcept

default constructor. initialize to 0.0

constexpr PMReal::PMReal (const PMReal)
defaultnoexcept

Copy constructor.

Parameters
otherIN The PMReal to initialize this object from
constexpr PMReal::PMReal (double d)
inlinenoexcept

Constructs this object from the specified double.

Parameters
dIN The value to initialize this object to

Member Function Documentation

PMReal & PMReal::operator*= (const PMReala)
inline

Multiples this object by a value.

Parameters
aIN The amount to multiply by
Returns
A reference to this object, so assignments can be chained
PMReal & PMReal::operator+= (const PMReala)
inline

Increments this object by a value.

Parameters
aIN The amount to increment by
Returns
A reference to this object, so assignments can be chained
PMReal & PMReal::operator-= (const PMReala)
inline

Decrements this object by a value.

Parameters
aIN The amount to decrement by
Returns
A reference to this object, so assignments can be chained
PMReal & PMReal::operator/= (const PMReala)
inline

Divides this object by a value.

Parameters
aIN The amount to divide by
Returns
A reference to this object, so assignments can be chained
PMReal& PMReal::operator= (const PMReal)
defaultnoexcept

Assigns a value to this object.

Parameters
cIN The value to assign
Returns
A reference to this object, so assignments can be chained

Friends And Related Function Documentation

PMReal abs (const PMReala)
friend

Calculates absolute value of a PMReal.

Parameters
aIN The PMReal whose absolute value is calculated
Returns
The absolute value of the input value
bool16 AnglesEqual (const PMReala,
const PMRealb 
)
friend

Convenience operator for comparing two angles (in degrees) with implicit epsilon.

Note: For the purposes of the comparison treats 360 as equal to zero.

Parameters
aIN The first angle to compare
bIN The second angle to compare
Returns
kTrue if the values are equal, else kFalse
PMReal Ceiling (const PMReala)
friend

Calculates ceiling of a PMReal by rounding up to integer value.

Parameters
aIN The PMReal to round
Returns
The result of the ceiling calculation
bool16 EqualsWithEpsilon (const PMReala,
const PMRealb,
double epsilon 
)
friend

Function for comparing two PMReal values using a custom epsilon value.

Parameters
aIN the first PMReal to compare
bIN the second PMReal to compare
epsilonIN the epsilon value used to compare the two PMReal values.
Returns
kTrue if the values are equal, else kFalse
PMReal Floor (const PMReala)
friend

Calculates floor of a PMReal by rounding down to integer value.

Parameters
aIN The PMReal to round
Returns
The result of the floor calculation
PMReal Mod (const PMReala,
const PMRealb 
)
friend

Calculates modulo (floating point remainder) of two PMReals.

Parameters
aIN The numerator
bIN The denominator
Returns
The modulo of the two input values
PMReal NearestMultiple (const PMReala,
const PMRealfactor 
)
friend

Calculates the nearest multiple of factor to a.

result = Round(a / factor) * factor

Parameters
aIN The number whose nearest multiple is to be calculated
factorIN The factor to use in the calculation
Returns
The nearest multiple of factor to a
bool16 operator!= (const PMReala,
const PMRealb 
)
friend

Compare two PMReals for inequality, using implicit epsilon.

Parameters
aIN The first PMReal to compare
bIN The second PMReal to compare
Returns
kTrue if the values are not equal, else kFalse if they're equal
PMReal operator* (const PMReala,
const PMRealb 
)
friend

Multiplies two PMReals.

Parameters
aIN The first PMReal to multiply
bIN The second PMReal to multiply
Returns
The sum of the two PMReals
PMReal operator+ (const PMReala,
const PMRealb 
)
friend

Adds two PMReals.

Parameters
aIN The first PMReal to add
bIN The second PMReal to add
Returns
The sum of the two PMReals
PMReal operator- (const PMReala)
friend

Negates a PMReal.

Parameters
aIN The PMReal to negate
Returns
The negated PMReal
PMReal operator- (const PMReala,
const PMRealb 
)
friend

Subtracts two PMReals.

Parameters
aIN The first PMReal to subtract
bIN The second PMReal to subtract
Returns
The difference of the two PMReals
PMReal operator/ (const PMReala,
const PMRealb 
)
friend

Divides a PMReal by another.

Parameters
aIN The numerator
bIN The denominator
Returns
The result of the division
bool16 operator< (const PMReala,
const PMRealb 
)
friend

Determines if one PMReal is less than another, using implicit epsilon.

Parameters
aIN The first PMReal to compare
bIN The second PMReal to compare
Returns
kTrue if first PMReal is less than the second, else kFalse
bool16 operator<= (const PMReala,
const PMRealb 
)
friend

Determines if one PMReal is less than or equal to another, using implicit epsilon.

Parameters
aIN The first PMReal to compare
bIN The second PMReal to compare
Returns
kTrue if first PMReal is less than or equal to the second, else kFalse
bool16 operator== (const PMReala,
const PMRealb 
)
friend

Compare two PMReals for equality, using implicit epsilon.

Parameters
aIN The first PMReal to compare
bIN The second PMReal to compare
Returns
kTrue if the values are equal, else kFalse
bool16 operator> (const PMReala,
const PMRealb 
)
friend

Determines if one PMReal is greater than another, using implicit epsilon.

Parameters
aIN The first PMReal to compare
bIN The second PMReal to compare
Returns
kTrue if first PMReal is greater than the second, else kFalse
bool16 operator>= (const PMReala,
const PMRealb 
)
friend

Determines if one PMReal is greater than or equal to another, using implicit epsilon.

Parameters
aIN The first PMReal to compare
bIN The second PMReal to compare
Returns
kTrue if first PMReal is greater than or equal to the second, else kFalse
PMReal Round (const PMReala)
friend

Rounds a PMReal to nearest integer value.

Parameters
aIN The PMReal to round
Returns
The rounded value
double ToDouble (const PMRealr)
friend

Converts a PMReal to a double.

Parameters
rIN The PMReal to convert
Returns
The PMReal as a double
Fixed ToFixed (const PMRealr)
friend

Converts a PMReal to a fixed-point number. Fixed-point numbers use 16/16 bit format.

Parameters
rIN The PMReal to convert
Returns
The PMReal as a fixed-point number
float ToFloat (const PMRealr)
friend

Converts a PMReal to a float.

Parameters
rIN The PMReal to convert
Returns
The PMReal as a float
int16 ToInt16 (const PMRealr)
friend

Converts a PMReal to an int16.

NOTE: This just casts the PMReal's value to an int16.

Parameters
rIN The PMReal to convert
Returns
The PMReal as an int16 value
int32 ToInt32 (const PMRealr)
friend

Converts a PMReal to an int32.

NOTE: This just casts the PMReal's value to an int32.

Parameters
rIN The PMReal to convert
Returns
The PMReal as an int32 value
PMReal ToPMReal (Fixed fx)
friend

Converts a fixed-point number to a PMReal. Fixed-point numbers use 16/16 bit format.

Parameters
fxIN The fixed-point number to convert
Returns
The fixed-point number as a PMReal
uint16 ToUInt16 (const PMRealr)
friend

Converts a PMReal to a uint16.

NOTE: This just casts the PMReal's value to a uint16.

Parameters
rIN The PMReal to convert
Returns
The PMReal as a uint16 value
uint32 ToUInt32 (const PMRealr)
friend

Converts a PMReal to a uint16.

NOTE: This just casts the PMReal's value to a uint32.

Parameters
rIN The PMReal to convert
Returns
The PMReal as an uint32 value