summaryrefslogtreecommitdiff
path: root/src/sim/sim_primitives.c
blob: a0a2e779cf9889597b86644433e218e21f7dca31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
/** \file
 * \brief Primitives of the Simulation Base Driver
 *
 * See Copyright Notice in cd.h
 */

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <memory.h>

#include "cd.h"
#include "cd_private.h"
#include "cd_truetype.h"
#include "sim.h"

void cdlineSIM(cdCtxCanvas* ctxcanvas, int x1, int y1, int x2, int y2)
{
  cdCanvas* canvas = ((cdCtxCanvasBase*)ctxcanvas)->canvas;
  int old_use_matrix = canvas->use_matrix;

  if (canvas->use_matrix && !canvas->invert_yaxis)
  {
    cdMatrixTransformPoint(canvas->matrix, x1, y1, &x1, &y1);
    cdMatrixTransformPoint(canvas->matrix, x2, y2, &x2, &y2);
  }

  /* must disable transformation here, because line simulation use cxPixel */
  canvas->use_matrix = 0;

  if(canvas->line_width > 1)
    simLineThick(canvas, x1, y1, x2, y2);
  else 
    simLineThin(canvas, x1, y1, x2, y2);

  canvas->use_matrix = old_use_matrix;
}

void cdrectSIM(cdCtxCanvas* ctxcanvas, int xmin, int xmax, int ymin, int ymax)
{
  cdCanvas* canvas = ((cdCtxCanvasBase*)ctxcanvas)->canvas;
  cdPoint poly[5]; /* leave room of one more point */
  poly[0].x = xmin; poly[0].y = ymin;
  poly[1].x = xmin; poly[1].y = ymax;
  poly[2].x = xmax; poly[2].y = ymax;
  poly[3].x = xmax; poly[3].y = ymin;
  canvas->cxPoly(canvas->ctxcanvas, CD_CLOSED_LINES, poly, 4);
}

void cdboxSIM(cdCtxCanvas* ctxcanvas, int xmin, int xmax, int ymin, int ymax)
{
  cdCanvas* canvas = ((cdCtxCanvasBase*)ctxcanvas)->canvas;
  
  if (canvas->use_matrix)
  {
    cdPoint poly[5]; /* leave room of one more point */
    poly[0].x = xmin; poly[0].y = ymin;
    poly[1].x = xmin; poly[1].y = ymax;
    poly[2].x = xmax; poly[2].y = ymax;
    poly[3].x = xmax; poly[3].y = ymin;
    canvas->cxPoly(canvas->ctxcanvas, CD_FILL, poly, 4);
  }
  else
  {
    cdSimulation* simulation = canvas->simulation;
    int y;

    /* must set line attributes here, because fill simulation use cxLine and cxPixel */
    int old_line_style = cdCanvasLineStyle(canvas, CD_CONTINUOUS);
    int old_line_width = cdCanvasLineWidth(canvas, 1);

    for(y=ymin;y<=ymax;y++)
      simFillHorizLine(simulation, xmin, y, xmax);

    cdCanvasLineStyle(canvas, old_line_style);
    cdCanvasLineWidth(canvas, old_line_width);
  }
}

void cdfSimBox(cdCtxCanvas *ctxcanvas, double xmin, double xmax, double ymin, double ymax)
{
  cdCanvas* canvas = ((cdCtxCanvasBase*)ctxcanvas)->canvas;
  cdfPoint poly[5]; /* leave room of one more point */
  poly[0].x = xmin; poly[0].y = ymin;
  poly[1].x = xmin; poly[1].y = ymax;
  poly[2].x = xmax; poly[2].y = ymax;
  poly[3].x = xmax; poly[3].y = ymin;
  canvas->cxFPoly(canvas->ctxcanvas, CD_FILL, poly, 4);
}

void cdfSimRect(cdCtxCanvas *ctxcanvas, double xmin, double xmax, double ymin, double ymax)
{
  cdCanvas* canvas = ((cdCtxCanvasBase*)ctxcanvas)->canvas;
  cdfPoint poly[5]; /* leave room of one more point */
  poly[0].x = xmin; poly[0].y = ymin;
  poly[1].x = xmin; poly[1].y = ymax;
  poly[2].x = xmax; poly[2].y = ymax;
  poly[3].x = xmax; poly[3].y = ymin;
  canvas->cxFPoly(canvas->ctxcanvas, CD_CLOSED_LINES, poly, 4);
}

