home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / i / iritsm3s.zip / cagd_lib / cagdbbox.c < prev    next >
C/C++ Source or Header  |  1992-01-28  |  3KB  |  85 lines

  1. /******************************************************************************
  2. * CagdBbox.c - Handle freeform cuves and surfaces bounding boxes.          *
  3. *******************************************************************************
  4. * Written by Gershon Elber, Jan. 92.                          *
  5. ******************************************************************************/
  6.  
  7. #include "cagd_loc.h"
  8.  
  9. static void CagdPointsBBox(CagdRType **Points, int Length, CagdBBoxStruct *BBox);
  10.  
  11. /******************************************************************************
  12. * Computes a bounding box around a freeform curve.                  *
  13. ******************************************************************************/
  14. void CagdCrvBBox(CagdCrvStruct *Crv, CagdBBoxStruct *BBox)
  15. {
  16.     CagdCrvStruct
  17.     *E3Crv = CagdCoerceCrvTo(Crv, CAGD_PT_E3_TYPE);
  18.     int Length = E3Crv -> Length;
  19.     CagdRType
  20.     **Points = E3Crv -> Points;
  21.  
  22.     CagdPointsBBox(Points, Length, BBox);
  23.  
  24.     CagdCrvFree(E3Crv);
  25. }
  26.  
  27. /******************************************************************************
  28. * Computes a bounding box around a freeform surface.                  *
  29. ******************************************************************************/
  30. void CagdSrfBBox(CagdSrfStruct *Srf, CagdBBoxStruct *BBox)
  31. {
  32.     CagdSrfStruct
  33.     *E3Srf = CagdCoerceSrfTo(Srf, CAGD_PT_E3_TYPE);
  34.     int Length = E3Srf -> ULength * E3Srf -> VLength;
  35.     CagdRType
  36.     **Points = E3Srf -> Points;
  37.  
  38.     CagdPointsBBox(Points, Length, BBox);
  39.  
  40.     CagdSrfFree(E3Srf);
  41. }
  42.  
  43. /******************************************************************************
  44. * Computes a bounding box around a freeform surface.                  *
  45. ******************************************************************************/
  46. static void CagdPointsBBox(CagdRType **Points, int Length, CagdBBoxStruct *BBox)
  47. {
  48.     int i;
  49.  
  50.     BBox -> Min[0] = BBox -> Min[1] = BBox -> Min[2] = INFINITY;
  51.     BBox -> Max[0] = BBox -> Max[1] = BBox -> Max[2] = -INFINITY;
  52.  
  53.     for (i = 0; i < Length; i++) {
  54.     if (BBox -> Min[0] > Points[X][i])
  55.         BBox -> Min[0] = Points[X][i];
  56.     if (BBox -> Min[1] > Points[Y][i])
  57.         BBox -> Min[1] = Points[Y][i];
  58.     if (BBox -> Min[2] > Points[Z][i])
  59.         BBox -> Min[2] = Points[Z][i];
  60.  
  61.     if (BBox -> Max[0] < Points[X][i])
  62.         BBox -> Max[0] = Points[X][i];
  63.     if (BBox -> Max[1] < Points[Y][i])
  64.         BBox -> Max[1] = Points[Y][i];
  65.     if (BBox -> Max[2] < Points[Z][i])
  66.         BBox -> Max[2] = Points[Z][i];
  67.     }
  68. }
  69.  
  70. /******************************************************************************
  71. * Merge (union) two bounding boxes into one.                      *
  72. ******************************************************************************/
  73. void CagdMergeBBox(CagdBBoxStruct *DestBBox, CagdBBoxStruct *SrcBBox)
  74. {
  75.     int i;
  76.  
  77.     for (i = 0; i < 3; i++) {
  78.     if (DestBBox -> Min[0] > SrcBBox -> Min[i])
  79.         DestBBox -> Min[0] = SrcBBox -> Min[i];
  80.     if (DestBBox -> Max[0] < SrcBBox -> Max[i])
  81.         DestBBox -> Max[0] = SrcBBox -> Max[i];
  82.     }
  83. }
  84.  
  85.