xref: /petsc/src/sys/classes/draw/interface/drect.c (revision 9371c9d470a9602b6d10a8bf50c9b2280a79e45a)
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
85c6c1daeSBarry 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:
135c6c1daeSBarry 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 
195c6c1daeSBarry Smith @*/
20*9371c9d4SSatish Balay PetscErrorCode PetscDrawIndicatorFunction(PetscDraw draw, PetscReal xmin, PetscReal xmax, PetscReal ymin, PetscReal ymax, int c, PetscErrorCode (*indicator)(void *, PetscReal, PetscReal, PetscBool *), void *ctx) {
21a7e8706aSLisandro Dalcin   int       i, j, xstart, ystart, xend, yend;
225c6c1daeSBarry Smith   PetscReal x, y;
235c6c1daeSBarry Smith   PetscBool isnull, flg;
245c6c1daeSBarry Smith 
255c6c1daeSBarry Smith   PetscFunctionBegin;
265c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
279566063dSJacob Faibussowitsch   PetscCall(PetscDrawIsNull(draw, &isnull));
285c6c1daeSBarry Smith   if (isnull) PetscFunctionReturn(0);
295c6c1daeSBarry Smith 
309566063dSJacob Faibussowitsch   PetscCall(PetscDrawCoordinateToPixel(draw, xmin, ymin, &xstart, &ystart));
319566063dSJacob Faibussowitsch   PetscCall(PetscDrawCoordinateToPixel(draw, xmax, ymax, &xend, &yend));
32*9371c9d4SSatish Balay   if (yend < ystart) {
33*9371c9d4SSatish Balay     PetscInt tmp = ystart;
34*9371c9d4SSatish Balay     ystart       = yend;
35*9371c9d4SSatish Balay     yend         = tmp;
36*9371c9d4SSatish Balay   }
3745f3bb6eSLisandro Dalcin 
3845f3bb6eSLisandro Dalcin   for (i = xstart; i <= xend; i++) {
3945f3bb6eSLisandro Dalcin     for (j = ystart; j <= yend; j++) {
409566063dSJacob Faibussowitsch       PetscCall(PetscDrawPixelToCoordinate(draw, i, j, &x, &y));
419566063dSJacob Faibussowitsch       PetscCall(indicator(ctx, x, y, &flg));
421baa6e33SBarry Smith       if (flg) PetscCall(PetscDrawPointPixel(draw, i, j, c));
435c6c1daeSBarry Smith     }
445c6c1daeSBarry Smith   }
455c6c1daeSBarry Smith   PetscFunctionReturn(0);
465c6c1daeSBarry Smith }
475c6c1daeSBarry Smith 
485c6c1daeSBarry Smith /*@C
495c6c1daeSBarry Smith    PetscDrawCoordinateToPixel - given a coordinate in a PetscDraw returns the pixel location
505c6c1daeSBarry Smith 
515c6c1daeSBarry Smith    Not collective
525c6c1daeSBarry Smith 
535c6c1daeSBarry Smith    Input Parameters:
545c6c1daeSBarry Smith +  draw - the draw where the coordinates are defined
556b867d5aSJose E. Roman .  x - the horizontal coordinate
566b867d5aSJose E. Roman -  y - the vertical coordinate
575c6c1daeSBarry Smith 
585c6c1daeSBarry Smith    Output Parameters:
596b867d5aSJose E. Roman +  i - the horizontal pixel location
606b867d5aSJose E. Roman -  j - the vertical pixel location
615c6c1daeSBarry Smith 
625c6c1daeSBarry Smith    Level: developer
635c6c1daeSBarry Smith 
645c6c1daeSBarry Smith @*/
65*9371c9d4SSatish Balay PetscErrorCode PetscDrawCoordinateToPixel(PetscDraw draw, PetscReal x, PetscReal y, int *i, int *j) {
665c6c1daeSBarry Smith   PetscFunctionBegin;
675c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
68dbbe0bcdSBarry Smith   PetscUseTypeMethod(draw, coordinatetopixel, x, y, i, j);
695c6c1daeSBarry Smith   PetscFunctionReturn(0);
705c6c1daeSBarry Smith }
715c6c1daeSBarry Smith 
725c6c1daeSBarry Smith /*@C
735c6c1daeSBarry Smith    PetscDrawPixelToCoordinate - given a pixel in a PetscDraw returns the coordinate
745c6c1daeSBarry Smith 
755c6c1daeSBarry Smith    Not collective
765c6c1daeSBarry Smith 
775c6c1daeSBarry Smith    Input Parameters:
785c6c1daeSBarry Smith +  draw - the draw where the coordinates are defined
796b867d5aSJose E. Roman .  i - the horizontal pixel location
806b867d5aSJose E. Roman -  j - the vertical pixel location
815c6c1daeSBarry Smith 
825c6c1daeSBarry Smith    Output Parameters:
836b867d5aSJose E. Roman +  x - the horizontal coordinate
846b867d5aSJose E. Roman -  y - the vertical coordinate
855c6c1daeSBarry Smith 
865c6c1daeSBarry Smith    Level: developer
875c6c1daeSBarry Smith 
885c6c1daeSBarry Smith @*/
89*9371c9d4SSatish Balay PetscErrorCode PetscDrawPixelToCoordinate(PetscDraw draw, int i, int j, PetscReal *x, PetscReal *y) {
905c6c1daeSBarry Smith   PetscFunctionBegin;
915c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
92dbbe0bcdSBarry Smith   PetscUseTypeMethod(draw, pixeltocoordinate, i, j, x, y);
935c6c1daeSBarry Smith   PetscFunctionReturn(0);
945c6c1daeSBarry Smith }
955c6c1daeSBarry Smith 
965c6c1daeSBarry Smith /*@
975c6c1daeSBarry Smith    PetscDrawRectangle - PetscDraws a rectangle  onto a drawable.
985c6c1daeSBarry Smith 
995c6c1daeSBarry Smith    Not Collective
1005c6c1daeSBarry Smith 
1015c6c1daeSBarry Smith    Input Parameters:
1025c6c1daeSBarry Smith +  draw - the drawing context
1035c6c1daeSBarry Smith .  xl,yl,xr,yr - the coordinates of the lower left, upper right corners
1045c6c1daeSBarry Smith -  c1,c2,c3,c4 - the colors of the four corners in counter clockwise order
1055c6c1daeSBarry Smith 
1065c6c1daeSBarry Smith    Level: beginner
1075c6c1daeSBarry Smith 
108db781477SPatrick Sanan .seealso: `PetscDrawLine()`, `PetscDrawRectangle()`, `PetscDrawTriangle()`, `PetscDrawEllipse()`,
109db781477SPatrick Sanan           `PetscDrawMarker()`, `PetscDrawPoint()`, `PetscDrawString()`, `PetscDrawPoint()`, `PetscDrawArrow()`
110ba1e01c4SBarry Smith 
1115c6c1daeSBarry Smith @*/
112*9371c9d4SSatish Balay PetscErrorCode PetscDrawRectangle(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int c1, int c2, int c3, int c4) {
1135c6c1daeSBarry Smith   PetscFunctionBegin;
1145c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
115dbbe0bcdSBarry Smith   PetscUseTypeMethod(draw, rectangle, xl, yl, xr, yr, c1, c2, c3, c4);
1165c6c1daeSBarry Smith   PetscFunctionReturn(0);
1175c6c1daeSBarry Smith }
118