int simCalcEllipseNumSegments(cdCanvas* canvas, int xc, int yc, int width, int height)
{
  int n, dx, dy, hd;
  int w2 = width/2;
  int h2 = height/2;
  int x1 = xc-w2, 
      y1 = yc-h2, 
      x2 = xc+w2, 
      y2 = yc+h2;

  if (canvas->use_matrix)
  {
    cdMatrixTransformPoint(canvas->matrix, x1, y1, &x1, &y1);
    cdMatrixTransformPoint(canvas->matrix, x2, y2, &x2, &y2);
  }

  dx = (x1-x2);
  dy = (y1-y2);
  hd = (int)(sqrt(dx*dx + dy*dy)/2);

  /*  Estimation Heuristic:
  use half diagonal to estimate the number of segments for 360 degrees.
  Use the difference of the half diagonal and its projection to calculate the minimum angle:
  cos(min_angle) = hd / (hd + 1)     or   min_angle = acos(hd / (hd + 1))
  The number of segments will be 360 / min_angle.
  */

  n = (int)((360.0*CD_DEG2RAD) / acos((double)hd / (hd + 1.0)) + 0.5); /* round up */

  /* multiple of 4 */
  n = ((n + 3)/4)*4;

  /* minimum number is 4 */
  if (n < 4) n = 4;

  return n;
}

void cdarcSIM(cdCtxCanvas* ctxcanvas, int xc, int yc, int width, int height, double angle1, double angle2)
{
  cdCanvas* canvas = ((cdCtxCanvasBase*)ctxcanvas)->canvas;
  double c, s, sx, sy, x, y, prev_x, prev_y;
  double da;
  int i, yc2 = 2*yc, p = 0,
      last_xi_a = -65535, 
      last_yi_a = -65535, 
      last_xi_b = -65535, 
      last_yi_b = -65535;
  cdPoint* poly = NULL;

  /* number of segments of equivalent poligonal for a full ellipse */
  int n = simCalcEllipseNumSegments(canvas, xc, yc, width, height);

  /* Use special floating point anti-alias line draw when
     line_width==1, and NOT using cdlineSIM. */
  if (canvas->line_width > 1 || canvas->cxLine != cdlineSIM)
  {
    poly = (cdPoint*)malloc(sizeof(cdPoint)*(n+1));  /* n+1 points */
    if (!poly) return;
  }

  /* number of segments for the arc */
  n = cdRound((fabs(angle2-angle1)*n)/360);
  if (n < 1) n = 1;

  /* converts degrees into radians */
  angle1 *= CD_DEG2RAD;
  angle2 *= CD_DEG2RAD;

  /* generates arc points at origin with axis x and y */

  da = (angle2-angle1)/n;
  c  = cos(da);
  s  = sin(da);
  sx = -(width*s)/height;
  sy = (height*s)/width;

  x = (width/2.0f)*cos(angle1);
  y = (height/2.0f)*sin(angle1);
  prev_x = x;
  prev_y = y;
  if (poly)
  {
    poly[0].x = _cdRound(x)+xc;
    poly[0].y = _cdRound(y)+yc;

    if (canvas->invert_yaxis)  /* must invert because of the angle orientation */
      poly[0].y = yc2 - poly[0].y;

    p = 1;
  }
  else
    simLineStyleNoReset = 1;

  for (i = 1; i < n+1; i++)  /* n+1 points */
  {
    x =  c*prev_x + sx*prev_y;
    y = sy*prev_x +  c*prev_y;

    if (poly)
    {
      poly[p].x = _cdRound(x)+xc;
      poly[p].y = _cdRound(y)+yc;

      if (canvas->invert_yaxis)   /* must invert because of the angle orientation */
        poly[p].y = yc2 - poly[p].y;

      if (poly[p-1].x != poly[p].x || poly[p-1].y != poly[p].y)
        p++;
    }
    else
    {
      int old_use_matrix = canvas->use_matrix;
      double x1 = prev_x+xc,
             y1 = prev_y+yc,
             x2 = x+xc,
             y2 = y+yc;

      if (canvas->use_matrix && !canvas->invert_yaxis)
      {
        cdfMatrixTransformPoint(canvas->matrix, x1, y1, &x1, &y1);
        cdfMatrixTransformPoint(canvas->matrix, x2, y2, &x2, &y2);
      }

      /* must disable transformation here, because line simulation use cxPixel */
      canvas->use_matrix = 0;

      if (canvas->invert_yaxis)  /* must invert because of the angle orientation */
      {
        y1 = yc2 - y1;
        y2 = yc2 - y2;
      }

      simfLineThin(canvas, x1, y1, x2, y2, &last_xi_a, &last_yi_a, &last_xi_b, &last_yi_b);

      canvas->use_matrix = old_use_matrix;
    }

    prev_x = x;
    prev_y = y;
  }

  if (poly)
  {
    canvas->cxPoly(canvas->ctxcanvas, CD_OPEN_LINES, poly, p);
    free(poly);
  }
  else
    simLineStyleNoReset = 0;
}

