package id.ac.itb.sigit.pengenalanpola;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Sigit on 22/09/2015.
 */
public class CharDef {
    private String character;
    private String chainCode;
    private String dirChainCode;
    private String relChainCode;
    private List<String> subChainCode=new ArrayList<>();

    public String getCharacter() {
        return character;
    }

    public void setCharacter(String character) {
        this.character = character;
    }

    public String getChainCode() {
        return chainCode;
    }

    public void setChainCode(String chainCode) {
        this.chainCode = chainCode;
    }

    public List<String> getSubChainCode() {
        return subChainCode;
    }

    public String getDirChainCode() {
        return dirChainCode;
    }

    public String getRelChainCode() {
        return relChainCode;
    }

    public void calcDirChainCode(){
        dirChainCode = "";

        for(int i=1; i < chainCode.length(); i++){
            int a = Integer.parseInt(chainCode.charAt(i) + "");
            int b = Integer.parseInt(chainCode.charAt(i - 1) + "");

            if(a == b){

            }else if(a < b){
                dirChainCode = dirChainCode + "-";
            }else{
                dirChainCode = dirChainCode + "+";
            }
        }
    }

    public void calcRelChainCode(){
        relChainCode = "";

        for(int i=1; i < chainCode.length(); i++){
            int a = Integer.parseInt(chainCode.charAt(i) + "");
            int b = Integer.parseInt(chainCode.charAt(i - 1) + "");

            if(a == b){

            }else if(a < b){
                relChainCode = relChainCode + (a - b + 8);
            }else{
                relChainCode = relChainCode + (a - b);
            }
        }
    }

}

@@ -1122,32 +1122,56 @@
 At(i - 1) + %22%22);
+%0A            int y, mod;
 %0A%0A            if
@@ -1165,39 +1165,48 @@
            if(a 
-==
+%3C
  b)%7B
-%0A
+ mod = 8; %7D
 %0A            %7Del
@@ -1198,38 +1198,106 @@
             
-%7D
 else
+%7B      mod = 0; %7D%0A%0A            y = a - b + mod;%0A%0A           
  if(
-a %3C b
+0 %3C y && y %3C 4
 )%7B%0A         
@@ -1334,17 +1334,17 @@
 Code + %22
--
++
 %22;%0A     
@@ -1347,32 +1347,43 @@
            %7Delse
+ if( y %3E 4)
 %7B%0A              
@@ -1407,33 +1407,33 @@
 dirChainCode + %22
-+
+-
 %22;%0A            %7D
@@ -1434,32 +1434,79 @@
      %7D%0A        %7D
+%0A%0A        Log.v(%22chaincode_dir%22, dirChainCode);
 %0A    %7D%0A%0A    publ
@@ -1743,16 +1743,37 @@
 ) + %22%22);
+%0A            int mod;
 %0A%0A      
@@ -1808,26 +1808,16 @@
    %7Delse
- if(a %3C b)
 %7B%0A      
@@ -1830,50 +1830,29 @@
     
-relChainCode = relChainCode + (a - b + 8);
+if(a %3C b)%7B mod = 8; %7D
 %0A   
@@ -1852,38 +1852,57 @@
 ; %7D%0A            
-%7D
+    
 else%7B
+      mod = 0; %7D
 %0A               
@@ -1938,16 +1938,22 @@
 + (a - b
+ + mod
 );%0A     
@@ -1966,22 +1966,69 @@
  %7D%0A        %7D
+%0A%0A        Log.v(%22chaincode_rel%22, relChainCode);
 %0A    %7D%0A%0A%7D%0A

fix calcDirChainCode() & calcRelChainCode