Added a function to clear data of polygons array.
[chise/kage.git] / engine / kage.js
index 0d3f933..bc97a5a 100755 (executable)
@@ -3,7 +3,7 @@ function Kage(){
   function makeGlyph(polygons, buhin){ // void\r
     var glyphData = this.kBuhin.search(buhin);\r
     if(glyphData != ""){\r
-      this.drawStrokesArray(polygons, this.adjustUroko(this.adjustKakato(this.getEachStrokes(glyphData))));\r
+      this.drawStrokesArray(polygons, this.adjustKirikuchi(this.adjustUroko(this.adjustKakato(this.getEachStrokes(glyphData)))));\r
     }\r
   }\r
   Kage.prototype.makeGlyph = makeGlyph;\r
@@ -65,10 +65,10 @@ function Kage(){
   \r
        function adjustUroko(strokesArray){ // strokesArray\r
     for(var i = 0; i < strokesArray.length; i++){\r
-      if(strokesArray[i][0] == 1 && strokesArray[i][2] == 0){ // \8fc\82Í\83E\83\8d\83R\82È\82¢\82Ì\82Å\96³\8e\8b\81B\82Å\82à\8cv\8eZ\97Ê\82ª\96³\91Ê\r
+      if(strokesArray[i][0] == 1 && strokesArray[i][2] == 0){ // no operation for TATE\r
         for(var k = 0; k < this.kAdjustUrokoLengthStep; k++){\r
           var tx, ty, tlen;\r
-          if(strokesArray[i][4] == strokesArray[i][6]){ // \89¡\r
+          if(strokesArray[i][4] == strokesArray[i][6]){ // YOKO\r
             tx = strokesArray[i][5] - this.kAdjustUrokoLine[k];\r
             ty = strokesArray[i][6] - 0.5;\r
             tlen = strokesArray[i][5] - strokesArray[i][3];\r
@@ -92,6 +92,25 @@ function Kage(){
   }\r
   Kage.prototype.adjustUroko = adjustUroko;\r
        \r
+       function adjustKirikuchi(strokesArray){ // strokesArray\r
+    for(var i = 0; i < strokesArray.length; i++){\r
+      if(strokesArray[i][0] == 2 && strokesArray[i][1] == 32 &&\r
+         strokesArray[i][3] > strokesArray[i][5] &&\r
+         strokesArray[i][4] < strokesArray[i][6]){\r
+        for(var j = 0; j < strokesArray.length; j++){ // no need to skip when i == j\r
+          if(strokesArray[j][0] == 1 &&\r
+             strokesArray[j][3] < strokesArray[i][3] && strokesArray[j][5] > strokesArray[i][3] &&\r
+             strokesArray[j][4] == strokesArray[i][4] && strokesArray[j][4] == strokesArray[j][6]){\r
+            strokesArray[i][1] = 132;\r
+            j = strokesArray.length;\r
+          }\r
+        }\r
+      }\r
+    }\r
+    return strokesArray;\r
+  }\r
+  Kage.prototype.adjustKirikuchi = adjustKirikuchi;\r
+       \r
   function adjustKakato(strokesArray){ // strokesArray\r
     for(var i = 0; i < strokesArray.length; i++){\r
       if(strokesArray[i][0] == 1 &&\r
@@ -204,17 +223,17 @@ function Kage(){
   this.kL2RDfatten = 1.1;\r
   this.kMage = 10;\r
        \r
-  this.kAdjustKakatoL = ([14, 9, 5, 2]); // \92²\90®\8dÏ\82Ý\83J\83J\83g\97p 000,100,200,300\r
-  this.kAdjustKakatoR = ([8, 6, 4, 2]); // \92²\90®\8dÏ\82Ý\83J\83J\83g\97p 000,100,200,300\r
-  this.kAdjustKakatoRangeX = 20; // \89e\8b¿\94»\92è\8bé\8c`\82Ì\91å\82«\82³\r
-  this.kAdjustKakatoRangeY = ([1, 19, 24, 30]); // \89e\8b¿\94»\92è\8bé\8c`\82Ì\91å\82«\82³\8b«\8aE\81i3\97Ì\88æ\81j\r
-  this.kAdjustKakatoStep = 3; // \89e\8b¿\94»\92è\8bé\8c`\82Ì\92i\8aK\r
+  this.kAdjustKakatoL = ([14, 9, 5, 2]); // for KAKATO adjustment 000,100,200,300\r
+  this.kAdjustKakatoR = ([8, 6, 4, 2]); // for KAKATO adjustment 000,100,200,300\r
+  this.kAdjustKakatoRangeX = 20; // check area width\r
+  this.kAdjustKakatoRangeY = ([1, 19, 24, 30]); // 3 steps of checking\r
+  this.kAdjustKakatoStep = 3; // number of steps\r
        \r
-  this.kAdjustUrokoX = ([24, 20, 16, 12]); // \92²\90®\8dÏ\82Ý\83T\83C\83Y 000,100,200,300\r
-  this.kAdjustUrokoY = ([12, 11, 9, 8]); // \92²\90®\8dÏ\82Ý\83T\83C\83Y 000,100,200,300\r
-  this.kAdjustUrokoLength = ([22, 36, 50]); // \89e\8b¿\94»\92è\92·\82³\82Ì\92i\8aK\r
-  this.kAdjustUrokoLengthStep = 3; // \89e\8b¿\94»\92è\92·\82³\82Ì\92i\8aK\r
-  this.kAdjustUrokoLine = ([22, 26, 30]); // \8cð\8d·\82Ì\89e\8b¿\94»\92è\81BLength\82Æ\91Î\89\9e\r
+  this.kAdjustUrokoX = ([24, 20, 16, 12]); // for UROKO adjustment 000,100,200,300\r
+  this.kAdjustUrokoY = ([12, 11, 9, 8]); // for UROKO adjustment 000,100,200,300\r
+  this.kAdjustUrokoLength = ([22, 36, 50]); // length for checking\r
+  this.kAdjustUrokoLengthStep = 3; // number of steps\r
+  this.kAdjustUrokoLine = ([22, 26, 30]); // check for crossing. corresponds to length\r
        \r
   this.kBuhin = new Buhin();\r
   \r