void cdfSimArc(cdCtxCanvas *ctxcanvas, double xc, double yc, double width, double height, double angle1, double angle2)
{
  cdCanvas* canvas = ((cdCtxCanvasBase*)ctxcanvas)->canvas;
  double c, s, sx, sy, x, y, prev_x, prev_y, da;
  int i, p;
  cdfPoint* poly = NULL;

  /* number of segments of equivalent poligonal for a full ellipse */
  int n = simCalcEllipseNumSegments(canvas, (int)xc, (int)yc, (int)width, (int)height);

  poly = (cdfPoint*)malloc(sizeof(cdfPoint)*(n+1));  /* n+1 points */
  if (!poly) return;

  /* number of segments for the arc */
  n = cdRound((fabs(angle2-angle1)*n)/360);
  if (n < 1) n = 1;

  /* converts degrees into radians */
  angle1 *= CD_DEG2RAD;
  angle2 *= CD_DEG2RAD;

  /* generates arc points at origin with axis x and y */

  da = (angle2-angle1)/n;
  c  = cos(da);
  s  = sin(da);
  sx = -(width*s)/height;
  sy = (height*s)/width;

  x = (width/2.0f)*cos(angle1);
  y = (height/2.0f)*sin(angle1);
  prev_x = x;
  prev_y = y;
  poly[0].x = x+xc;
  poly[0].y = y+yc;

  p = 1;

  for (i = 1; i < n+1; i++)  /* n+1 points */
  {
    x =  c*prev_x + sx*prev_y;
    y = sy*prev_x +  c*prev_y;

    poly[p].x = x+xc;
    poly[p].y = y+yc;

    if (poly[p-1].x != poly[p].x || 
        poly[p-1].y != poly[p].y)
      p++;

    prev_x = x;
    prev_y = y;
  }

  canvas->cxFPoly(canvas->ctxcanvas, CD_OPEN_LINES, poly, p);
  free(poly);
}

void cdfSimElipse(cdCtxCanvas* ctxcanvas, double xc, double yc, double width, double height, double angle1, double angle2, int sector)
{
  cdCanvas* canvas = ((cdCtxCanvasBase*)ctxcanvas)->canvas;
  double c, s, sx, sy, x, y, prev_x, prev_y, da;
  int i, p;
  cdfPoint* poly;

  /* number of segments of equivalent poligonal for a full ellipse */
  int n = simCalcEllipseNumSegments(canvas, (int)xc, (int)yc, (int)width, (int)height);

  /* number of segments for the arc */
  n = cdRound(((angle2-angle1)*n)/360);
  if (n < 1) n = 1;

  poly = (cdfPoint*)malloc(sizeof(cdfPoint)*(n+2+1));  /* n+1 points +1 center */

  /* converts degrees into radians */
  angle1 *= CD_DEG2RAD;
  angle2 *= CD_DEG2RAD;

  /* generates arc points at origin with axis x and y */

  da = (angle2-angle1)/n;
  c  = cos(da);
  s  = sin(da);
  sx = -(width*s)/height;
  sy = (height*s)/width;

  x = xc +  (width/2.0)*cos(angle1);
  y = yc + (height/2.0)*sin(angle1);
  prev_x = x;
  prev_y = y;

  poly[0].x = x;
  poly[0].y = y;
  p = 1;

  for (i = 1; i < n+1; i++) /* n+1 points */
  {
    x = xc +  c*(prev_x-xc) + sx*(prev_y-yc);
    y = yc + sy*(prev_x-xc) +  c*(prev_y-yc);

    poly[p].x = x;
    poly[p].y = y;

    if (poly[p-1].x != poly[p].x || poly[p-1].y != poly[p].y)
      p++;

    prev_x = x;
    prev_y = y;
  }

  if (poly[p-1].x != poly[0].x || poly[p-1].y != poly[0].y)
  {
    if (sector)  /* cdSector */
    {
      /* add center */
      poly[p].x = xc;
      poly[p].y = yc;
    }
    else         /* cdChord */
    {
      /* add initial point */
      poly[p].x = poly[0].x;
      poly[p].y = poly[0].y;
    }
    p++;
  }

  canvas->cxFPoly(canvas->ctxcanvas, CD_FILL, poly, p);
  free(poly);
}

