/ *   
 
   *   P R O J E C T :   N y A R T o o l k i t C S ( E x t e n s i o n ) 
 
   *   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
   *   T h e   N y A R T o o l k i t C S   i s   C #   e d i t i o n   A R T o o l K i t   c l a s s   l i b r a r y . 
 
   *   C o p y r i g h t   ( C ) 2 0 0 8 - 2 0 0 9   R y o   I i z u k a 
 
   * 
 
   *   T h i s   p r o g r a m   i s   f r e e   s o f t w a r e :   y o u   c a n   r e d i s t r i b u t e   i t   a n d / o r   m o d i f y 
 
   *   i t   u n d e r   t h e   t e r m s   o f   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e   a s   p u b l i s h e d   b y 
 
   *   t h e   F r e e   S o f t w a r e   F o u n d a t i o n ,   e i t h e r   v e r s i o n   3   o f   t h e   L i c e n s e ,   o r 
 
   *   ( a t   y o u r   o p t i o n )   a n y   l a t e r   v e r s i o n . 
 
   *   
 
   *   T h i s   p r o g r a m   i s   d i s t r i b u t e d   i n   t h e   h o p e   t h a t   i t   w i l l   b e   u s e f u l , 
 
   *   b u t   W I T H O U T   A N Y   W A R R A N T Y ;   w i t h o u t   e v e n   t h e   i m p l i e d   w a r r a n t y   o f 
 
   *   M E R C H A N T A B I L I T Y   o r   F I T N E S S   F O R   A   P A R T I C U L A R   P U R P O S E .     S e e   t h e 
 
   *   G N U   G e n e r a l   P u b l i c   L i c e n s e   f o r   m o r e   d e t a i l s . 
 
   * 
 
   *   Y o u   s h o u l d   h a v e   r e c e i v e d   a   c o p y   o f   t h e   G N U   G e n e r a l   P u b l i c   L i c e n s e 
 
   *   a l o n g   w i t h   t h i s   p r o g r a m .     I f   n o t ,   s e e   < h t t p : / / w w w . g n u . o r g / l i c e n s e s / > . 
 
   *   
 
   *   F o r   f u r t h e r   i n f o r m a t i o n   p l e a s e   c o n t a c t . 
 
   * 	 h t t p : / / n y a t l a . j p / n y a t o o l k i t / 
 
   * 	 < a i r m a i l ( a t ) e b o n y . p l a l a . o r . j p >   o r   < n y a t l a ( a t ) n y a t l a . j p > 
 
   *   
 
   * / 
 
 u s i n g   S y s t e m ; 
 
 u s i n g   S y s t e m . D i a g n o s t i c s ; 
 
 u s i n g   j p . n y a t l a . n y a r t o o l k i t . c s . c o r e ; 
 
 
 
 n a m e s p a c e   j p . n y a t l a . n y a r t o o l k i t . c s . r p f 
 
 
 
 { 
 
         / * * 
 
           *   *gwn0wb_0XY0000000
 
           *   v}[vj0[lo0Bl000j0D0n0g00wb_n0ks0c[W0f0ԏW0~0Y00
 
           *   ewn00000XW0_0D0n0j00p00ksc[_k000000n0!jiK00]0n0v}[0000yr[Y00h0oD0K00W00~0[000
 
           * 
 
           * / 
 
         p u b l i c   c l a s s   C a r d D e t e c t 
 
         { 
 
 	         p u b l i c   c l a s s   U n k n o w n R e c t I n f o 
 
 	         { 
 
 	 	         / * *   QO(u0c[W0f0D0000000n00000I D * / 
 
 	 	         p u b l i c   l o n g   _ t a r g e t _ s e r i a l ; 
 
 	 	         / * *  0QO(u0bRVpen00000* / 
 
 	 	         p u b l i c   i n t   _ s u c c e s s _ p o i n t ; 
 
 	 	         / * *  0QO(u01YWeVpen00000* / 
 
 	 	         p u b l i c   i n t   _ f a i l e d ; 
 
 	 	         / * *   iQW0_0wb_n0&~*j^c[$P0% h0* / 
 
 	 	         p u b l i c   d o u b l e   r a t e ; 
 
 	 	         / * *   A R T o o l K i t 0000n0d i r e c t i o n $P* / 
 
 	 	         p u b l i c   i n t   a r t k _ d i r e c t i o n ; 
 
         	 	 
 
 	 	         / * * 
 
 	 	           *   s(Wn0Xrl0
 
 	 	           *   < u l > 
 
 	 	           *   < l i > { @ l i n k   # M O R E _ F R O N T _ C E N T E R } S0n0000000c[Y00k0o0000ckbK00dq_L0_g0Y00< / l i > 
 
 	 	           *   < l i > { @ l i n k   # E S T I M A T E _ N O W } 'YM0U00c[-Ng0Y00_M0}M00!kn00000n0i _ t a r g e t h0i o _ r e s u l t 000eQRW0f0O0`0U0D00< / l i > 
 
 	 	           *   < l i > { @ l i n k   # E S T I M A T E _ C O M P L E T E } c[[N0i o _ r e s u l t n0000	YpeL0)R(uSg0Y00< / l i > 
 
 	 	           *   < l i > { @ l i n k   # E S T I M A T E _ F A I L E D } c[k01YWeW0~0W0_00	Yj0b_n0R E C T `0c0_0n0K000< / l i > 
 
 	 	           *   < l i > { @ l i n k   # F A I L E D _ T A R G E T _ M I S S M A T C H } c[k01YWeW0~0W0_00i _ t a r g e t h0i o _ r e s u l t 00L0Uc0f0D000< / l i > 
 
 	 	           *   < / u l > 
 
 	 	           * / 
 
 	 	         p u b l i c   i n t   l a s t _ s t a t u s ; 
 
 	 	         p u b l i c   U n k n o w n R e c t I n f o ( ) 
 
 	 	         { 
 
 	 	 	         t h i s . _ t a r g e t _ s e r i a l = N y A R R e a l i t y T a r g e t . I N V A L I D _ R E A L I T Y _ T A R G E T _ I D ; 
 
 	 	         } 
 
 	         } 
 
 	         p u b l i c   c o n s t   i n t   M O R E _ F R O N T _ C E N T E R = 0 ; 
 
 	         p u b l i c   c o n s t   i n t   E S T I M A T E _ N O W = 1 ; 
 
 	         p u b l i c   c o n s t   i n t   E S T I M A T E _ C O M P L E T E = 2 ; 
 
 	         p u b l i c   c o n s t   i n t   F A I L E D _ E S T I M A T E = 3 ; 
 
 	         p u b l i c   c o n s t   i n t   F A I L E D _ T A R G E T _ M I S S M A T C H = 4 ; 
 
 	         / * * 
 
 	           *   i _ t a r g e t n0'YM0U00c[W0f00{ @ l i n k   U n k n o w n R e c t I n f o } k0P}g0OX[W0~0Y00S0n0peo0{ @ l i n k   U n k n o w n R e c t I n f o } n0rKa0	YSU0[00`0Q0g0Y00
 
 	           *   @ p a r a m   i _ t a r g e t 
 
 	           *   'YM0U00c[Y00000000
 
 	           *   @ p a r a m   i o _ r e s u l t 
 
 	           *   eQQR000000MRk~0g0n0c[P}gh0s(Wn0c[$P0000W0f0ԏW0~0Y00
 
 	           *   o0X00f000000n0c[0Y00h0M0o000000W0_0{ @ l i n k   U n k n o w n R e c t I n f o } 0eQRW0f0O0`0U0D00
 
 	           *   @ r e t u r n 
 
 	           *   Xrl0ԏW0~0Y00
 
 	           *   @ t h r o w s   N y A R E x c e p t i o n 
 
 	           * / 
 
 	         p u b l i c   v o i d   d e t e c t C a r d D i r e c t i o n ( N y A R R e a l i t y T a r g e t   i _ t a r g e t , U n k n o w n R e c t I n f o   i o _ r e s u l t ) 
 
 	         { 
 
 	 	         / / bRppeL02 0 p0H0_00c[[N0
 
 	 	         i f ( i o _ r e s u l t . _ s u c c e s s _ p o i n t > 2 0 ) { 
 
 	 	 	         i o _ r e s u l t . l a s t _ s t a t u s = E S T I M A T E _ C O M P L E T E ; 
 
 	 	 	         r e t u r n ; 
 
 	 	         } 
 
 	 	         / / 1 0 V1YWeW0_00c[1YWe
 
 	 	         i f ( i o _ r e s u l t . _ f a i l e d > 1 0 ) { 
 
 	 	 	         i o _ r e s u l t . l a s t _ s t a t u s = F A I L E D _ E S T I M A T E ; 
 
 	 	 	         r e t u r n ; 
 
 	 	         } 
 
 	 	         N y A R D o u b l e P o i n t 2 d [ ]   p o s = i _ t a r g e t . r e f T a r g e t V e r t e x ( ) ; 
 
 	 	         / / ckbK00 NVXU0[0f0{0W0D00
 
 	 	         f o r ( i n t   i = 0 ; i < 4 ; i + + ) { 
 
 	 	 	         / / ckb$R[0n0j0Y0҉L09 0 0~0_0o0- 9 0 ^n01 0 ^NQg0B00S0h00
 
 	 	 	         i f ( g e t A b s S i n ( p o s [ 0 + i ] , p o s [ ( 1 + i ) % 4 ] , p o s [ ( 2 + i ) % 4 ] ) < 0 . 9 8 4 ) { 
 
 	 	 	 	         i o _ r e s u l t . l a s t _ s t a t u s = M O R E _ F R O N T _ C E N T E R ; 
 
 	 	 	 	         r e t u r n ; 
 
 	 	 	         } 
 
 	 	         } 
 
 	 	         / / }n0wU004 ,g{
 
 	 	         d o u b l e   d 1 = M a t h . S q r t ( p o s [ 0 ] . s q D i s t ( p o s [ 1 ] ) ) ; 
 
 	 	         d o u b l e   d 2 = M a t h . S q r t ( p o s [ 1 ] . s q D i s t ( p o s [ 2 ] ) ) ; 
 
 	 	         d o u b l e   d 3 = M a t h . S q r t ( p o s [ 2 ] . s q D i s t ( p o s [ 3 ] ) ) ; 
 
 	 	         d o u b l e   d 4 = M a t h . S q r t ( p o s [ 3 ] . s q D i s t ( p o s [ 0 ] ) ) ; 
 
 	 	         / / s(Wn0ks0{
 
 	 	         d o u b l e   t , t 2 , t 3 ; 
 
 	 	         t = d 1 + d 3 * 0 . 5 ; 
 
 	 	         t 2 = d 2 + d 4 * 0 . 5 ; 
 
 	 	         t 3 = t / t 2 ; 
 
 	 	         t 3 = t 3 < 1 ? 1 / t 3 : t 3 ; 
 
 	 	         i f ( i o _ r e s u l t . _ t a r g e t _ s e r i a l = = N y A R R e a l i t y T a r g e t . I N V A L I D _ R E A L I T Y _ T A R G E T _ I D ) { 
 
 	 	 	         / / 000000000
 
 	 	 	         i o _ r e s u l t . _ t a r g e t _ s e r i a l = i _ t a r g e t . g e t S e r i a l I d ( ) ; 
 
 	 	 	         i o _ r e s u l t . r a t e = t 3 ; 
 
 	 	 	         i o _ r e s u l t . _ s u c c e s s _ p o i n t = 0 ; 
 
 	 	 	         i o _ r e s u l t . _ f a i l e d = 0 ; 
 
 	 	 	         i o _ r e s u l t . a r t k _ d i r e c t i o n = t < t 2 ? 1 : 0 ; 
 
 	 	         } e l s e { 
 
 	 	 	         i f ( i o _ r e s u l t . _ t a r g e t _ s e r i a l ! = i _ t a r g e t . g e t S e r i a l I d ( ) ) { 
 
 	 	 	 	         / / 00000L0 NW0j0D00
 
 	 	 	 	         i o _ r e s u l t . l a s t _ s t a t u s = F A I L E D _ T A R G E T _ M I S S M A T C H ; 
 
 	 	 	 	         r e t u r n ; 
 
 	 	 	         } 
 
 	 	 	         i f ( t 3 / i o _ r e s u l t . r a t e > 0 . 9 8   & &   t 3 / i o _ r e s u l t . r a t e < 1 . 0 2 ) 
 
 	 	 	         { 
 
 	 	 	 	         i o _ r e s u l t . r a t e = ( i o _ r e s u l t . r a t e + t 3 ) * 0 . 5 ; 
 
 	 	 	 	         i o _ r e s u l t . _ s u c c e s s _ p o i n t + + ; 
 
 	 	 	         } e l s e { 
 
 	 	 	 	         i o _ r e s u l t . _ f a i l e d + + ; 
 
 	 	 	         } 
 
 	 	         } 
 
 	 	         / / c[-N
 
 	 	         i o _ r e s u l t . l a s t _ s t a t u s = E S T I M A T E _ N O W ; 
 
 	 	         r e t u r n ; 
 
 	         } 
 
 	         / * * 
 
 	           *   p 1 - > p 2 h0p 2 - > p 3 n0\O0҉n0s i n $Pn0v}[$P0_~0Y00
 
 	           *   @ p a r a m   p 1 
 
 	           *   @ p a r a m   p 2 
 
 	           *   @ p a r a m   p 3 
 
 	           *   @ r e t u r n 
 
 	           * / 
 
 	         p u b l i c   s t a t i c   d o u b l e   g e t A b s S i n ( N y A R D o u b l e P o i n t 2 d   p 1 , N y A R D o u b l e P o i n t 2 d   p 2 , N y A R D o u b l e P o i n t 2 d   p 3 ) 
 
 	         { 
 
 	 	         d o u b l e   c p = N y A R D o u b l e P o i n t 2 d . c r o s s P r o d u c t 3 P o i n t ( p 1 , p 2 , p 3 ) ; 
 
 	 	         c p / = ( M a t h . S q r t ( p 1 . s q D i s t ( p 2 ) ) * M a t h . S q r t ( p 2 . s q D i s t ( p 3 ) ) ) ; 
 
 	 	         r e t u r n   c p > 0 ? c p : - c p ; 
 
 	         } 	 
 
         } 
 
 } 