From cb1bc5e9b37b5f302221252e4078f8a68d30585b Mon Sep 17 00:00:00 2001 From: rodri Date: Sun, 21 Jun 2020 14:06:22 +0000 Subject: =?UTF-8?q?draw=20a=20proper=20set=20of=20axes=20using=20a=20na?= =?UTF-8?q?=C3=AFve=20method.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rframeviz.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/rframeviz.c b/rframeviz.c index 7a3e761..58fe7e3 100644 --- a/rframeviz.c +++ b/rframeviz.c @@ -61,6 +61,12 @@ ptinrect2(Point2 p, Rectangle2 r) p.y >= r.min.y && p.y < r.max.y; } +Point2 +perppt2(Point2 p) +{ + return Pt2(-p.y,p.x,p.w); +} + void initcontainers(Rectangle parent) { @@ -109,10 +115,53 @@ initpalette(void) pal[PCAux] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DRed); } +void +drawaxes(Container *c) +{ + Point2 painter; + + /* draw positive x axis */ + painter = c->p; + while(ptinrect2(painter, c->bbox)){ + line(screen, toscreen(painter), toscreen(addpt2(painter, mulpt2(c->bx, 10))), Endsquare, Endsquare, 0, pal[PCFg], ZP); + painter = addpt2(painter, mulpt2(c->bx, 10)); + /* unit markers */ + line(screen, toscreen(painter), toscreen(addpt2(painter, mulpt2(normvec2(perppt2(c->bx)), 4))), Endsquare, Endsquare, 0, pal[PCFg], ZP); + line(screen, toscreen(painter), toscreen(subpt2(painter, mulpt2(normvec2(perppt2(c->bx)), 4))), Endsquare, Endsquare, 0, pal[PCFg], ZP); + } + /* draw negative x axis */ + painter = c->p; + while(ptinrect2(painter, c->bbox)){ + line(screen, toscreen(painter), toscreen(subpt2(painter, mulpt2(c->bx, 10))), Endsquare, Endsquare, 0, pal[PCFg], ZP); + painter = subpt2(painter, mulpt2(c->bx, 10)); + /* unit markers */ + line(screen, toscreen(painter), toscreen(addpt2(painter, mulpt2(normvec2(perppt2(c->bx)), 4))), Endsquare, Endsquare, 0, pal[PCFg], ZP); + line(screen, toscreen(painter), toscreen(subpt2(painter, mulpt2(normvec2(perppt2(c->bx)), 4))), Endsquare, Endsquare, 0, pal[PCFg], ZP); + } + + /* draw positive y axis */ + painter = c->p; + while(ptinrect2(painter, c->bbox)){ + line(screen, toscreen(painter), toscreen(addpt2(painter, mulpt2(c->by, 10))), Endsquare, Endsquare, 0, pal[PCFg], ZP); + painter = addpt2(painter, mulpt2(c->by, 10)); + /* unit markers */ + line(screen, toscreen(painter), toscreen(addpt2(painter, mulpt2(normvec2(perppt2(c->by)), 4))), Endsquare, Endsquare, 0, pal[PCFg], ZP); + line(screen, toscreen(painter), toscreen(subpt2(painter, mulpt2(normvec2(perppt2(c->by)), 4))), Endsquare, Endsquare, 0, pal[PCFg], ZP); + } + /* draw negative y axis */ + painter = c->p; + while(ptinrect2(painter, c->bbox)){ + line(screen, toscreen(painter), toscreen(subpt2(painter, mulpt2(c->by, 10))), Endsquare, Endsquare, 0, pal[PCFg], ZP); + painter = subpt2(painter, mulpt2(c->by, 10)); + /* unit markers */ + line(screen, toscreen(painter), toscreen(addpt2(painter, mulpt2(normvec2(perppt2(c->by)), 4))), Endsquare, Endsquare, 0, pal[PCFg], ZP); + line(screen, toscreen(painter), toscreen(subpt2(painter, mulpt2(normvec2(perppt2(c->by)), 4))), Endsquare, Endsquare, 0, pal[PCFg], ZP); + } +} + void drawcontainers(void) { - static Rectangle UR = {0,0,1,1}; /* unit rectangle */ char buf[128]; int i; @@ -120,8 +169,7 @@ drawcontainers(void) line(screen, addpt(screen->r.min, Pt(0,Dy(screen->r)/2)), subpt(screen->r.max, Pt(0,Dy(screen->r)/2)), Endsquare, Endsquare, 0, pal[PCFg], ZP); for(i = 0; i < nelem(containers); i++){ - /* TODO: replace for an axis. */ - draw(screen, rectaddpt(UR, toscreen(containers[i].p)), pal[PCAux], nil, ZP); + drawaxes(&containers[i]); if(ptinrect2(invrframexform(thepoint, containers[i]), containers[i].bbox)) fillellipse(screen, toscreen(invrframexform(thepoint, containers[i])), 2, 2, pal[PCAux], ZP); -- cgit v1.2.3