Example #1
0
template<class T> T ___max(int n, int key, T a, T b, T c, ...) {
    T m = ___max(2, key, ___max(2, key, a, b), c);
    va_list ap;
    va_start(ap, c);
    for(int i=0; i<n-3; i++) {
        T t = va_arg(ap, T);
        if(__cmp(t,m)==1) m=t;
    }
    va_end(ap);
    return m;
}
Example #2
0
template<class T, class B> T ___max(int n, B (*key)(T), T a, T b, T c, ...) {
    T m = ___max(2, key, ___max(2, key, a, b), c);
    B maxkey = key(m);
    va_list ap;
    va_start(ap, c);
    for(int i=0; i<n-3; i++) {
        T t = va_arg(ap, T);
        if(__cmp(key(t),maxkey)==1)
            m=t;
    }
    va_end(ap);
    return m;
}
Example #3
0
tuple2<double, double> *rgb_to_hls(double r, double g, double b) {
    double bc, gc, h, l, maxc, minc, rc, s;

    maxc = ___max(3, ((double)(0)), r, g, b);
    minc = ___min(3, ((double)(0)), r, g, b);
    l = ((minc+maxc)/2.0);
    if ((minc==maxc)) {
        return (new tuple2<double, double>(3,0.0,l,0.0));
    }
    if ((l<=0.5)) {
        s = ((maxc-minc)/(maxc+minc));
    }
    else {
        s = ((maxc-minc)/((2.0-maxc)-minc));
    }
    rc = ((maxc-r)/(maxc-minc));
    gc = ((maxc-g)/(maxc-minc));
    bc = ((maxc-b)/(maxc-minc));
    if ((r==maxc)) {
        h = (bc-gc);
    }
    else if ((g==maxc)) {
        h = ((2.0+rc)-bc);
    }
    else {
        h = ((4.0+gc)-rc);
    }
    h = __mods((h/6.0), 1.0);
    return (new tuple2<double, double>(3,h,l,s));
}
Example #4
0
tuple2<double, double> *rgb_to_hsv(double r, double g, double b) {
    double bc, gc, h, maxc, minc, rc, s, v;

    maxc = ___max(3, ((double)(0)), r, g, b);
    minc = ___min(3, ((double)(0)), r, g, b);
    v = maxc;
    if ((minc==maxc)) {
        return (new tuple2<double, double>(3,0.0,0.0,v));
    }
    s = ((maxc-minc)/maxc);
    rc = ((maxc-r)/(maxc-minc));
    gc = ((maxc-g)/(maxc-minc));
    bc = ((maxc-b)/(maxc-minc));
    if ((r==maxc)) {
        h = (bc-gc);
    }
    else if ((g==maxc)) {
        h = ((2.0+rc)-bc);
    }
    else {
        h = ((4.0+gc)-rc);
    }
    h = __mods((h/6.0), 1.0);
    return (new tuple2<double, double>(3,h,s,v));
}
Example #5
0
tuple2<str *, str *> *splitext(str *p) {
    /**
    Split the extension from a pathname.

    Extension is everything from the last dot to the end.
    Return (root, ext), either part may be empty.
    */
    __ss_int i;

    i = p->rfind(const_0);
    if ((i<=___max(2, 0, p->rfind(const_6), p->rfind(const_4)))) {
        return (new tuple2<str *, str *>(2, p, const_1));
    }
    else {
        return (new tuple2<str *, str *>(2, p->__slice__(2, 0, i, 0), p->__slice__(1, i, 0, 0)));
    }
    return 0;
}
Example #6
0
str *commonprefix(list<str *> *m) {
    /**
    Given a list of pathnames, returns the longest common leading component
    */
    str *s1, *s2;
    __ss_int __11, __12, i, n;

    if ((!___bool(m))) {
        return const_0;
    }
    s1 = ___min(1, 0, m);
    s2 = ___max(1, 0, m);
    n = ___min(2, 0, len(s1), len(s2));

    FAST_FOR(i,0,n,1,11,12)
        if (__ne(s1->__getitem__(i), s2->__getitem__(i))) {
            return s1->__slice__(2, 0, i, 0);
        }
    END_FOR

    return s1->__slice__(2, 0, n, 0);
}
Example #7
0
template<class A> typename A::for_in_unit ___max(int nn, int, A *iter) { return ___max(nn, (int (*)(typename A::for_in_unit))0, iter); }