Actual source code: drect.c


  2: /*
  3:        Provides the calling sequences for all the basic PetscDraw routines.
  4: */
  5: #include <petsc/private/drawimpl.h>

  7: /*@C
  8:    PetscDrawIndicatorFunction - Draws an indicator function (where a relationship is true) on a `PetscDraw`

 10:    Not collective

 12:    Input Parameters:
 13: +  draw - a `PetscDraw`
 14: .  xmin,xmax,ymin,ymax - region to draw indicator function
 15: -  f - the indicator function

 17:    Level: developer

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

 28:   PetscDrawIsNull(draw, &isnull);
 29:   if (isnull) return 0;

 31:   PetscDrawCoordinateToPixel(draw, xmin, ymin, &xstart, &ystart);
 32:   PetscDrawCoordinateToPixel(draw, xmax, ymax, &xend, &yend);
 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:       PetscDrawPixelToCoordinate(draw, i, j, &x, &y);
 42:       indicator(ctx, x, y, &flg);
 43:       if (flg) PetscDrawPointPixel(draw, i, j, c);
 44:     }
 45:   }
 46:   return 0;
 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: {
 70:   PetscUseTypeMethod(draw, coordinatetopixel, x, y, i, j);
 71:   return 0;
 72: }

 74: /*@C
 75:    PetscDrawPixelToCoordinate - given a pixel in a `PetscDraw` returns the coordinate

 77:    Not collective

 79:    Input Parameters:
 80: +  draw - the draw where the coordinates are defined
 81: .  i - the horizontal pixel location
 82: -  j - the vertical pixel location

 84:    Output Parameters:
 85: +  x - the horizontal coordinate
 86: -  y - the vertical coordinate

 88:    Level: developer

 90: .seealso: `PetscDraw`
 91: @*/
 92: PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw, int i, int j, PetscReal *x, PetscReal *y)
 93: {
 95:   PetscUseTypeMethod(draw, pixeltocoordinate, i, j, x, y);
 96:   return 0;
 97: }

 99: /*@
100:    PetscDrawRectangle - draws a rectangle  onto a drawable.

102:    Not Collective

104:    Input Parameters:
105: +  draw - the drawing context
106: .  xl,yl,xr,yr - the coordinates of the lower left, upper right corners
107: -  c1,c2,c3,c4 - the colors of the four corners in counter clockwise order

109:    Level: beginner

111: .seealso: `PetscDraw`, `PetscDrawLine()`, `PetscDrawRectangle()`, `PetscDrawTriangle()`, `PetscDrawEllipse()`,
112:           `PetscDrawMarker()`, `PetscDrawPoint()`, `PetscDrawString()`, `PetscDrawPoint()`, `PetscDrawArrow()`
113: @*/
114: PetscErrorCode PetscDrawRectangle(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int c1, int c2, int c3, int c4)
115: {
117:   PetscUseTypeMethod(draw, rectangle, xl, yl, xr, yr, c1, c2, c3, c4);
118:   return 0;
119: }