static void cdSimElipse(cdCtxCanvas* ctxcanvas, int xc, int yc, int width, int height, double angle1, double angle2, int sector)
{
  cdCanvas* canvas = ((cdCtxCanvasBase*)ctxcanvas)->canvas;
  float c, s, sx, sy, x, y, prev_x, prev_y;
  double da;
  int i, p, yc2 = 2*yc;
  cdPoint* poly;

  /* number of segments of equivalent poligonal for a full ellipse */
  int n = simCalcEllipseNumSegments(canvas, xc, yc, width, height);

  /* number of segments for the arc */
  n = cdRound(((angle2-angle1)*n)/360);
  if (n < 1) n = 1;

  poly = (cdPoint*)malloc(sizeof(cdPoint)*(n+2+1));  /* n+1 points +1 center */

  /* converts degrees into radians */
  angle1 *= CD_DEG2RAD;
  angle2 *= CD_DEG2RAD;

  /* generates arc points at origin with axis x and y */

  da = (angle2-angle1)/n;
  c  = (float)cos(da);
  s  = (float)sin(da);
  sx = -(width*s)/height;
  sy = (height*s)/width;

  x = xc +  (width/2.0f)*(float)cos(angle1);
  y = yc + (height/2.0f)*(float)sin(angle1);
  prev_x = x;
  prev_y = y;

  poly[0].x = _cdRound(x);
  poly[0].y = _cdRound(y);
  if (canvas->invert_yaxis)
    poly[0].y = yc2 - poly[0].y;
  p = 1;

  for (i = 1; i < n+1; i++) /* n+1 points */
  {
    x = xc +  c*(prev_x-xc) + sx*(prev_y-yc);
    y = yc + sy*(prev_x-xc) +  c*(prev_y-yc);

    poly[p].x = _cdRound(x);
    poly[p].y = _cdRound(y);

    if (canvas->invert_yaxis)
      poly[p].y = yc2 - poly[p].y;

    if (poly[p-1].x != poly[p].x || poly[p-1].y != poly[p].y)
      p++;

    prev_x = x;
    prev_y = y;
  }

  if (poly[p-1].x != poly[0].x || poly[p-1].y != poly[0].y)
  {
    if (sector)  /* cdSector */
    {
      /* add center */
      poly[p].x = xc;
      poly[p].y = yc;
    }
    else         /* cdChord */
    {
      /* add initial point */
      poly[p].x = poly[0].x;
      poly[p].y = poly[0].y;
    }
    p++;
  }

  canvas->cxPoly(canvas->ctxcanvas, CD_FILL, poly, p);

  free(poly);
}

void cdsectorSIM(cdCtxCanvas* ctxcanvas, int xc, int yc, int width, int height, double angle1, double angle2)
{
  cdSimElipse(ctxcanvas, xc, yc, width, height, angle1, angle2, 1);
}

void cdchordSIM(cdCtxCanvas* ctxcanvas, int xc, int yc, int width, int height, double angle1, double angle2)
{
  cdSimElipse(ctxcanvas, xc, yc, width, height, angle1, angle2, 0);
}

void cdfSimPolyPath(cdCtxCanvas* ctxcanvas, cdfPoint* poly, int n)
{
}

