Revision: 1.1 - (view) (download) (as text)
1 : | ktanaka | 1.1 | #include "PatMatch.h" |
2 : | |||
3 : | PatMatch::PatMatch(int w,int h,std::string s,const Assumption &as) | ||
4 : | :width(w), height(h), pat(s), assumption(as){ | ||
5 : | assert(pat.length() == (unsigned int)width*height); | ||
6 : | } | ||
7 : | PatMatch::PatMatch(int w,int h,std::string s, const SimpleAssumption &sa) | ||
8 : | :width(w), height(h), pat(s), assumption(){ | ||
9 : | assumption.add(sa); | ||
10 : | assert(pat.length() == (unsigned int)width*height); | ||
11 : | } | ||
12 : | int PatMatch::get(int x,int y) const{ | ||
13 : | return pat[y*width+x]; | ||
14 : | } | ||
15 : | #if 0 | ||
16 : | bool PatMatch::isMatch(const BitmapFont& bf, int x, int y) const{ | ||
17 : | for(int i=0;i<width;i++) | ||
18 : | for(int j=0;j<height;j++){ | ||
19 : | if(bf.get(x+i,y+j)){ | ||
20 : | if(get(i,j)=='.') return false; | ||
21 : | } | ||
22 : | else if(get(i,j)=='@') return false; | ||
23 : | } | ||
24 : | return true; | ||
25 : | } | ||
26 : | #endif | ||
27 : | int PatMatch::matchPenalty(const BitmapFont& bf, int x, int y) const{ | ||
28 : | int penalty=0; | ||
29 : | for(int i=0;i<width;i++) | ||
30 : | for(int j=0;j<height;j++){ | ||
31 : | if(bf.get(x+i,y+j)){ | ||
32 : | if(get(i,j)=='.') return -1; | ||
33 : | else if(get(i,j)=='*') penalty++; | ||
34 : | } | ||
35 : | else if(get(i,j)=='@') return -1; | ||
36 : | } | ||
37 : | return penalty; | ||
38 : | } | ||
39 : | std::vector<pixel> PatMatch::getPixels(int x, int y) const{ | ||
40 : | std::vector<pixel> pixels; | ||
41 : | for(int i=0;i<width;i++) | ||
42 : | for(int j=0;j<height;j++){ | ||
43 : | if(get(i,j)=='@'){ | ||
44 : | pixels.push_back(pixel(x+i,y+j)); | ||
45 : | } | ||
46 : | } | ||
47 : | return pixels; | ||
48 : | } | ||
49 : | std::ostream& operator<<(std::ostream &os,const PatMatch &pm){ | ||
50 : | return os << "PatMatch(width=" << pm.width << ",height=" << pm.height << | ||
51 : | ",pat=" << pm.pat << "," << pm.assumption << ")"; | ||
52 : | } |
ktanaka Powered by ViewCVS 1.0-dev |
ViewCVS and CVS Help |