OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [tags/] [eco32-0.26/] [lcc/] [tst/] [struct.c] - Diff between revs 4 and 270

Only display areas with differences | Details | Blame | View Log

Rev 4 Rev 270
typedef struct point { int x,y; } point;
typedef struct point { int x,y; } point;
typedef struct rect { point pt1, pt2; } rect;
typedef struct rect { point pt1, pt2; } rect;
 
 
point addpoint(point p1, point p2) {    /* add two points */
point addpoint(point p1, point p2) {    /* add two points */
        p1.x += p2.x;
        p1.x += p2.x;
        p1.y += p2.y;
        p1.y += p2.y;
        return p1;
        return p1;
}
}
 
 
#define min(a, b) ((a) < (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
 
 
rect canonrect(rect r) {                /* canonicalize rectangle coordinates */
rect canonrect(rect r) {                /* canonicalize rectangle coordinates */
        rect temp;
        rect temp;
 
 
        temp.pt1.x = min(r.pt1.x, r.pt2.x);
        temp.pt1.x = min(r.pt1.x, r.pt2.x);
        temp.pt1.y = min(r.pt1.y, r.pt2.y);
        temp.pt1.y = min(r.pt1.y, r.pt2.y);
        temp.pt2.x = max(r.pt1.x, r.pt2.x);
        temp.pt2.x = max(r.pt1.x, r.pt2.x);
        temp.pt2.y = max(r.pt1.y, r.pt2.y);
        temp.pt2.y = max(r.pt1.y, r.pt2.y);
        return temp;
        return temp;
}
}
 
 
point makepoint(int x, int y) {         /* make a point from x and y components */
point makepoint(int x, int y) {         /* make a point from x and y components */
        point p;
        point p;
 
 
        p.x = x;
        p.x = x;
        p.y = y;
        p.y = y;
        return p;
        return p;
}
}
 
 
rect makerect(point p1, point p2) {     /* make a rectangle from two points */
rect makerect(point p1, point p2) {     /* make a rectangle from two points */
        rect r;
        rect r;
 
 
        r.pt1 = p1;
        r.pt1 = p1;
        r.pt2 = p2;
        r.pt2 = p2;
        return canonrect(r);
        return canonrect(r);
}
}
 
 
int ptinrect(point p, rect r) {         /* is p in r? */
int ptinrect(point p, rect r) {         /* is p in r? */
        return p.x >= r.pt1.x && p.x < r.pt2.x
        return p.x >= r.pt1.x && p.x < r.pt2.x
                && p.y >= r.pt1.y && p.y < r.pt2.y;
                && p.y >= r.pt1.y && p.y < r.pt2.y;
}
}
 
 
struct odd {char a[3]; } y = {'a', 'b', 0};
struct odd {char a[3]; } y = {'a', 'b', 0};
 
 
odd(struct odd y) {
odd(struct odd y) {
        struct odd x = y;
        struct odd x = y;
        printf("%s\n", x.a);
        printf("%s\n", x.a);
}
}
 
 
main() {
main() {
        int i;
        int i;
        point x, origin = { 0, 0 }, maxpt = { 320, 320 };
        point x, origin = { 0, 0 }, maxpt = { 320, 320 };
        point pts[] = { -1, -1, 1, 1, 20, 300, 500, 400 };
        point pts[] = { -1, -1, 1, 1, 20, 300, 500, 400 };
        rect screen = makerect(addpoint(maxpt, makepoint(-10, -10)),
        rect screen = makerect(addpoint(maxpt, makepoint(-10, -10)),
                addpoint(origin, makepoint(10, 10)));
                addpoint(origin, makepoint(10, 10)));
 
 
        for (i = 0; i < sizeof pts/sizeof pts[0]; i++) {
        for (i = 0; i < sizeof pts/sizeof pts[0]; i++) {
                printf("(%d,%d) is ", pts[i].x,
                printf("(%d,%d) is ", pts[i].x,
                        (x = makepoint(pts[i].x, pts[i].y)).y);
                        (x = makepoint(pts[i].x, pts[i].y)).y);
                if (ptinrect(x, screen) == 0)
                if (ptinrect(x, screen) == 0)
                        printf("not ");
                        printf("not ");
                printf("within [%d,%d; %d,%d]\n", screen.pt1.x, screen.pt1.y,
                printf("within [%d,%d; %d,%d]\n", screen.pt1.x, screen.pt1.y,
                        screen.pt2.x, screen.pt2.y);
                        screen.pt2.x, screen.pt2.y);
        }
        }
        odd(y);
        odd(y);
        exit(0);
        exit(0);
}
}
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.