Mac OS 9
GXMath.h
Go to the documentation of this file.
1 
19 #ifndef __GXMATH__
20 #define __GXMATH__
21 
22 #ifndef __CONDITIONALMACROS__
23 #include <ConditionalMacros.h>
24 #endif
25 
26 #ifndef __MACTYPES__
27 #include <MacTypes.h>
28 #endif
29 
30 #ifndef __FIXMATH__
31 #include <FixMath.h>
32 #endif
33 
34 #if PRAGMA_ONCE
35 #pragma once
36 #endif
37 
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #endif
42 
43 #if PRAGMA_IMPORT
44 #pragma import on
45 #endif
46 
47 #if PRAGMA_STRUCT_ALIGN
48 #pragma options align = mac68k
49 #elif PRAGMA_STRUCT_PACKPUSH
50 #pragma pack(push, 2)
51 #elif PRAGMA_STRUCT_PACK
52 #pragma pack(2)
53 #endif
54 
55 #if defined(__MWERKS__) && TARGET_CPU_68K
56 #pragma push
57 #pragma pointers_in_D0
58 #endif
59 
60  struct gxPoint
61  {
62  Fixed x;
63  Fixed y;
64  };
65  typedef struct gxPoint gxPoint;
66 
67  typedef unsigned short gxColorValue;
68  struct gxPolar
69  {
70  Fixed radius;
71  Fixed angle;
72  };
73  typedef struct gxPolar gxPolar;
74  struct gxMapping
75  {
76  Fixed map[3][3];
77  };
78  typedef struct gxMapping gxMapping;
79 #define gxColorValue1 ((gxColorValue)0x0000FFFF)
80 #define gxPositiveInfinity ((long)0x7FFFFFFFL)
81 #define gxNegativeInfinity ((long)0x80000000L)
82 
83 #if CALL_NOT_IN_CARBON
92  gxMapping *
93  CopyToMapping(gxMapping *target, const gxMapping *source);
94 
103  gxMapping *
104  InvertMapping(gxMapping *target, const gxMapping *source);
105 
114  gxMapping *
115  MapMapping(gxMapping *target, const gxMapping *source);
116 
125  gxMapping *
126  MoveMapping(gxMapping *target, Fixed hOffset, Fixed vOffset);
127 
136  gxMapping *
137  MoveMappingTo(gxMapping *target, Fixed hPosition, Fixed vPosition);
138 
147  gxMapping *
149 
158  gxMapping *
159  RotateMapping(gxMapping *target, Fixed angle, Fixed xCenter, Fixed yCenter);
160 
169  gxMapping *
170  ScaleMapping(gxMapping *target, Fixed hFactor, Fixed vFactor, Fixed xCenter,
171  Fixed yCenter);
172 
181  gxMapping *
183 
192  gxMapping *
193  SkewMapping(gxMapping *target, Fixed skewX, Fixed skewY, Fixed xCenter,
194  Fixed yCenter);
195 
204  void
205  MapPoints(const gxMapping *source, long count, gxPoint theVector[]);
206 
215  short
216  FirstBit(unsigned long x);
217 
226  short
227  WideScale(const wide *source);
228 
237  short
238  LinearRoot(Fixed first, Fixed last, Fract t[]);
239 
248  short
249  QuadraticRoot(Fixed first, Fixed control, Fixed last, Fract t[]);
250 
259  gxPoint *
260  PolarToPoint(const gxPolar *ra, gxPoint *xy);
261 
270  gxPolar *
271  PointToPolar(const gxPoint *xy, gxPolar *ra);
272 
281  Fract
282  FractCubeRoot(Fract source);
283 
292  Fract
293  FractDivide(Fract dividend, Fract divisor);
294 
303  Fract
304  FractMultiply(Fract multiplicand, Fract multiplier);
305 
314  Fract
315  FractSineCosine(Fixed degrees, Fract *cosine);
316 
325  Fract
326  FractSquareRoot(Fract source);
327 
336  Fixed
337  FixedDivide(Fixed dividend, Fixed divisor);
338 
347  Fixed
348  FixedMultiply(Fixed multiplicand, Fixed multiplier);
349 
360  long
361  MultiplyDivide(long source, long multiplier, long divisor);
362 
371  unsigned long
372  Magnitude(long deltaX, long deltaY);
373 
382  long
383  VectorMultiplyDivide(long count, const long *vector1, long step1,
384  const long *vector2, long step2, long divisor);
385 
387 #endif
389 #if TARGET_OS_MAC && TARGET_CPU_68K
390 #if CALL_NOT_IN_CARBON
399  wide *
400  WideAdd(wide *target, const wide *source);
401 
410  short
411  WideCompare(const wide *target, const wide *source);
412 
421  wide *
422  WideNegate(wide *target);
423 
432  wide *
433  WideShift(wide *target, long shift);
434 
443  unsigned long
444  WideSquareRoot(const wide *source);
445 
454  wide *
455  WideSubtract(wide *target, const wide *source);
456 
465  wide *
466  WideMultiply(long multiplicand, long multiplier, wide *target);
467 
477  long
478  WideDivide(const wide *dividend, long divisor, long *remainder);
479 
489  wide *
490  WideWideDivide(wide *dividend, long divisor, long *remainder);
491 
492 #endif
494 #endif
496 #if CALL_NOT_IN_CARBON
505  wide *
506  VectorMultiply(long count, const long *vector1, long step1, const long *vector2,
507  long step2, wide *dot);
508 
517  unsigned long
518  RandomBits(long count, long focus);
519 
528  void
529  SetRandomSeed(const wide *seed);
530 
539  wide *
541 
542 #endif
544 #define FixedRound(a) ((short)((Fixed)(a) + fixed1 / 2 >> 16))
545 #define FixedSquareRoot(a) ((Fixed)FractSquareRoot(a) + 64 >> 7)
546 #define FixedTruncate(a) ((short)((Fixed)(a) >> 16))
547 #define FixedToFract(a) ((Fract)(a) << 14)
548 #define FractToFixed(a) (((Fixed)(a) + 8192L) >> 14)
549 #define FixedToInt(a) ((short)(((Fixed)(a) + fixed1 / 2) >> 16))
550 #define IntToFixed(a) ((Fixed)(a) << 16)
551 #define FixedToFloat(a) ((float)(a) / fixed1)
552 #define FloatToFixed(a) ((Fixed)((float)(a) * fixed1))
553 #define FractToFloat(a) ((float)(a) / fract1)
554 #define FloatToFract(a) ((Fract)((float)(a) * fract1))
555 #define ColorToFract(a) (((Fract)(a) << 14) + ((Fract)(a) + 2 >> 2))
556 #define FractToColor(a) ((gxColorValue)((a) - ((a) >> 16) + 8191 >> 14))
557 #ifndef ff
558 #define ff(a) IntToFixed(a)
559 #define fl(a) FloatToFixed(a)
560 #endif
561 
562 #if defined(__MWERKS__) && TARGET_CPU_68K
563 #pragma pop
564 #endif
565 
566 #if PRAGMA_STRUCT_ALIGN
567 #pragma options align = reset
568 #elif PRAGMA_STRUCT_PACKPUSH
569 #pragma pack(pop)
570 #elif PRAGMA_STRUCT_PACK
571 #pragma pack()
572 #endif
573 
574 #ifdef PRAGMA_IMPORT_OFF
575 #pragma import off
576 #elif PRAGMA_IMPORT
577 #pragma import reset
578 #endif
579 
580 #ifdef __cplusplus
581 }
582 #endif
583 
584 #endif
Set up for compiler independent conditionals.
Fixed Math Interfaces.
unsigned long WideSquareRoot(const wide *source)
long WideDivide(const wide *dividend, long divisor, long *remainder)
wide * WideWideDivide(wide *dividend, long divisor, long *remainder)
wide * WideAdd(wide *target, const wide *source)
wide * WideSubtract(wide *target, const wide *source)
wide * WideMultiply(long multiplicand, long multiplier, wide *target)
wide * WideShift(wide *target, long shift)
short WideCompare(const wide *target, const wide *source)
wide * WideNegate(wide *target)
Fract FractMultiply(Fract multiplicand, Fract multiplier)
wide * GetRandomSeed(wide *seed)
wide * VectorMultiply(long count, const long *vector1, long step1, const long *vector2, long step2, wide *dot)
short FirstBit(unsigned long x)
Fract FractSineCosine(Fixed degrees, Fract *cosine)
void MapPoints(const gxMapping *source, long count, gxPoint theVector[])
gxMapping * CopyToMapping(gxMapping *target, const gxMapping *source)
gxMapping * ScaleMapping(gxMapping *target, Fixed hFactor, Fixed vFactor, Fixed xCenter, Fixed yCenter)
gxPolar * PointToPolar(const gxPoint *xy, gxPolar *ra)
gxMapping * MoveMappingTo(gxMapping *target, Fixed hPosition, Fixed vPosition)
gxMapping * RotateMapping(gxMapping *target, Fixed angle, Fixed xCenter, Fixed yCenter)
gxMapping * SkewMapping(gxMapping *target, Fixed skewX, Fixed skewY, Fixed xCenter, Fixed yCenter)
Fract FractDivide(Fract dividend, Fract divisor)
unsigned long RandomBits(long count, long focus)
gxMapping * MoveMapping(gxMapping *target, Fixed hOffset, Fixed vOffset)
gxMapping * NormalizeMapping(gxMapping *target)
gxMapping * MapMapping(gxMapping *target, const gxMapping *source)
gxPoint * PolarToPoint(const gxPolar *ra, gxPoint *xy)
short WideScale(const wide *source)
Fixed FixedMultiply(Fixed multiplicand, Fixed multiplier)
short LinearRoot(Fixed first, Fixed last, Fract t[])
Fract FractSquareRoot(Fract source)
long MultiplyDivide(long source, long multiplier, long divisor)
gxMapping * InvertMapping(gxMapping *target, const gxMapping *source)
void SetRandomSeed(const wide *seed)
Fixed FixedDivide(Fixed dividend, Fixed divisor)
short QuadraticRoot(Fixed first, Fixed control, Fixed last, Fract t[])
unsigned long Magnitude(long deltaX, long deltaY)
long VectorMultiplyDivide(long count, const long *vector1, long step1, const long *vector2, long step2, long divisor)
Fract FractCubeRoot(Fract source)
gxMapping * ResetMapping(gxMapping *target)
Basic Macintosh data types.
long Fixed
Definition: MacTypes.h:153
x
Definition: ToolUtils.h:163
Definition: GXMath.h:75
Definition: GXMath.h:61
Definition: GXMath.h:69
Definition: MacTypes.h:104