Defines | Typedefs | Functions

nsCoord.h File Reference

#include "nscore.h"
#include "nsMathUtils.h"
#include <math.h>
#include <float.h>
#include "nsDebug.h"
Include dependency graph for nsCoord.h:
This graph shows which files directly or indirectly include this file:

Defines

#define nscoord_MAX   nscoord(1 << 30)
#define nscoord_MIN   (-nscoord_MAX)
#define TWIPS_PER_POINT_INT   20
 handy constants
#define TWIPS_PER_POINT_FLOAT   20.0f
#define POINTS_PER_INCH_INT   72
#define POINTS_PER_INCH_FLOAT   72.0f
#define CM_PER_INCH_FLOAT   2.54f
#define MM_PER_INCH_FLOAT   25.4f

#define NS_POINTS_TO_TWIPS(x)   NSUnitsToTwips((x), 1.0f)
 Unit conversion macros.
#define NS_INCHES_TO_TWIPS(x)   NSUnitsToTwips((x), POINTS_PER_INCH_FLOAT)
 Unit conversion macros.
#define NS_MILLIMETERS_TO_TWIPS(x)   NSUnitsToTwips((x), (POINTS_PER_INCH_FLOAT * 0.03937f))
 Unit conversion macros.
#define NS_CENTIMETERS_TO_TWIPS(x)   NSUnitsToTwips((x), (POINTS_PER_INCH_FLOAT * 0.3937f))
 Unit conversion macros.
#define NS_PICAS_TO_TWIPS(x)   NSUnitsToTwips((x), 12.0f)
 Unit conversion macros.
#define NS_POINTS_TO_INT_TWIPS(x)   NSToIntRound(NS_POINTS_TO_TWIPS(x))
 Unit conversion macros.
#define NS_INCHES_TO_INT_TWIPS(x)   NSToIntRound(NS_INCHES_TO_TWIPS(x))
 Unit conversion macros.
#define NS_TWIPS_TO_POINTS(x)   NSTwipsToUnits((x), 1.0f)
 Unit conversion macros.
#define NS_TWIPS_TO_INCHES(x)   NSTwipsToUnits((x), 1.0f / POINTS_PER_INCH_FLOAT)
 Unit conversion macros.
#define NS_TWIPS_TO_MILLIMETERS(x)   NSTwipsToUnits((x), 1.0f / (POINTS_PER_INCH_FLOAT * 0.03937f))
 Unit conversion macros.
#define NS_TWIPS_TO_CENTIMETERS(x)   NSTwipsToUnits((x), 1.0f / (POINTS_PER_INCH_FLOAT * 0.3937f))
 Unit conversion macros.
#define NS_TWIPS_TO_PICAS(x)   NSTwipsToUnits((x), 1.0f / 12.0f)
 Unit conversion macros.

Typedefs

typedef PRInt32 nscoord

Functions

float NS_IEEEPositiveInfinity ()
PRBool NS_IEEEIsNan (float aF)
void VERIFY_COORD (nscoord aCoord)
nscoord NSToCoordRound (float aValue)
nscoord NSToCoordRoundWithClamp (float aValue)
nscoord _nscoordSaturatingMultiply (nscoord aCoord, float aScale, PRBool requireNotNegative)
 Returns aCoord * aScale, capping the product to nscoord_MAX or nscoord_MIN as appropriate for the signs of aCoord and aScale.
nscoord NSCoordSaturatingNonnegativeMultiply (nscoord aCoord, float aScale)
 Returns aCoord * aScale, capping the product to nscoord_MAX or nscoord_MIN as appropriate for the sign of aCoord.
nscoord NSCoordSaturatingMultiply (nscoord aCoord, float aScale)
 Returns aCoord * aScale, capping the product to nscoord_MAX or nscoord_MIN as appropriate for the signs of aCoord and aScale.
nscoord NSCoordMultiply (nscoord aCoord, PRInt32 aScale)
nscoord NSCoordDivide (nscoord aCoord, float aVal)
nscoord NSCoordDivide (nscoord aCoord, PRInt32 aVal)
nscoord NSCoordSaturatingAdd (nscoord a, nscoord b)
 Returns a + b, capping the sum to nscoord_MAX.
nscoord NSCoordSaturatingSubtract (nscoord a, nscoord b, nscoord infMinusInfResult)
 Returns a - b, gracefully handling cases involving nscoord_MAX.
PRBool NSCoordLessThan (nscoord a, nscoord b)
 compare against a nscoord "b", which might be unconstrained "a" must not be unconstrained.
