Mercurial > ~dholland > hg > ag > index.cgi
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* | |
2 * AnaGram, A System for Syntax Directed Programming | |
3 * Copyright 1993-1999 Parsifal Software. All Rights Reserved. | |
4 * See the file COPYING for license and usage terms. | |
5 * | |
6 * ci1.cpp - Complex integer arithmetic | |
7 */ | |
8 | |
9 #include "cint.h" | |
10 #include "minmax.h" | |
11 | |
12 | |
13 int cint::operator <= (const cint &s) const { | |
14 return x <= s.x && y <= s.y; | |
15 } | |
16 | |
17 int cint::operator < (const cint &s) const { | |
18 return x < s.x && y < s.y; | |
19 } | |
20 | |
21 int cint::operator >= (const cint &s) const { | |
22 return x >= s.x && y >= s.y; | |
23 } | |
24 | |
25 int cint::operator > (const cint &s) const { | |
26 return x > s.x && y > s.y; | |
27 } | |
28 | |
29 int cint::inside_rect(cint pos, cint size) const { | |
30 return *this >= pos && *this < pos + size; | |
31 } | |
32 | |
33 int cint::inside_rect(rect r) const { | |
34 return *this >= r.pos && *this < r.pos + r.size; | |
35 } | |
36 | |
37 int cint::on_boundary(cint pos, cint size) const { | |
38 if (!inside_rect(pos, size)) { | |
39 return 0; | |
40 } | |
41 pos += cint(1, 1); | |
42 size -= cint(2, 2); | |
43 if (inside_rect(pos, size)) { | |
44 return 0; | |
45 } | |
46 return 1; | |
47 } | |
48 | |
49 | |
50 cint ulci(cint a, cint b) { | |
51 cint c; | |
52 c.x = min(a.x, b.x); | |
53 c.y = min(a.y, b.y); | |
54 return c; | |
55 } | |
56 | |
57 cint lrci(cint a, cint b) { | |
58 cint c; | |
59 c.x = max(a.x, b.x); | |
60 c.y = max(a.y, b.y); | |
61 return c; | |
62 } | |
63 | |
64 cint measure_string(const char *s) { | |
65 int w=0, d=0, k=0; | |
66 cint m; | |
67 | |
68 while (*s) { | |
69 for (k=0; *s && *s!='\n'; s++, k++); | |
70 w = max(w, k); | |
71 d++; | |
72 if (*s =='\n') { | |
73 s++; | |
74 } | |
75 } | |
76 m.x = w; | |
77 m.y = d; | |
78 return m; | |
79 } | |
80 | |
81 int measure_line(const char *s) { | |
82 int m; | |
83 | |
84 m = 0; | |
85 while (*s && *s !='\n') { | |
86 m++; | |
87 s++; | |
88 } | |
89 return m; | |
90 } | |
91 | |
92 | |
93 cint place(cint measure, cint size, int jm) { | |
94 int hm, vm; | |
95 cint p; | |
96 | |
97 hm = (jm/10)&3; | |
98 vm = jm%10; | |
99 | |
100 size = ulci(measure, size); | |
101 p.x = (measure.x-size.x)*hm/2; | |
102 p.y = (measure.y-size.y)*vm/2; | |
103 return p; | |
104 } | |
105 | |
106 | |
107 rect place_rect(rect w, cint s, int jm) { | |
108 cint p; | |
109 | |
110 p = place(w.size, s, jm); | |
111 w.size = ulci(w.size, p+s) - p; | |
112 w.pos += p; | |
113 return w; | |
114 } |