Back to index

lightning-sunbird  0.9+nobinonly
Defines | Typedefs | Functions
nsCoord.h File Reference
#include <math.h>
#include "nsDebug.h"

Go to the source code of this file.

Defines

#define nscoord_MAX   nscoord(1 << 30)
#define nscoord_MIN   (-nscoord_MAX)

Typedefs

typedef PRInt32 nscoord

Functions

float NS_IEEEPositiveInfinity ()
PRBool NS_IEEEIsNan (float aF)
void VERIFY_COORD (nscoord aCoord)
nscoord NSCoordMultiply (nscoord aCoord, float aVal)
nscoord NSCoordMultiply (nscoord aCoord, PRInt32 aVal)
nscoord NSCoordDivide (nscoord aCoord, float aVal)
nscoord NSCoordDivide (nscoord aCoord, PRInt32 aVal)
PRInt32 NSCoordToInt (nscoord aCoord)
 Convert an nscoord to a PRInt32.
float NSCoordToFloat (nscoord aCoord)

Define Documentation

#define nscoord_MAX   nscoord(1 << 30)

Definition at line 79 of file nsCoord.h.

Definition at line 82 of file nsCoord.h.


Typedef Documentation

typedef PRInt32 nscoord

Definition at line 78 of file nsCoord.h.


Function Documentation

PRBool NS_IEEEIsNan ( float  aF) [inline]

Definition at line 68 of file nsCoord.h.

                                     {
  PRUint32 bits = *(PRUint32*)&aF;
  return (bits & 0x7F800000) == 0x7F800000 &&
    (bits & 0x007FFFFF) != 0;
}

Here is the caller graph for this function:

float NS_IEEEPositiveInfinity ( ) [inline]

Definition at line 63 of file nsCoord.h.

                                       {
  float f;
  *(PRUint32*)&f = 0x7F800000;
  return f;
}
nscoord NSCoordDivide ( nscoord  aCoord,
float  aVal 
) [inline]

Definition at line 105 of file nsCoord.h.

                                                         {
  VERIFY_COORD(aCoord);
#ifdef NS_COORD_IS_FLOAT
  return floorf(aCoord/aVal);
#else
  return (PRInt32)(aCoord/aVal);
#endif
}

Here is the call graph for this function:

nscoord NSCoordDivide ( nscoord  aCoord,
PRInt32  aVal 
) [inline]

Definition at line 114 of file nsCoord.h.

                                                           {
  VERIFY_COORD(aCoord);
#ifdef NS_COORD_IS_FLOAT
  return floorf(aCoord/aVal);
#else
  return aCoord/aVal;
#endif
}

Here is the call graph for this function:

nscoord NSCoordMultiply ( nscoord  aCoord,
float  aVal 
) [inline]

Definition at line 91 of file nsCoord.h.

                                                           {
  VERIFY_COORD(aCoord);
#ifdef NS_COORD_IS_FLOAT
  return floorf(aCoord*aVal);
#else
  return (PRInt32)(aCoord*aVal);
#endif
}

Here is the call graph for this function:

nscoord NSCoordMultiply ( nscoord  aCoord,
PRInt32  aVal 
) [inline]

Definition at line 100 of file nsCoord.h.

                                                             {
  VERIFY_COORD(aCoord);
  return aCoord*aVal;
}

Here is the call graph for this function:

float NSCoordToFloat ( nscoord  aCoord) [inline]

Definition at line 148 of file nsCoord.h.

                                            {
  VERIFY_COORD(aCoord);
#ifdef NS_COORD_IS_FLOAT
  NS_ASSERTION(!NS_IEEEIsNan(aCoord), "NaN encountered in float conversion");
#endif
  return (float)aCoord;
}

Here is the call graph for this function:

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.

Definition at line 128 of file nsCoord.h.

                                            {
  VERIFY_COORD(aCoord);
#ifdef NS_COORD_IS_FLOAT
  NS_ASSERTION(!NS_IEEEIsNan(aCoord), "NaN encountered in int conversion");
  if (aCoord < -2147483648.0f) {
    // -2147483648 is the smallest 32-bit signed integer that can be
    // exactly represented as a float
    return PR_INT32_MIN;
  } else if (aCoord > 2147483520.0f) {
    // 2147483520 is the largest 32-bit signed integer that can be
    // exactly represented as an IEEE float
    return PR_INT32_MAX;
  } else {
    return (PRInt32)aCoord;
  }
#else
  return aCoord;
#endif
}

Here is the call graph for this function:

void VERIFY_COORD ( nscoord  aCoord) [inline]

Definition at line 84 of file nsCoord.h.

                                         {
#ifdef NS_COORD_IS_FLOAT
  NS_ASSERTION(floorf(aCoord) == aCoord,
               "Coords cannot have fractions");
#endif
}

Here is the caller graph for this function: