On Mon, Apr 22, 2024 at 06:52:59PM +0800, Qian Yun wrote:
> Unlike the 3D case, where "GDrawPoint" is only limited involved,
> in 2D case, "GFillArc" and "GDrawLine" are more widely used,
> and even are used to draw the X11 interface itself.
> 
> So to avoid a bigger change and breakage, I duplicated code
> to add new function "GColorFillArc" and "GColorLine".

OK.  Ideally low level part of 2D and 3D graphics should be
very similar.  Basically 3D graphics computes projection onto
a plane and uses 2D operations to draw the result of projection.
There is some difference, because surface in 3D projects
to an area in 2D, so 3D graphics will mostly use area operations
like filling, but 2D may also fill areas and wireframe 3D projects
to a collection of lines.

> This is not unprecedented, for example PSColorPolygon/PSFillPolygon.
> 
> - Qian
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to fricas-devel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/fricas-devel/940d8bd0-a126-4f2c-823e-de1b2fe5bd1c%40gmail.com.

> diff --git a/src/graph/Gdraws/Gfun.c b/src/graph/Gdraws/Gfun.c
> index 5168de4e..d86fdc07 100644
> --- a/src/graph/Gdraws/Gfun.c
> +++ b/src/graph/Gdraws/Gfun.c
> @@ -363,6 +363,47 @@ GDrawLine(
>    return (s);
>  }
>  
> +/*
> + * GColorLine draws a colored line, see GDrawLine
> + */
> +
> +int
> +GColorLine(
> +          GC gc,                /* graphics context */
> +          Window wid,           /* window id */
> +          int x0, int y0, int x1, int y1, int color, int dFlag)
> +{
> +  int s = 0;
> +
> +  switch (dFlag) {
> +  case Xoption:
> +    XSetForeground(dsply, gc, (unsigned long) color);
> +    XDrawLine(dsply, wid, gc, x0, y0, x1, y1);
> +    break;
> +  case PSoption:
> +    {
> +      PSsetrgbcolor(color);
> +      FILE *fp;
> +
> +      if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) {
> +        fprintf(stderr, "GColorLine cannot open %s\n",
> +                psData[scriptps].filename);
> +        return (psError);
> +      }
> +
> +      psData[drawlineps].flag = yes;      /* sets procedure flag */
> +      fprintf(fp, "\t%d\t%d\t%d\t%d\tpsColorLine\n",
> +              x1, y1, x0, y0);
> +      s = fclose(fp);
> +    }
> +    break;
> +  default:
> +    fprintf(stderr, "GColorLine request (%d) not implemented yet.\n",
> +            dFlag);
> +    return (psError);
> +  }
> +  return (s);
> +}
>  
>  
>  
> @@ -683,6 +724,52 @@ GFillArc(
>    return (s);
>  }
>  
> +/*
> + * Draws and fills an arc with color; see GFillArc
> + */
> +
> +int
> +GColorFillArc(
> +         GC gc,                 /* graphics context */
> +         Window wid,            /* window id */
> +         int x, int y,
> +         unsigned int wdth, unsigned int hght,
> +         int ang1, int ang2, int color, int dFlag)
> +{
> +  int s = 0;
> +
> +  switch (dFlag) {
> +  case Xoption:                   /* angle: times 64 already */
> +    XSetForeground(dsply, gc, (unsigned long) color);
> +    XFillArc(dsply, wid, gc, x, y, wdth, hght, ang1, ang2);
> +    break;
> +  case PSoption:
> +    {
> +      PSsetrgbcolor(color);
> +
> +      FILE *fp;
> +
> +      if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) {
> +        fprintf(stderr, "GColorFillArc cannot open %s\n",
> +                psData[scriptps].filename);
> +        return (psError);
> +      }
> +
> +      psData[fillarcps].flag = yes;       /* sets procedure flag */
> +      fprintf(fp, "\t%d %d\t%d %d\t%d %d\t%d %d\tpsColorFillArc\n",
> +              x, y, hght, wdth, ang1 / 64, ang2 / 64,
> +              x + wdth / 2, y + hght / 2);
> +      s = fclose(fp);
> +    }
> +    break;
> +  default:
> +    fprintf(stderr, "GColorFillArc request (%d) not implemented yet\n",
> +            dFlag);
> +    return (psError);
> +  }
> +  return (s);
> +}
> +
>  /*
>   * Initializes the path and files to be used.
>   */
> diff --git a/src/graph/Gdraws/ps_files/drawline.ps 
> b/src/graph/Gdraws/ps_files/drawline.ps
> index 80962689..74f3a059 100644
> --- a/src/graph/Gdraws/ps_files/drawline.ps
> +++ b/src/graph/Gdraws/ps_files/drawline.ps
> @@ -7,3 +7,12 @@
>                  grestore }
>          def
>  
> +/psColorLine
> +        {       gsave
> +                newpath
> +                yVal moveto
> +                yVal lineto
> +                stroke
> +                grestore }
> +        def
> +
> diff --git a/src/graph/Gdraws/ps_files/fillarc.ps 
> b/src/graph/Gdraws/ps_files/fillarc.ps
> index fb0547e1..f7e5d10e 100644
> --- a/src/graph/Gdraws/ps_files/fillarc.ps
> +++ b/src/graph/Gdraws/ps_files/fillarc.ps
> @@ -18,3 +18,23 @@
>                  grestore }
>          def
>  
> +/psColorFillArc
> +        {       gsave
> +                yVal moveto
> +                newpath
> +                /sfactor 4 index 4 index div def
> +                1 sfactor scale
> +                6 5 roll                        %%       x on top of stack
> +                3 index 2 div add               %% define x origin
> +                6 5 roll                        %%       y on top of stack
> +                6 5 roll                        %%       h on top of stack
> +                2 div add yVal sfactor div      %% define y origin
> +                5 4 roll                        %%       w on top of stack
> +                2 div                           %% define radius
> +                5 3 roll                        %%       a1 a2 now on top
> +                1 index add
> +                arc                             %% draw clockwise arc
> +                fill
> +                grestore }
> +        def
> +
> diff --git a/src/graph/view2D/viewport2D.c b/src/graph/view2D/viewport2D.c
> index 0aaa182c..95b15f21 100644
> --- a/src/graph/view2D/viewport2D.c
> +++ b/src/graph/view2D/viewport2D.c
> @@ -210,6 +210,7 @@ drawTheViewport(int dFlag) /* display flag: X, PS,... */
>    int               xAxis,yAxis,dummyInt, ascent, descent;
>    int               unitWidth,boxX,boxY,boxW,boxH;
>    XCharStruct       overall;
> +  int               color;
>  
>    drawMore = yes;
>    vw = viewport->viewWindow;
> @@ -344,22 +345,15 @@ drawTheViewport(int dFlag) /* display flag: X, PS,... */
>            clipped = ptX > vwInfo.x && ptX < vwInfo.width &&
>              ptY > 0 && ptY < vwInfo.height;
>            if (graphStateArray[i].pointsOn) {
> -            if (dFlag==Xoption) {
> -              if (mono) {
> -                GSetForeground(globalGC1,
> -                               (float)monoColor((int)(aPoint->hue)),
> -                               dFlag);
> -              } else {
> -                GSetForeground(globalGC1,
> -                               (float)XSolidColor((int)(aPoint->hue),
> -                                                  (int)(aPoint->shade)),
> -                               dFlag);
> -              }
> +            if (mono) {
> +              color = monoColor((int)(aPoint->hue));
> +            } else {
> +              color = XSolidColor((int)(aPoint->hue), (int)(aPoint->shade));
>              }
>              if (clipped && !eqNANQ(ptX) && !eqNANQ(ptY))
> -              GFillArc(globalGC1,vw,ptX-halfSize,
> -                       ptY-halfSize,aList->pointSize,aList->pointSize,
> -                       0,360*64, dFlag);
> +              GColorFillArc(globalGC1, vw, ptX-halfSize, ptY-halfSize,
> +                            aList->pointSize, aList->pointSize,
> +                            0, 360*64, color, dFlag);
>  
>            } /* if points on */
>            for (ii=0, aPoint=aList->listOfPoints;
> @@ -370,41 +364,28 @@ drawTheViewport(int dFlag) /* display flag: X, PS,... */
>              clipped1 = ptX1 > vwInfo.x && ptX1 < vwInfo.width &&
>                ptY1 > 0 && ptY1 < vwInfo.height;
>              if (graphStateArray[i].connectOn) {
> -              if (dFlag==Xoption) {
> -                if (mono) {
> -                  GSetForeground(globalGC1,
> -                         (float)monoColor((int)(aList->lineColor-1)/5),
> -                         dFlag);
> +              if (mono) {
> +                color = monoColor((int)(aList->lineColor-1)/5);
>                  } else {
> -                  GSetForeground(globalGC1,
> -                         (float)XSolidColor((int)(aList->lineColor-1)/5,
> -                                            (int)((aList->lineColor-1)%5)/2),
> -                                 dFlag);
> +                color = XSolidColor((int)(aList->lineColor-1)/5,
> +                                    (int)((aList->lineColor-1)%5)/2);
>                  }
> -              } /* if X */
>                if ((clipped || clipped1) && !eqNANQ(ptX) && !eqNANQ(ptY) &&
>                    !eqNANQ(ptX1) && !eqNANQ(ptY1))
> -                GDrawLine(globalGC1,vw,
> -                          ptX,ptY,ptX1,ptY1,
> -                          dFlag);
> +                GColorLine(globalGC1, vw, ptX, ptY, ptX1, ptY1,
> +                           color, dFlag);
>              } /* if lines on */
>              if (graphStateArray[i].pointsOn) {
> -              if (dFlag==Xoption) {
>                  if (mono) {
> -                  GSetForeground(globalGC1,
> -                                 (float)monoColor((int)(aPoint->hue)),
> -                                 dFlag);
> +                  color = monoColor((int)(aPoint->hue));
>                  } else {
> -                  GSetForeground(globalGC1,
> -                                 (float)XSolidColor((int)(aPoint->hue),
> -                                                    (int)(aPoint->shade)),
> -                                 dFlag);
> +                  color = XSolidColor((int)(aPoint->hue),
> +                                      (int)(aPoint->shade));
>                  }
> -              }
>                if (clipped1 && !eqNANQ(ptX1) && !eqNANQ(ptY1))
> -                GFillArc(globalGC1,vw,ptX1-halfSize,
> -                         ptY1-halfSize,aList->pointSize,aList->pointSize,
> -                         0,360*64, dFlag);
> +                GColorFillArc(globalGC1, vw, ptX1-halfSize, ptY1-halfSize,
> +                              aList->pointSize, aList->pointSize,
> +                              0, 360*64, color, dFlag);
>              } /* if points on */
>              ptX = ptX1;  ptY = ptY1;  clipped = clipped1;
>            } /* for all points */


-- 
                              Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/ZiaWavdSt5B6Xjla%40fricas.org.

Reply via email to