Mercurial > ~dholland > hg > ag > index.cgi
diff anagram/support/cint.cpp @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/anagram/support/cint.cpp Sat Dec 22 17:52:45 2007 -0500 @@ -0,0 +1,114 @@ +/* + * AnaGram, A System for Syntax Directed Programming + * Copyright 1993-1999 Parsifal Software. All Rights Reserved. + * See the file COPYING for license and usage terms. + * + * ci1.cpp - Complex integer arithmetic + */ + +#include "cint.h" +#include "minmax.h" + + +int cint::operator <= (const cint &s) const { + return x <= s.x && y <= s.y; +} + +int cint::operator < (const cint &s) const { + return x < s.x && y < s.y; +} + +int cint::operator >= (const cint &s) const { + return x >= s.x && y >= s.y; +} + +int cint::operator > (const cint &s) const { + return x > s.x && y > s.y; +} + +int cint::inside_rect(cint pos, cint size) const { + return *this >= pos && *this < pos + size; +} + +int cint::inside_rect(rect r) const { + return *this >= r.pos && *this < r.pos + r.size; +} + +int cint::on_boundary(cint pos, cint size) const { + if (!inside_rect(pos, size)) { + return 0; + } + pos += cint(1, 1); + size -= cint(2, 2); + if (inside_rect(pos, size)) { + return 0; + } + return 1; +} + + +cint ulci(cint a, cint b) { + cint c; + c.x = min(a.x, b.x); + c.y = min(a.y, b.y); + return c; +} + +cint lrci(cint a, cint b) { + cint c; + c.x = max(a.x, b.x); + c.y = max(a.y, b.y); + return c; +} + +cint measure_string(const char *s) { + int w=0, d=0, k=0; + cint m; + + while (*s) { + for (k=0; *s && *s!='\n'; s++, k++); + w = max(w, k); + d++; + if (*s =='\n') { + s++; + } + } + m.x = w; + m.y = d; + return m; +} + +int measure_line(const char *s) { + int m; + + m = 0; + while (*s && *s !='\n') { + m++; + s++; + } + return m; +} + + +cint place(cint measure, cint size, int jm) { + int hm, vm; + cint p; + + hm = (jm/10)&3; + vm = jm%10; + + size = ulci(measure, size); + p.x = (measure.x-size.x)*hm/2; + p.y = (measure.y-size.y)*vm/2; + return p; +} + + +rect place_rect(rect w, cint s, int jm) { + cint p; + + p = place(w.size, s, jm); + w.size = ulci(w.size, p+s) - p; + w.pos += p; + return w; +}