Actual source code: drect.c
1: #include <petsc/private/drawimpl.h>
3: /*@C
4: PetscDrawIndicatorFunction - Draws an indicator function (where a relationship is true) on a `PetscDraw`
6: Not Collective
8: Input Parameters:
9: + draw - a `PetscDraw`
10: . xmin - region to draw indicator function
11: . xmax - region to draw indicator function
12: . ymin - region to draw indicator function
13: . ymax - region to draw indicator function
14: - f - the indicator function
16: Level: developer
18: .seealso: `PetscDraw`
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: {
22: int i, j, xstart, ystart, xend, yend;
23: PetscReal x, y;
24: PetscBool isnull, flg;
26: PetscFunctionBegin;
28: PetscCall(PetscDrawIsNull(draw, &isnull));
29: if (isnull) PetscFunctionReturn(PETSC_SUCCESS);
31: PetscCall(PetscDrawCoordinateToPixel(draw, xmin, ymin, &xstart, &ystart));
32: PetscCall(PetscDrawCoordinateToPixel(draw, xmax, ymax, &xend, ¥d));
33: if (yend < ystart) {
34: PetscInt tmp = ystart;
35: ystart = yend;
36: yend = tmp;
37: }
39: for (i = xstart; i <= xend; i++) {
40: for (j = ystart; j <= yend; j++) {
41: PetscCall(PetscDrawPixelToCoordinate(draw, i, j, &x, &y));
42: PetscCall(indicator(ctx, x, y, &flg));
43: if (flg) PetscCall(PetscDrawPointPixel(draw, i, j, c));
44: }
45: }
46: PetscFunctionReturn(PETSC_SUCCESS);
47: }
49: /*@C
50: PetscDrawCoordinateToPixel - given a coordinate in a `PetscDraw` returns the pixel location
52: Not Collective
54: Input Parameters:
55: + draw - the draw where the coordinates are defined
56: . x - the horizontal coordinate
57: - y - the vertical coordinate
59: Output Parameters:
60: + i - the horizontal pixel location
61: - j - the vertical pixel location
63: Level: developer
65: .seealso: `PetscDraw`
66: @*/
67: PetscErrorCode PetscDrawCoordinateToPixel(PetscDraw draw, PetscReal x, PetscReal y, int *i, int *j)
68: {
69: PetscFunctionBegin;
71: PetscUseTypeMethod(draw, coordinatetopixel, x, y, i, j);
72: PetscFunctionReturn(PETSC_SUCCESS);
73: }
75: /*@C
76: PetscDrawPixelToCoordinate - given a pixel in a `PetscDraw` returns the coordinate
78: Not Collective
80: Input Parameters:
81: + draw - the draw where the coordinates are defined
82: . i - the horizontal pixel location
83: - j - the vertical pixel location
85: Output Parameters:
86: + x - the horizontal coordinate
87: - y - the vertical coordinate
89: Level: developer
91: .seealso: `PetscDraw`
92: @*/
93: PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw, int i, int j, PetscReal *x, PetscReal *y)
94: {
95: PetscFunctionBegin;
97: PetscUseTypeMethod(draw, pixeltocoordinate, i, j, x, y);
98: PetscFunctionReturn(PETSC_SUCCESS);
99: }
101: /*@
102: PetscDrawRectangle - draws a rectangle onto a `PetscDraw` object
104: Not Collective
106: Input Parameters:
107: + draw - the drawing context
108: . xl - coordinates of the lower left corner
109: . yl - coordinates of the lower left corner
110: . xr - coordinate of the upper right corner
111: . yr - coordinate of the upper right corner
112: . c1 - the color of the first corner
113: . c2 - the color of the second corner
114: . c3 - the color of the third corner
115: - c4 - the color of the fourth corner
117: Level: beginner
119: .seealso: `PetscDraw`, `PetscDrawLine()`, `PetscDrawRectangle()`, `PetscDrawTriangle()`, `PetscDrawEllipse()`,
120: `PetscDrawMarker()`, `PetscDrawPoint()`, `PetscDrawString()`, `PetscDrawPoint()`, `PetscDrawArrow()`
121: @*/
122: PetscErrorCode PetscDrawRectangle(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int c1, int c2, int c3, int c4)
123: {
124: PetscFunctionBegin;
126: PetscUseTypeMethod(draw, rectangle, xl, yl, xr, yr, c1, c2, c3, c4);
127: PetscFunctionReturn(PETSC_SUCCESS);
128: }