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: . c         - the color of the region
 15: . indicator - the indicator function
 16: - ctx       - the context to pass to the indicator function

 18:   Level: developer

 20: .seealso: `PetscDraw`
 21: @*/
 22: PetscErrorCode PetscDrawIndicatorFunction(PetscDraw draw, PetscReal xmin, PetscReal xmax, PetscReal ymin, PetscReal ymax, int c, PetscErrorCode (*indicator)(void *, PetscReal, PetscReal, PetscBool *), void *ctx)
 23: {
 24:   int       i, j, xstart, ystart, xend, yend;
 25:   PetscReal x, y;
 26:   PetscBool isnull, flg;

 28:   PetscFunctionBegin;
 30:   PetscCall(PetscDrawIsNull(draw, &isnull));
 31:   if (isnull) PetscFunctionReturn(PETSC_SUCCESS);

 33:   PetscCall(PetscDrawCoordinateToPixel(draw, xmin, ymin, &xstart, &ystart));
 34:   PetscCall(PetscDrawCoordinateToPixel(draw, xmax, ymax, &xend, &yend));
 35:   if (yend < ystart) {
 36:     int tmp = ystart;
 37:     ystart  = yend;
 38:     yend    = tmp;
 39:   }

 41:   for (i = xstart; i <= xend; i++) {
 42:     for (j = ystart; j <= yend; j++) {
 43:       PetscCall(PetscDrawPixelToCoordinate(draw, i, j, &x, &y));
 44:       PetscCall(indicator(ctx, x, y, &flg));
 45:       if (flg) PetscCall(PetscDrawPointPixel(draw, i, j, c));
 46:     }
 47:   }
 48:   PetscFunctionReturn(PETSC_SUCCESS);
 49: }

 51: /*@
 52:   PetscDrawCoordinateToPixel - given a coordinate in a `PetscDraw` returns the pixel location

 54:   Not Collective

 56:   Input Parameters:
 57: + draw - the draw where the coordinates are defined
 58: . x    - the horizontal coordinate
 59: - y    - the vertical coordinate

 61:   Output Parameters:
 62: + i - the horizontal pixel location
 63: - j - the vertical pixel location

 65:   Level: developer

 67: .seealso: `PetscDraw`
 68: @*/
 69: PetscErrorCode PetscDrawCoordinateToPixel(PetscDraw draw, PetscReal x, PetscReal y, int *i, int *j)
 70: {
 71:   PetscFunctionBegin;
 73:   PetscUseTypeMethod(draw, coordinatetopixel, x, y, i, j);
 74:   PetscFunctionReturn(PETSC_SUCCESS);
 75: }

 77: /*@
 78:   PetscDrawPixelToCoordinate - given a pixel in a `PetscDraw` returns the coordinate

 80:   Not Collective

 82:   Input Parameters:
 83: + draw - the draw where the coordinates are defined
 84: . i    - the horizontal pixel location
 85: - j    - the vertical pixel location

 87:   Output Parameters:
 88: + x - the horizontal coordinate
 89: - y - the vertical coordinate

 91:   Level: developer

 93: .seealso: `PetscDraw`
 94: @*/
 95: PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw, int i, int j, PetscReal *x, PetscReal *y)
 96: {
 97:   PetscFunctionBegin;
 99:   PetscUseTypeMethod(draw, pixeltocoordinate, i, j, x, y);
100:   PetscFunctionReturn(PETSC_SUCCESS);
101: }

103: /*@
104:   PetscDrawRectangle - draws a rectangle onto a `PetscDraw` object

106:   Not Collective

108:   Input Parameters:
109: + draw - the drawing context
110: . xl   - coordinates of the lower left corner
111: . yl   - coordinates of the lower left corner
112: . xr   - coordinate of the upper right corner
113: . yr   - coordinate of the upper right corner
114: . c1   - the color of the first corner
115: . c2   - the color of the second corner
116: . c3   - the color of the third corner
117: - c4   - the color of the fourth corner

119:   Level: beginner

121: .seealso: `PetscDraw`, `PetscDrawLine()`, `PetscDrawTriangle()`, `PetscDrawEllipse()`,
122:           `PetscDrawMarker()`, `PetscDrawPoint()`, `PetscDrawString()`, `PetscDrawArrow()`
123: @*/
124: PetscErrorCode PetscDrawRectangle(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int c1, int c2, int c3, int c4)
125: {
126:   PetscFunctionBegin;
128:   PetscUseTypeMethod(draw, rectangle, xl, yl, xr, yr, c1, c2, c3, c4);
129:   PetscFunctionReturn(PETSC_SUCCESS);
130: }