| std::string pat; |
std::string pat; |
| Assumption assumption; |
Assumption assumption; |
| public: |
public: |
| PatMatch(int w,int h,std::string s,const Assumption &as) |
PatMatch(int w,int h,std::string s,const Assumption &as); |
| :width(w), height(h), pat(s), assumption(as){ |
PatMatch(int w,int h,std::string s, const SimpleAssumption &sa); |
| assert(pat.length() == (unsigned int)width*height); |
int get(int x,int y) const; |
| } |
|
| PatMatch(int w,int h,std::string s, const SimpleAssumption &sa) |
|
| :width(w), height(h), pat(s), assumption(){ |
|
| assumption.add(sa); |
|
| assert(pat.length() == (unsigned int)width*height); |
|
| } |
|
| int get(int x,int y) const{ |
|
| return pat[y*width+x]; |
|
| } |
|
| #if 0 |
#if 0 |
| bool isMatch(const BitmapFont& bf, int x, int y) const{ |
bool isMatch(const BitmapFont& bf, int x, int y) const; |
| for(int i=0;i<width;i++) |
|
| for(int j=0;j<height;j++){ |
|
| if(bf.get(x+i,y+j)){ |
|
| if(get(i,j)=='.') return false; |
|
| } |
|
| else if(get(i,j)=='@') return false; |
|
| } |
|
| return true; |
|
| } |
|
| #endif |
#endif |
| int matchPenalty(const BitmapFont& bf, int x, int y) const{ |
int matchPenalty(const BitmapFont& bf, int x, int y) const; |
| int penalty=0; |
std::vector<pixel> getPixels(int x, int y) const; |
| for(int i=0;i<width;i++) |
|
| for(int j=0;j<height;j++){ |
|
| if(bf.get(x+i,y+j)){ |
|
| if(get(i,j)=='.') return -1; |
|
| else if(get(i,j)=='*') penalty++; |
|
| } |
|
| else if(get(i,j)=='@') return -1; |
|
| } |
|
| return penalty; |
|
| } |
|
| std::vector<pixel> getPixels(int x, int y) const{ |
|
| std::vector<pixel> pixels; |
|
| for(int i=0;i<width;i++) |
|
| for(int j=0;j<height;j++){ |
|
| if(get(i,j)=='@'){ |
|
| pixels.push_back(pixel(x+i,y+j)); |
|
| } |
|
| } |
|
| return pixels; |
|
| } |
|
| }; |
}; |
| std::ostream& operator<<(std::ostream &os,const PatMatch &pm){ |
std::ostream& operator<<(std::ostream &os,const PatMatch &pm); |
| return os << "PatMatch(width=" << pm.width << ",height=" << pm.height << |
|
| ",pat=" << pm.pat << "," << pm.assumption << ")"; |
|
| } |
|
| #endif /* _PAT_MATCH_H */ |
#endif /* _PAT_MATCH_H */ |