PRBool NSCoordGreaterThan (nscoord a, nscoord b)
 compare against a nscoord "b", which might be unconstrained "a" must not be unconstrained No number is larger than a unconstrained one.
PRInt32 NSCoordToInt (nscoord aCoord)
 Convert an nscoord to a PRInt32.
float NSCoordToFloat (nscoord aCoord)
nscoord NSToCoordFloor (float aValue)
nscoord NSToCoordFloorClamped (float aValue)
nscoord NSToCoordCeil (float aValue)
nscoord NSToCoordCeilClamped (float aValue)
PRInt32 NSToIntFloor (float aValue)
PRInt32 NSToIntCeil (float aValue)
PRInt32 NSToIntRound (float aValue)
PRInt32 NSToIntRoundUp (float aValue)
nscoord NSFloatPixelsToAppUnits (float aPixels, float aAppUnitsPerPixel)
nscoord NSIntPixelsToAppUnits (PRInt32 aPixels, PRInt32 aAppUnitsPerPixel)
float NSAppUnitsToFloatPixels (nscoord aAppUnits, float aAppUnitsPerPixel)
PRInt32 NSAppUnitsToIntPixels (nscoord aAppUnits, float aAppUnitsPerPixel)
float NSCoordScale (nscoord aCoord, PRInt32 aFromAPP, PRInt32 aToAPP)
float NSUnitsToTwips (float aValue, float aPointsPerUnit)
float NSTwipsToUnits (float aTwips, float aUnitsPerPoint)

Define Documentation

#define CM_PER_INCH_FLOAT   2.54f
#define MM_PER_INCH_FLOAT   25.4f
#define NS_CENTIMETERS_TO_TWIPS (   x  )     NSUnitsToTwips((x), (POINTS_PER_INCH_FLOAT * 0.3937f))

Unit conversion macros.

#define NS_INCHES_TO_INT_TWIPS (   x  )     NSToIntRound(NS_INCHES_TO_TWIPS(x))

Unit conversion macros.

#define NS_INCHES_TO_TWIPS (   x  )     NSUnitsToTwips((x), POINTS_PER_INCH_FLOAT)

Unit conversion macros.

#define NS_MILLIMETERS_TO_TWIPS (   x  )     NSUnitsToTwips((x), (POINTS_PER_INCH_FLOAT * 0.03937f))

Unit conversion macros.

#define NS_PICAS_TO_TWIPS (   x  )     NSUnitsToTwips((x), 12.0f)

Unit conversion macros.

#define NS_POINTS_TO_INT_TWIPS (   x  )     NSToIntRound(NS_POINTS_TO_TWIPS(x))

Unit conversion macros.

#define NS_POINTS_TO_TWIPS (   x  )     NSUnitsToTwips((x), 1.0f)

Unit conversion macros.

#define NS_TWIPS_TO_CENTIMETERS (   x  )     NSTwipsToUnits((x), 1.0f / (POINTS_PER_INCH_FLOAT * 0.3937f))

Unit conversion macros.

#define NS_TWIPS_TO_INCHES (   x  )     NSTwipsToUnits((x), 1.0f / POINTS_PER_INCH_FLOAT)

Unit conversion macros.

#define NS_TWIPS_TO_MILLIMETERS (   x  )     NSTwipsToUnits((x), 1.0f / (POINTS_PER_INCH_FLOAT * 0.03937f))

Unit conversion macros.

#define NS_TWIPS_TO_PICAS (   x  )     NSTwipsToUnits((x), 1.0f / 12.0f)

Unit conversion macros.

#define NS_TWIPS_TO_POINTS (   x  )     NSTwipsToUnits((x), 1.0f)

Unit conversion macros.

#define nscoord_MAX   nscoord(1 << 30)
#define nscoord_MIN   (-nscoord_MAX)
#define POINTS_PER_INCH_FLOAT   72.0f
#define POINTS_PER_INCH_INT   72
#define TWIPS_PER_POINT_FLOAT   20.0f
#define TWIPS_PER_POINT_INT   20

handy constants


Typedef Documentation

typedef PRInt32 nscoord

Function Documentation

nscoord _nscoordSaturatingMultiply ( nscoord  aCoord,
float  aScale,
PRBool  requireNotNegative 
) [inline]

Returns aCoord * aScale, capping the product to nscoord_MAX or nscoord_MIN as appropriate for the signs of aCoord and aScale.

If requireNotNegative is true, this method will enforce that aScale is not negative; use that parametrization to get a check of that fact in debug builds.

