xref: /petsc/src/sys/classes/draw/interface/drect.c (revision 9371c9d470a9602b6d10a8bf50c9b2280a79e45a)
1 
2 /*
3        Provides the calling sequences for all the basic PetscDraw routines.
4 */
5 #include <petsc/private/drawimpl.h> /*I "petscdraw.h" I*/
6 
7 /*@C
8    PetscDrawIndicatorFunction - Draws an indicator function (where a relationship is true) on a PetscDraw
9 
10    Not collective
11 
12    Input Parameters:
13 +  draw - a PetscDraw
14 .  xmin,xmax,ymin,ymax - region to draw indicator function
15 -  f - the indicator function
16 
17    Level: developer
18 
19 @*/
20 PetscErrorCode PetscDrawIndicatorFunction(PetscDraw draw, PetscReal xmin, PetscReal xmax, PetscReal ymin, PetscReal ymax, int c, PetscErrorCode (*indicator)(void *, PetscReal, PetscReal, PetscBool *), void *ctx) {
21   int       i, j, xstart, ystart, xend, yend;
22   PetscReal x, y;
23   PetscBool isnull, flg;
24 
25   PetscFunctionBegin;
26   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
27   PetscCall(PetscDrawIsNull(draw, &isnull));
28   if (isnull) PetscFunctionReturn(0);
29 
30   PetscCall(PetscDrawCoordinateToPixel(draw, xmin, ymin, &xstart, &ystart));
31   PetscCall(PetscDrawCoordinateToPixel(draw, xmax, ymax, &xend, &yend));
32   if (yend < ystart) {
33     PetscInt tmp = ystart;
34     ystart       = yend;
35     yend         = tmp;
36   }
37 
38   for (i = xstart; i <= xend; i++) {
39     for (j = ystart; j <= yend; j++) {
40       PetscCall(PetscDrawPixelToCoordinate(draw, i, j, &x, &y));
41       PetscCall(indicator(ctx, x, y, &flg));
42       if (flg) PetscCall(PetscDrawPointPixel(draw, i, j, c));
43     }
44   }
45   PetscFunctionReturn(0);
46 }
47 
48 /*@C
49    PetscDrawCoordinateToPixel - given a coordinate in a PetscDraw returns the pixel location
50 
51    Not collective
52 
53    Input Parameters:
54 +  draw - the draw where the coordinates are defined
55 .  x - the horizontal coordinate
56 -  y - the vertical coordinate
57 
58    Output Parameters:
59 +  i - the horizontal pixel location
60 -  j - the vertical pixel location
61 
62    Level: developer
63 
64 @*/
65 PetscErrorCode PetscDrawCoordinateToPixel(PetscDraw draw, PetscReal x, PetscReal y, int *i, int *j) {
66   PetscFunctionBegin;
67   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
68   PetscUseTypeMethod(draw, coordinatetopixel, x, y, i, j);
69   PetscFunctionReturn(0);
70 }
71 
72 /*@C
73    PetscDrawPixelToCoordinate - given a pixel in a PetscDraw returns the coordinate
74 
75    Not collective
76 
77    Input Parameters:
78 +  draw - the draw where the coordinates are defined
79 .  i - the horizontal pixel location
80 -  j - the vertical pixel location
81 
82    Output Parameters:
83 +  x - the horizontal coordinate
84 -  y - the vertical coordinate
85 
86    Level: developer
87 
88 @*/
89 PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw, int i, int j, PetscReal *x, PetscReal *y) {
90   PetscFunctionBegin;
91   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
92   PetscUseTypeMethod(draw, pixeltocoordinate, i, j, x, y);
93   PetscFunctionReturn(0);
94 }
95 
96 /*@
97    PetscDrawRectangle - PetscDraws a rectangle  onto a drawable.
98 
99    Not Collective
100 
101    Input Parameters:
102 +  draw - the drawing context
103 .  xl,yl,xr,yr - the coordinates of the lower left, upper right corners
104 -  c1,c2,c3,c4 - the colors of the four corners in counter clockwise order
105 
106    Level: beginner
107 
108 .seealso: `PetscDrawLine()`, `PetscDrawRectangle()`, `PetscDrawTriangle()`, `PetscDrawEllipse()`,
109           `PetscDrawMarker()`, `PetscDrawPoint()`, `PetscDrawString()`, `PetscDrawPoint()`, `PetscDrawArrow()`
110 
111 @*/
112 PetscErrorCode PetscDrawRectangle(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int c1, int c2, int c3, int c4) {
113   PetscFunctionBegin;
114   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
115   PetscUseTypeMethod(draw, rectangle, xl, yl, xr, yr, c1, c2, c3, c4);
116   PetscFunctionReturn(0);
117 }
118