void cdSimPolyPath(cdCtxCanvas* ctxcanvas, cdPoint* poly, int n)
{
//  int p, i, current_x = 0, current_y = 0, current_set = 0;
//
//  i = 0;
//  for (p=0; p<ctxcanvas->canvas->path_n; p++)
//  {
//    switch(ctxcanvas->canvas->path[p])
//    {
//    case CD_PATH_NEW:
//      current_set = 0;
//      break;
//    case CD_PATH_MOVETO:
//      if (i+1 > n) break;
//      current_x = poly[i].x;
//      current_y = poly[i].y;
//      current_set = 1;
//      i++;
//      break;
//    case CD_PATH_LINETO:
//      if (i+1 > n) break;
//      if (current_set)
//        graphics_path->AddLine(current_x, current_y, poly[i].x, poly[i].y);
//      current_x = poly[i].x;
//      current_y = poly[i].y;
//      current_set = 1;
//      i++;
//      break;
//    case CD_PATH_ARC:
//      {
//        int xc, yc, w, h;
//        double a1, a2;
//
//        if (i+3 > n) break;
//
//        xc = poly[i].x, 
//        yc = poly[i].y, 
//        w = poly[i+1].x, 
//        h = poly[i+1].y, 
//        a1 = poly[i+2].x/1000.0, 
//        a2 = poly[i+2].y/1000.0;
//
//        if (current_set)
//        {
//          int StartX, StartY;
//
//          if (ctxcanvas->canvas->invert_yaxis)
//          {
//            StartX = xc + cdRound(w * cos(CD_DEG2RAD * a1) / 2.0);
//            StartY = yc - cdRound(h * sin(CD_DEG2RAD * a1) / 2.0);
//          }
//          else
//          {
//            StartX = xc + cdRound(w * cos(CD_DEG2RAD * a2) / 2.0);
//            StartY = yc + cdRound(h * sin(CD_DEG2RAD * a2) / 2.0);
//          }
//
//          graphics_path->AddLine(current_x, current_y, StartX, StartY);
//        }
//
//        Rect rect(xc - w/2, yc - h/2, w, h);
//        if (a1 == 0 && a2 == 360)
//          graphics_path->AddEllipse(rect);
//        else
//        {
//          cdwpFixAngles(ctxcanvas, &a1, &a2);
//          graphics_path->AddArc(rect, (REAL)a1, (REAL)(a2-a1));
//        }
//
//        graphics_path->GetLastPoint(&lastPoint);
//        current_x = (int)lastPoint.X;
//        current_y = (int)lastPoint.Y;
//        current_set = 1;
//
//        i += 3;
//      }
//      break;
//    case CD_PATH_CURVETO:
//      if (i+3 > n) break;
//      if (!current_set)
//      {
//        current_x = poly[i].x;
//        current_y = poly[i].y;
//      }
//      graphics_path->AddBezier(current_x, current_y, poly[i].x, poly[i].y, poly[i+1].x, poly[i+1].y, poly[i+2].x, poly[i+2].y);
//      graphics_path->GetLastPoint(&lastPoint);
//      current_x = (int)lastPoint.X;
//      current_y = (int)lastPoint.Y;
//      current_set = 1;
//      i += 3;
//      break;
//    case CD_PATH_CLOSE:
//      graphics_path->CloseFigure();
//      break;
//    case CD_PATH_FILL:
//      ctxcanvas->graphics->FillPath(ctxcanvas->fillBrush, graphics_path);
//      break;
//    case CD_PATH_STROKE:
//      ctxcanvas->graphics->DrawPath(ctxcanvas->linePen, graphics_path);
//      break;
//    case CD_PATH_FILLSTROKE:
//      ctxcanvas->graphics->FillPath(ctxcanvas->fillBrush, graphics_path);
//      ctxcanvas->graphics->DrawPath(ctxcanvas->linePen, graphics_path);
//      break;
//    case CD_PATH_CLIP:
//      ctxcanvas->graphics->SetClip(graphics_path, CombineModeIntersect);
//      break;
//    }
//  }
//
//  delete graphics_path;
//  break;
}

void cdpolySIM(cdCtxCanvas* ctxcanvas, int mode, cdPoint* poly, int n)
{
  cdCanvas* canvas = ((cdCtxCanvasBase*)ctxcanvas)->canvas;
  int i, reset = 1;

  switch(mode) 
  {
  case CD_CLOSED_LINES:
    poly[n] = poly[0];
    n++;
    /* continue */
  case CD_OPEN_LINES:
    if (simLineStyleNoReset)  /* Bezier simulation use several poly */
    {
      reset = 0;
      simLineStyleNoReset = 1;
    }
    for (i = 0; i< n - 1; i++)
      canvas->cxLine(canvas->ctxcanvas, poly[i].x, poly[i].y, poly[i+1].x, poly[i+1].y);
    if (reset) simLineStyleNoReset = 0;
    break;
  case CD_BEZIER:
    simLineStyleNoReset = 1;
    cdSimPolyBezier(canvas, poly, n);
    simLineStyleNoReset = 0;
    break;
  case CD_PATH:
    simLineStyleNoReset = 1;
    cdSimPolyPath(canvas, poly, n);
    simLineStyleNoReset = 0;
    break;
  case CD_FILL:
    {
      /* must set line attributes here, because fill simulation use cxLine */
      int oldwidth = cdCanvasLineWidth(canvas, 1);
      int oldstyle = cdCanvasLineStyle(canvas, CD_CONTINUOUS);
      int old_use_matrix = canvas->use_matrix;

      if (canvas->use_matrix && !canvas->invert_yaxis)
      {
        for(i = 0; i < n; i++)
          cdMatrixTransformPoint(canvas->matrix, poly[i].x, poly[i].y, &poly[i].x, &poly[i].y);
      }

      /* must disable transformation here, because line simulation use cxPixel */
      canvas->use_matrix = 0;

      simPolyFill(canvas->simulation, poly, n);

      canvas->use_matrix = old_use_matrix;
      cdCanvasLineStyle(canvas, oldstyle);
      cdCanvasLineWidth(canvas, oldwidth);
    }
    break;
  }
}