[wadalabfont-kit] / jis2prim / PatMatch.h  

Annotation of /jis2prim/PatMatch.h

Parent Directory | Revision Log

Revision: 1.3 - (view) (download) (as text)

1 : ktanaka 1.2 #ifndef _PAT_MATCH_H
2 :     #define _PAT_MATCH_H
3 :    
4 : ktanaka 1.1 #include <string>
5 :     #include "BitmapFont.h"
6 :     #include "Assumption.h"
7 :    
8 :     /* @ : 黒 */
9 :     /* . : 白 */
10 :     /* else(?) : どちらでも */
11 :     class PatMatch{
12 : ktanaka 1.2 friend ostream& operator<<(ostream &os,const PatMatch &pm);
13 :     protected:
14 : ktanaka 1.1 int width, height;
15 :     string pat;
16 :     Assumption assumption;
17 :     public:
18 : ktanaka 1.2 PatMatch(int w,int h,string s,const Assumption &as)
19 : ktanaka 1.1 :width(w), height(h), pat(s), assumption(as){
20 :     assert(pat.length() == (unsigned int)width*height);
21 :     }
22 : ktanaka 1.2 PatMatch(int w,int h,string s, const SimpleAssumption &sa)
23 :     :width(w), height(h), pat(s), assumption(){
24 :     assumption.add(sa);
25 :     assert(pat.length() == (unsigned int)width*height);
26 :     }
27 :     int get(int x,int y) const{
28 :     return pat[y*width+x];
29 :     }
30 : ktanaka 1.1 bool isMatch(const BitmapFont& bf, int x, int y) const{
31 :     for(int i=0;i<width;i++)
32 :     for(int j=0;j<height;j++){
33 :     if(bf.get(x+i,y+j)){
34 : ktanaka 1.2 if(get(i,j)=='.') return false;
35 : ktanaka 1.1 }
36 : ktanaka 1.2 else if(get(i,j)=='@') return false;
37 : ktanaka 1.1 }
38 :     return true;
39 :     }
40 : ktanaka 1.2 vector<pixel> getPixels(int x, int y) const{
41 :     vector<pixel> pixels;
42 :     for(int i=0;i<width;i++)
43 :     for(int j=0;j<height;j++){
44 : ktanaka 1.3 if(get(i,j)=='@'){
45 : ktanaka 1.2 pixels.push_back(pixel(x+i,y+j));
46 :     }
47 :     }
48 :     return pixels;
49 :     }
50 : ktanaka 1.1 };
51 : ktanaka 1.2 ostream& operator<<(ostream &os,const PatMatch &pm){
52 :     return os << "PatMatch(width=" << pm.width << ",height=" << pm.height <<
53 :     ",pat=" << pm.pat << "," << pm.assumption << ")";
54 :     }
55 :     #endif /* _PAT_MATCH_H */

ktanaka

Powered by ViewCVS 1.0-dev

ViewCVS and CVS Help