Changeset 47 for trunk/luigi/base.d

Show
Ignore:
Timestamp:
02/24/07 04:54:29 (2 years ago)
Author:
baxissimo
Message:

Just some minor tweaks and convenience additions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/luigi/base.d

    r37 r47  
    7272    float y2(float v) { return h=(v-y); } 
    7373 
     74    Point center() { return Point(x+width/2,y+height/2); } 
     75    Point minpos() { return Point(x1,y1); } 
     76    Point maxpos() { return Point(x2,y2); } 
     77 
    7478    /** Rect constructor */ 
    7579    static Rect opCall(float rx = 0, float ry = 0, float rwidth = 0, float rheight = 0) { 
     
    8589        set(leftx,topy,rightx-leftx,bottomy-topy); 
    8690    } 
     91    alias setLTRB setMinMax; 
    8792 
    8893    /** Point-inside-rect test */ 
     
    116121    /** Grow rect to enclose point p. */ 
    117122    void enclose(Point p) { 
     123        if (!valid) { 
     124            x = p.x; y=p.y; 
     125            w = 0; h = 0; 
     126        } 
    118127        if (p.x < x) {  w = x2-p.x;  x = p.x; } 
    119128        else if (p.x > x2) {  x2 = p.x; } 
     
    122131    } 
    123132 
     133 
     134    bool valid() { 
     135        return !(math.isnan(x)||math.isnan(y)|| 
     136                 math.isnan(w)||math.isnan(h)); 
     137    } 
    124138 
    125139    char[] toString() { 
     
    162176    } 
    163177 
     178    /** Return a pointer to the first element */ 
     179    float *ptr() { return &x; } 
    164180} 
    165181