(root)/
libredwg-0.13/
test/
unit-testing/
spline.c
       1  #define DWG_TYPE DWG_TYPE_SPLINE
       2  #include "common.c"
       3  
       4  void
       5  api_process (dwg_object *obj)
       6  {
       7    int error;
       8    BITCODE_RS flag;     /* computed */
       9    BITCODE_BS scenario; /* 1 spline, 2 bezier */
      10    BITCODE_BS degree;
      11    BITCODE_BL splineflags; /* 2013+: method fit points = 1, CV frame show = 2,
      12                                closed = 4 */
      13    BITCODE_BL knotparam;   /* 2013+: Chord = 0, Square root = 1, Uniform = 2,
      14                               Custom = 15 */
      15    BITCODE_BD fit_tol;
      16    BITCODE_3BD beg_tan_vec;
      17    BITCODE_3BD end_tan_vec;
      18    BITCODE_B closed_b; /* bit 1 of 70 */
      19    BITCODE_B periodic; /* bit 2 of 70 */
      20    BITCODE_B rational; /* bit 3 of 70 */
      21    BITCODE_B weighted; /* bit 4 of 70 */
      22    BITCODE_BD knot_tol;
      23    BITCODE_BD ctrl_tol;
      24    BITCODE_BS num_fit_pts;
      25    BITCODE_3DPOINT *fit_pts;
      26    BITCODE_BL num_knots;
      27    BITCODE_BD *knots;
      28    BITCODE_BL num_ctrl_pts;
      29    Dwg_SPLINE_control_point *ctrl_pts;
      30  
      31    dwg_ent_spline *spline = dwg_object_to_SPLINE (obj);
      32  
      33    CHK_ENTITY_TYPE (spline, SPLINE, flag, RS);
      34    CHK_ENTITY_TYPE (spline, SPLINE, splineflags, BL);
      35    CHK_ENTITY_TYPE (spline, SPLINE, knotparam, BL);
      36    CHK_ENTITY_TYPE_W_OLD (spline, SPLINE, scenario, BS);
      37    if (scenario == 0 || scenario > 2)
      38      fail ("Illegal SPLINE.scenario %d", (int)scenario);
      39    CHK_ENTITY_TYPE_W_OLD (spline, SPLINE, degree, BS);
      40    CHK_ENTITY_TYPE_W_OLD (spline, SPLINE, fit_tol, BD);
      41    CHK_ENTITY_3RD (spline, SPLINE, beg_tan_vec);
      42    CHK_ENTITY_3RD (spline, SPLINE, end_tan_vec);
      43    CHK_ENTITY_TYPE_W_OLD (spline, SPLINE, closed_b, B);
      44    CHK_ENTITY_TYPE_W_OLD (spline, SPLINE, periodic, B);
      45    CHK_ENTITY_TYPE_W_OLD (spline, SPLINE, rational, B);
      46    CHK_ENTITY_TYPE_W_OLD (spline, SPLINE, weighted, B);
      47    CHK_ENTITY_TYPE_W_OLD (spline, SPLINE, knot_tol, BD);
      48    CHK_ENTITY_TYPE_W_OLD (spline, SPLINE, ctrl_tol, BD);
      49    CHK_ENTITY_TYPE_W_OLD (spline, SPLINE, num_fit_pts, BS);
      50    CHK_ENTITY_TYPE_W_OLD (spline, SPLINE, num_knots, BL);
      51    CHK_ENTITY_TYPE_W_OLD (spline, SPLINE, num_ctrl_pts, BL);
      52  
      53    if (!dwg_dynapi_entity_value (spline, "SPLINE", "fit_pts", &fit_pts, NULL))
      54      fail ("SPLINE.fit_pts");
      55    if (!dwg_dynapi_entity_value (spline, "SPLINE", "knots", &knots, NULL))
      56      fail ("SPLINE.knots");
      57    if (!dwg_dynapi_entity_value (spline, "SPLINE", "ctrl_pts", &ctrl_pts, NULL))
      58      fail ("SPLINE.ctrl_pts");
      59  
      60    if (scenario == 1)
      61      {
      62        dwg_spline_control_point *cpts;
      63        double *knots1;
      64        if (num_fit_pts)
      65          fail ("SPLINE.num_fit_pts with scenario 1");
      66  
      67  #ifdef USE_DEPRECATED_API
      68        cpts = dwg_ent_spline_get_ctrl_pts (spline, &error);
      69  #else
      70        cpts = spline->ctrl_pts;
      71        error = 0;
      72  #endif
      73        if (error)
      74          fail ("SPLINE.ctrl_pts");
      75        else
      76          {
      77            for (BITCODE_BL i = 0; i < num_ctrl_pts; i++)
      78              {
      79                ok ("SPLINE.ctrl_pts[%d]: (%f, %f, %f, %f)", i, cpts[i].x,
      80                    cpts[i].y, cpts[i].z, cpts[i].w);
      81                if (memcmp (&ctrl_pts[i], &cpts[i], sizeof (ctrl_pts[i])))
      82                  fail ("SPLINE.ctrl_pts[%d]", i);
      83              }
      84          }
      85  #ifdef USE_DEPRECATED_API
      86        free (cpts);
      87  #endif
      88  
      89  #ifdef USE_DEPRECATED_API
      90        knots1 = dwg_ent_spline_get_knots (spline, &error);
      91  #else
      92        knots1 = spline->knots;
      93        error = 0;
      94  #endif
      95        if (error)
      96          fail ("SPLINE.knots");
      97        else
      98          {
      99            for (BITCODE_BL i = 0; i < num_knots; i++)
     100              {
     101                ok ("SPLINE.knots[%d]: %f", i, knots1[i]);
     102                if (memcmp (&knots[i], &knots1[i], sizeof (double)))
     103                  fail ("SPLINE.knots[%d]", i);
     104              }
     105          }
     106  #ifdef USE_DEPRECATED_API
     107        free (knots1);
     108  #endif
     109      }
     110    else
     111      {
     112        dwg_point_3d *pts;
     113        if (num_knots)
     114          fail ("SPLINE.num_knots with scenario 2");
     115        if (num_ctrl_pts)
     116          fail ("SPLINE.num_ctrl_pts with scenario 2");
     117  
     118  #ifdef USE_DEPRECATED_API
     119        pts = dwg_ent_spline_get_fit_pts (spline, &error);
     120  #else
     121        pts = (dwg_point_3d *)spline->fit_pts;
     122        error = 0;
     123  #endif
     124        if (error)
     125          fail ("SPLINE.fit_pts");
     126        else
     127          {
     128            for (BITCODE_BL i = 0; i < num_fit_pts; i++)
     129              {
     130                ok ("SPLINE.fit_pts[%d]: (%f, %f, %f)", i, pts[i].x, pts[i].y,
     131                    pts[i].z);
     132                if (memcmp (&fit_pts[i], &pts[i], sizeof (fit_pts[i])))
     133                  fail ("SPLINE.fit_pts[%d]", i);
     134              }
     135          }
     136  #ifdef USE_DEPRECATED_API
     137        free (pts);
     138  #endif
     139      }
     140  }