xref: /petsc/src/sys/classes/draw/interface/drect.c (revision 811af0c4b09a35de4306c442f88bd09fdc09897d)
15c6c1daeSBarry Smith 
25c6c1daeSBarry Smith /*
35c6c1daeSBarry Smith        Provides the calling sequences for all the basic PetscDraw routines.
45c6c1daeSBarry Smith */
5af0996ceSBarry Smith #include <petsc/private/drawimpl.h> /*I "petscdraw.h" I*/
65c6c1daeSBarry Smith 
75c6c1daeSBarry Smith /*@C
8*811af0c4SBarry Smith    PetscDrawIndicatorFunction - Draws an indicator function (where a relationship is true) on a `PetscDraw`
95c6c1daeSBarry Smith 
105c6c1daeSBarry Smith    Not collective
115c6c1daeSBarry Smith 
12d8d19677SJose E. Roman    Input Parameters:
13*811af0c4SBarry Smith +  draw - a `PetscDraw`
145c6c1daeSBarry Smith .  xmin,xmax,ymin,ymax - region to draw indicator function
155c6c1daeSBarry Smith -  f - the indicator function
165c6c1daeSBarry Smith 
175c6c1daeSBarry Smith    Level: developer
185c6c1daeSBarry Smith 
19*811af0c4SBarry Smith .seealso: `PetscDraw`
205c6c1daeSBarry Smith @*/
219371c9d4SSatish Balay PetscErrorCode PetscDrawIndicatorFunction(PetscDraw draw, PetscReal xmin, PetscReal xmax, PetscReal ymin, PetscReal ymax, int c, PetscErrorCode (*indicator)(void *, PetscReal, PetscReal, PetscBool *), void *ctx) {
22a7e8706aSLisandro Dalcin   int       i, j, xstart, ystart, xend, yend;
235c6c1daeSBarry Smith   PetscReal x, y;
245c6c1daeSBarry Smith   PetscBool isnull, flg;
255c6c1daeSBarry Smith 
265c6c1daeSBarry Smith   PetscFunctionBegin;
275c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
289566063dSJacob Faibussowitsch   PetscCall(PetscDrawIsNull(draw, &isnull));
295c6c1daeSBarry Smith   if (isnull) PetscFunctionReturn(0);
305c6c1daeSBarry Smith 
319566063dSJacob Faibussowitsch   PetscCall(PetscDrawCoordinateToPixel(draw, xmin, ymin, &xstart, &ystart));
329566063dSJacob Faibussowitsch   PetscCall(PetscDrawCoordinateToPixel(draw, xmax, ymax, &xend, &yend));
339371c9d4SSatish Balay   if (yend < ystart) {
349371c9d4SSatish Balay     PetscInt tmp = ystart;
359371c9d4SSatish Balay     ystart       = yend;
369371c9d4SSatish Balay     yend         = tmp;
379371c9d4SSatish Balay   }
3845f3bb6eSLisandro Dalcin 
3945f3bb6eSLisandro Dalcin   for (i = xstart; i <= xend; i++) {
4045f3bb6eSLisandro Dalcin     for (j = ystart; j <= yend; j++) {
419566063dSJacob Faibussowitsch       PetscCall(PetscDrawPixelToCoordinate(draw, i, j, &x, &y));
429566063dSJacob Faibussowitsch       PetscCall(indicator(ctx, x, y, &flg));
431baa6e33SBarry Smith       if (flg) PetscCall(PetscDrawPointPixel(draw, i, j, c));
445c6c1daeSBarry Smith     }
455c6c1daeSBarry Smith   }
465c6c1daeSBarry Smith   PetscFunctionReturn(0);
475c6c1daeSBarry Smith }
485c6c1daeSBarry Smith 
495c6c1daeSBarry Smith /*@C
50*811af0c4SBarry Smith    PetscDrawCoordinateToPixel - given a coordinate in a `PetscDraw` returns the pixel location
515c6c1daeSBarry Smith 
525c6c1daeSBarry Smith    Not collective
535c6c1daeSBarry Smith 
545c6c1daeSBarry Smith    Input Parameters:
555c6c1daeSBarry Smith +  draw - the draw where the coordinates are defined
566b867d5aSJose E. Roman .  x - the horizontal coordinate
576b867d5aSJose E. Roman -  y - the vertical coordinate
585c6c1daeSBarry Smith 
595c6c1daeSBarry Smith    Output Parameters:
606b867d5aSJose E. Roman +  i - the horizontal pixel location
616b867d5aSJose E. Roman -  j - the vertical pixel location
625c6c1daeSBarry Smith 
635c6c1daeSBarry Smith    Level: developer
645c6c1daeSBarry Smith 
65*811af0c4SBarry Smith .seealso: `PetscDraw`
665c6c1daeSBarry Smith @*/
679371c9d4SSatish Balay PetscErrorCode PetscDrawCoordinateToPixel(PetscDraw draw, PetscReal x, PetscReal y, int *i, int *j) {
685c6c1daeSBarry Smith   PetscFunctionBegin;
695c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
70dbbe0bcdSBarry Smith   PetscUseTypeMethod(draw, coordinatetopixel, x, y, i, j);
715c6c1daeSBarry Smith   PetscFunctionReturn(0);
725c6c1daeSBarry Smith }
735c6c1daeSBarry Smith 
745c6c1daeSBarry Smith /*@C
75*811af0c4SBarry Smith    PetscDrawPixelToCoordinate - given a pixel in a `PetscDraw` returns the coordinate
765c6c1daeSBarry Smith 
775c6c1daeSBarry Smith    Not collective
785c6c1daeSBarry Smith 
795c6c1daeSBarry Smith    Input Parameters:
805c6c1daeSBarry Smith +  draw - the draw where the coordinates are defined
816b867d5aSJose E. Roman .  i - the horizontal pixel location
826b867d5aSJose E. Roman -  j - the vertical pixel location
835c6c1daeSBarry Smith 
845c6c1daeSBarry Smith    Output Parameters:
856b867d5aSJose E. Roman +  x - the horizontal coordinate
866b867d5aSJose E. Roman -  y - the vertical coordinate
875c6c1daeSBarry Smith 
885c6c1daeSBarry Smith    Level: developer
895c6c1daeSBarry Smith 
90*811af0c4SBarry Smith .seealso: `PetscDraw`
915c6c1daeSBarry Smith @*/
929371c9d4SSatish Balay PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw, int i, int j, PetscReal *x, PetscReal *y) {
935c6c1daeSBarry Smith   PetscFunctionBegin;
945c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
95dbbe0bcdSBarry Smith   PetscUseTypeMethod(draw, pixeltocoordinate, i, j, x, y);
965c6c1daeSBarry Smith   PetscFunctionReturn(0);
975c6c1daeSBarry Smith }
985c6c1daeSBarry Smith 
995c6c1daeSBarry Smith /*@
100*811af0c4SBarry Smith    PetscDrawRectangle - draws a rectangle  onto a drawable.
1015c6c1daeSBarry Smith 
1025c6c1daeSBarry Smith    Not Collective
1035c6c1daeSBarry Smith 
1045c6c1daeSBarry Smith    Input Parameters:
1055c6c1daeSBarry Smith +  draw - the drawing context
1065c6c1daeSBarry Smith .  xl,yl,xr,yr - the coordinates of the lower left, upper right corners
1075c6c1daeSBarry Smith -  c1,c2,c3,c4 - the colors of the four corners in counter clockwise order
1085c6c1daeSBarry Smith 
1095c6c1daeSBarry Smith    Level: beginner
1105c6c1daeSBarry Smith 
111*811af0c4SBarry Smith .seealso: `PetscDraw`, `PetscDrawLine()`, `PetscDrawRectangle()`, `PetscDrawTriangle()`, `PetscDrawEllipse()`,
112db781477SPatrick Sanan           `PetscDrawMarker()`, `PetscDrawPoint()`, `PetscDrawString()`, `PetscDrawPoint()`, `PetscDrawArrow()`
1135c6c1daeSBarry Smith @*/
1149371c9d4SSatish Balay PetscErrorCode PetscDrawRectangle(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int c1, int c2, int c3, int c4) {
1155c6c1daeSBarry Smith   PetscFunctionBegin;
1165c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
117dbbe0bcdSBarry Smith   PetscUseTypeMethod(draw, rectangle, xl, yl, xr, yr, c1, c2, c3, c4);
1185c6c1daeSBarry Smith   PetscFunctionReturn(0);
1195c6c1daeSBarry Smith }
120