PRBool NS_IEEEIsNan ( float  aF  )  [inline]
float NS_IEEEPositiveInfinity (  )  [inline]
float NSAppUnitsToFloatPixels ( nscoord  aAppUnits,
float  aAppUnitsPerPixel 
) [inline]
PRInt32 NSAppUnitsToIntPixels ( nscoord  aAppUnits,
float  aAppUnitsPerPixel 
) [inline]
nscoord NSCoordDivide ( nscoord  aCoord,
float  aVal 
) [inline]
nscoord NSCoordDivide ( nscoord  aCoord,
PRInt32  aVal 
) [inline]
PRBool NSCoordGreaterThan ( nscoord  a,
nscoord  b 
) [inline]

compare against a nscoord "b", which might be unconstrained "a" must not be unconstrained No number is larger than a unconstrained one.

PRBool NSCoordLessThan ( nscoord  a,
nscoord  b 
) [inline]

compare against a nscoord "b", which might be unconstrained "a" must not be unconstrained.

Every number is smaller than a unconstrained one

nscoord NSCoordMultiply ( nscoord  aCoord,
PRInt32  aScale 
) [inline]
nscoord NSCoordSaturatingAdd ( nscoord  a,
nscoord  b 
) [inline]

Returns a + b, capping the sum to nscoord_MAX.

This function assumes that neither argument is nscoord_MIN.

Note: If/when we start using floats for nscoords, this function won't be as necessary. Normal float addition correctly handles adding with infinity, assuming we aren't adding nscoord_MIN. (-infinity)

nscoord NSCoordSaturatingMultiply ( nscoord  aCoord,
float  aScale 
) [inline]

Returns aCoord * aScale, capping the product to nscoord_MAX or nscoord_MIN as appropriate for the signs of aCoord and aScale.

nscoord NSCoordSaturatingNonnegativeMultiply ( nscoord  aCoord,
float  aScale 
) [inline]

Returns aCoord * aScale, capping the product to nscoord_MAX or nscoord_MIN as appropriate for the sign of aCoord.

This method requires aScale to not be negative; use this method when you know that aScale should never be negative to get a sanity check of that invariant in debug builds.

nscoord NSCoordSaturatingSubtract ( nscoord  a,
nscoord  b,
nscoord  infMinusInfResult 
) [inline]

Returns a - b, gracefully handling cases involving nscoord_MAX.

This function assumes that neither argument is nscoord_MIN.

The behavior is as follows:

a) infinity - infinity -> infMinusInfResult b) N - infinity -> 0 (unexpected -- triggers NOTREACHED) c) infinity - N -> infinity d) N1 - N2 -> N1 - N2

Note: For float nscoords, cases (c) and (d) are handled by normal float math. We still need to explicitly specify the behavior for cases (a) and (b), though. (Under normal float math, those cases would return NaN and -infinity, respectively.)

float NSCoordScale ( nscoord  aCoord,
PRInt32  aFromAPP,
PRInt32  aToAPP 
) [inline]
float NSCoordToFloat ( nscoord  aCoord  )  [inline]
PRInt32 NSCoordToInt ( nscoord  aCoord  )  [inline]

Convert an nscoord to a PRInt32.

This *does not* do rounding because coords are never fractional. They can be out of range, so this does clamp out of bounds coord values to PR_INT32_MIN and PR_INT32_MAX.

nscoord NSFloatPixelsToAppUnits ( float  aPixels,
float  aAppUnitsPerPixel 
) [inline]
nscoord NSIntPixelsToAppUnits ( PRInt32  aPixels,
PRInt32  aAppUnitsPerPixel 
) [inline]
nscoord NSToCoordCeil ( float  aValue  )  [inline]
nscoord NSToCoordCeilClamped ( float  aValue  )  [inline]
nscoord NSToCoordFloor ( float  aValue  )  [inline]
nscoord NSToCoordFloorClamped ( float  aValue  )  [inline]
nscoord NSToCoordRound ( float  aValue  )  [inline]
nscoord NSToCoordRoundWithClamp ( float  aValue  )  [inline]
PRInt32 NSToIntCeil ( float  aValue  )  [inline]
PRInt32 NSToIntFloor ( float  aValue  )  [inline]
PRInt32 NSToIntRound ( float  aValue  )  [inline]
PRInt32 NSToIntRoundUp ( float  aValue  )  [inline]
float NSTwipsToUnits ( float  aTwips,
float  aUnitsPerPoint 
) [inline]
float NSUnitsToTwips ( float  aValue,
float  aPointsPerUnit 
) [inline]
void VERIFY_COORD ( nscoord  aCoord  )  [inline]