/ *   
 
   *   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 
 
 { 
 
         / * * 
 
           *   N y A R V e c t o r R e a d e r 0000000n0F0a000000000000k0OX[W0j0D0pe0[ňY000000
 
           *   >mu000g0;u }0000pe0[ňW0f00 gB}vj0000k0N
NR0~0Y00
 
           * 
 
           * / 
 
         p u b l i c   a b s t r a c t   c l a s s   N y A R V e c t o r R e a d e r _ B a s e   :   I N y A R V e c t o r R e a d e r 
 
         { 
 
                 p r i v a t e   V e c L i n e a r C o o r d i n a t e s . V e c L i n e a r C o o r d i n a t e P o i n t [ ]   _ t m p _ c o o r d _ p o s ; 
 
 	         p r i v a t e   i n t   _ r o b _ r e s o l u t i o n ; 
 
 	         p r o t e c t e d   N y A R G r a y s c a l e R a s t e r   _ r e f _ b a s e _ r a s t e r ; 
 
 	         p r i v a t e   N y A R G r a y s c a l e R a s t e r   _ r e f _ r o b _ r a s t e r ; 
 
 	         p r o t e c t e d   I N y A R C a m e r a D i s t o r t i o n F a c t o r   _ f a c t o r ; 
 
 	         / * * 
 
 	           *   }b0_h0Y00_00000000000=0
 
 	           * / 
 
 	         p r o t e c t e d   N y A R V e c t o r R e a d e r _ B a s e ( ) 
 
 	         { 
 
         	 	 
 
 	         } 
 
         	 
 
 	         / * * 
 
 	           *   }b000n00000000K00|Ts0QY00
 
 	           *   @ p a r a m   i _ r e f _ r a s t e r 
 
 	           *   W,g;uP
 
 	           *   @ p a r a m   i _ r e f _ r a s t e r _ d i s t o r t i o n 
 
 	           *   jk0d000000( n u l l n04XTjk0d0weu) 
 
 	           *   @ p a r a m   i _ r e f _ r o b _ r a s t e r 
 
 	           *   000c"}(un0R O B ;uP
 
 	           *   @ p a r a m   i _ c o n t o u r _ p i c k u p 
 
 	           *   *}S_000
 
 	           *   @ p a r a m   
 
 	           * / 
 
 	         p u b l i c   v o i d   i n i t I n s t a n c e ( N y A R G r a y s c a l e R a s t e r   i _ r e f _ r a s t e r , I N y A R C a m e r a D i s t o r t i o n F a c t o r   i _ r e f _ r a s t e r _ d i s t o r t i o n , N y A R G r a y s c a l e R a s t e r   i _ r e f _ r o b _ r a s t e r , N y A R C o n t o u r P i c k u p   i _ c o n t o u r _ p i c k u p ) 
 
 	         { 
 
 	 	         t h i s . _ r o b _ r e s o l u t i o n = i _ r e f _ r a s t e r . g e t W i d t h ( ) / i _ r e f _ r o b _ r a s t e r . g e t W i d t h ( ) ; 
 
 	 	         t h i s . _ r e f _ r o b _ r a s t e r = i _ r e f _ r o b _ r a s t e r ; 
 
 	 	         t h i s . _ r e f _ b a s e _ r a s t e r = i _ r e f _ r a s t e r ; 
 
 	 	         t h i s . _ c o o r d _ b u f   =   n e w   N y A R I n t C o o r d i n a t e s ( ( i _ r e f _ r a s t e r . g e t W i d t h ( )   +   i _ r e f _ r a s t e r . g e t H e i g h t ( ) )   *   4 ) ; 
 
 	 	         t h i s . _ f a c t o r = i _ r e f _ r a s t e r _ d i s t o r t i o n ; 
 
                         t h i s . _ t m p _ c o o r d _ p o s   =   V e c L i n e a r C o o r d i n a t e s . V e c L i n e a r C o o r d i n a t e P o i n t . c r e a t e A r r a y ( t h i s . _ c o o r d _ b u f . i t e m s . L e n g t h ) ; 
 
 	 	         t h i s . _ c p i c k u p   =   i _ c o n t o u r _ p i c k u p ; 
 
 	 	         r e t u r n ; 
 
 	         } 
 
 	         / * * 
 
 	           *   000	Ype
 
 	           * / 
 
 	         p r o t e c t e d   N y A R I n t C o o r d i n a t e s   _ c o o r d _ b u f ; 
 
 	         p r i v a t e   N y A R C o n t o u r P i c k u p   _ c p i c k u p ; 
 
 	         p r o t e c t e d   c o n s t   d o u b l e   _ M A R G E _ A N G _ T H   =   N y A R M a t h . C O S _ D E G _ 1 0 ; 
 
 
 
                 p u b l i c   b o o l   t r a c e C o n t u r e ( i n t   i _ t h , 
 
 	 	 	         N y A R I n t P o i n t 2 d   i _ e n t r y ,   V e c L i n e a r C o o r d i n a t e s   o _ c o o r d ) 
 
 	         { 
 
 	 	         N y A R I n t C o o r d i n a t e s   c o o r d   =   t h i s . _ c o o r d _ b u f ; 
 
 	 	         / /   R o b e r t s 000K00*퐽bQ
 
 	 	         i f   ( ! t h i s . _ c p i c k u p . g e t C o n t o u r ( t h i s . _ r e f _ r o b _ r a s t e r ,   i _ t h ,   i _ e n t r y . x ,   i _ e n t r y . y , 
 
 	 	 	 	         c o o r d ) )   { 
 
 	 	 	         / /   *}M A X j00j0k00g0M0j0D0m00
 
 	 	 	         r e t u r n   f a l s e ; 
 
 
 
 	 	         } 
 
 	 	         / /   *}n00000S
 
 	 	         r e t u r n   t r a c e C o n t u r e ( c o o r d ,   t h i s . _ r o b _ r e s o l u t i o n , 
 
 	 	 	 	         t h i s . _ r o b _ r e s o l u t i o n   *   2 ,   o _ c o o r d ) ; 
 
 	         } 
 
 
 
 
 
 
 
 	         / * * 
 
 	           *   p1 h0p2 n0k0}R0[W0f00]0n0}R
Nn000000_~0Y00po00;uPn0QtPg0j0Q00p0j00~0[000  3 2 0 * 2 4 0 n04XT0( x > = 0   & & 
 
 	           *   x < 3 2 0   x + w > 0   & &   x + w < 3 2 0 ) , ( y > 0   & &   y < 2 4 0   y + h > = 0   & &   y + h < = 3 1 9 ) h0j00~0Y00
 
 	           *   
 
 	           *   @ p a r a m   i _ p o s 1 
 
 	           *                         p1 n0^jg0Y00
 
 	           *   @ p a r a m   i _ p o s 2 
 
 	           *                         p2 n0^jg0Y00
 
 	           *   @ p a r a m   i _ a r e a 
 
 	           *                         00000iQY000000000g0Y001 n04XT( n * 2 - 1 ) ^ 2 n00000k0j00~0Y00  p2 n0^jg0Y00
 
 	           *   @ p a r a m   o _ c o o r d 
 
 	           *                         P}g0SQ0S0000000g0Y00
 
 	           *   @ r e t u r n 
 
 	           *   @ 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   b o o l   t r a c e L i n e ( N y A R I n t P o i n t 2 d   i _ p o s 1 ,   N y A R I n t P o i n t 2 d   i _ p o s 2 ,   i n t   i _ e d g e ,   V e c L i n e a r C o o r d i n a t e s   o _ c o o r d ) 
 
 	         { 
 
 	 	         N y A R I n t C o o r d i n a t e s   c o o r d   =   t h i s . _ c o o r d _ b u f ; 
 
 	 	         N y A R I n t S i z e   b a s e _ s = t h i s . _ r e f _ b a s e _ r a s t e r . g e t S i z e ( ) ; 
 
 	 	         / /   ( i _ a r e a * 2 ) n0wb_L0{VQk0S~000F0k0}0_O0
 
 	 	         / /   yRϑ
 
 
 
 	 	         / /   pݍ▒0{
 
 	 	         i n t   d i s t   =   ( i n t )   M a t h . S q r t ( i _ p o s 1 . s q D i s t ( i _ p o s 2 ) ) ; 
 
 	 	         / /    gNOA R E A * 2 N
Nn0'YM0U0L0!qD0j000000n00000o0
NS0
 
 	 	         i f   ( d i s t   <   4 )   { 
 
 	 	 	         r e t u r n   f a l s e ; 
 
 	 	         } 
 
 	 	         / /   d i s t  g'Ypen0zl[
 
 	 	         i f   ( d i s t   >   1 2 )   { 
 
 	 	 	         d i s t   =   1 2 ; 
 
 	 	         } 
 
 	 	         / /   0000000000zl[( yR^h0000K00) 
 
 	 	         i n t   s   =   i _ e d g e   *   2   +   1 ; 
 
 	 	         i n t   d x   =   ( i _ p o s 2 . x   -   i _ p o s 1 . x ) ; 
 
 	 	         i n t   d y   =   ( i _ p o s 2 . y   -   i _ p o s 1 . y ) ; 
 
 	 	         i n t   r   =   b a s e _ s . w   -   s ; 
 
 	 	         i n t   b   =   b a s e _ s . h   -   s ; 
 
 
 
 	 	         / /    g'Y1 4 p0[W0f00]0n0F0a0!Nz0dD0_0p0O(uY000
 
 	 	         f o r   ( i n t   i   =   1 ;   i   <   d i s t   -   1 ;   i + + )   { 
 
 	 	 	         i n t   x   =   i   *   d x   /   d i s t   +   i _ p o s 1 . x   -   i _ e d g e ; 
 
 	 	 	         i n t   y   =   i   *   d y   /   d i s t   +   i _ p o s 1 . y   -   i _ e d g e ; 
 
 	 	 	         / /   l i m i t 
 
 	 	 	         c o o r d . i t e m s [ i   -   1 ] . x   =   x   <   0   ?   0   :   ( x   > =   r   ?   r   :   x ) ; 
 
 	 	 	         c o o r d . i t e m s [ i   -   1 ] . y   =   y   <   0   ?   0   :   ( y   > =   b   ?   b   :   y ) ; 
 
 	 	         } 
 
 
 
 	 	         c o o r d . l e n g t h   =   d i s t   -   2 ; 
 
 	 	         / /   ppeo02 0 pz^0_00
 
 	 	         r e t u r n   t r a c e C o n t u r e ( c o o r d ,   1 ,   s ,   o _ c o o r d ) ; 
 
 	         } 
 
 
 
                 p u b l i c   b o o l   t r a c e L i n e ( N y A R D o u b l e P o i n t 2 d   i _ p o s 1 ,   N y A R D o u b l e P o i n t 2 d   i _ p o s 2 ,   i n t   i _ e d g e ,   V e c L i n e a r C o o r d i n a t e s   o _ c o o r d ) 
 
 	         { 
 
 	 	         N y A R I n t C o o r d i n a t e s   c o o r d   =   t h i s . _ c o o r d _ b u f ; 
 
 	 	         N y A R I n t S i z e   b a s e _ s = t h i s . _ r e f _ b a s e _ r a s t e r . g e t S i z e ( ) ; 
 
 	 	         / /   ( i _ a r e a * 2 ) n0wb_L0{VQk0S~000F0k0}0_O0
 
 	 	         / /   yRϑ
 
 
 
 	 	         / /   pݍ▒0{
 
 	 	         i n t   d i s t   =   ( i n t )   M a t h . S q r t ( i _ p o s 1 . s q D i s t ( i _ p o s 2 ) ) ; 
 
 	 	         / /    gNOA R E A * 2 N
Nn0'YM0U0L0!qD0j000000n00000o0
NS0
 
 	 	         i f   ( d i s t   <   4 )   { 
 
 	 	 	         r e t u r n   f a l s e ; 
 
 	 	         } 
 
 	 	         / /   d i s t  g'Ypen0zl[
 
 	 	         i f   ( d i s t   >   1 2 )   { 
 
 	 	 	         d i s t   =   1 2 ; 
 
 	 	         } 
 
 	 	         / /   0000000000zl[( yR^h0000K00) 
 
 	 	         i n t   s   =   i _ e d g e   *   2   +   1 ; 
 
 	 	         i n t   d x   =   ( i n t )   ( i _ p o s 2 . x   -   i _ p o s 1 . x ) ; 
 
 	 	         i n t   d y   =   ( i n t )   ( i _ p o s 2 . y   -   i _ p o s 1 . y ) ; 
 
 	 	         i n t   r   =   b a s e _ s . w   -   s ; 
 
 	 	         i n t   b   =   b a s e _ s . h   -   s ; 
 
 
 
 	 	         / /    g'Y2 4 p0[W0f00]0n0F0a0!Nzn02 P0dD0_0p0O(uY000
 
 	 	         f o r   ( i n t   i   =   1 ;   i   <   d i s t   -   1 ;   i + + )   { 
 
 	 	 	         i n t   x   =   ( i n t )   ( i   *   d x   /   d i s t   +   i _ p o s 1 . x   -   i _ e d g e ) ; 
 
 	 	 	         i n t   y   =   ( i n t )   ( i   *   d y   /   d i s t   +   i _ p o s 1 . y   -   i _ e d g e ) ; 
 
 	 	 	         / /   l i m i t 
 
 	 	 	         c o o r d . i t e m s [ i   -   1 ] . x   =   x   <   0   ?   0   :   ( x   > =   r   ?   r   :   x ) ; 
 
 	 	 	         c o o r d . i t e m s [ i   -   1 ] . y   =   y   <   0   ?   0   :   ( y   > =   b   ?   b   :   y ) ; 
 
 	 	         } 
 
 
 
 	 	         c o o r d . l e n g t h   =   d i s t   -   2 ; 
 
 	 	         / /   ppeo01 0 pz^0_00
 
 	 	         r e t u r n   t r a c e C o n t u r e ( c o o r d ,   1 ,   s ,   o _ c o o r d ) ; 
 
 	         } 
 
 	         / / 0000n0^<O^$R[_
 
                 p r i v a t e   s t a t i c   b o o l   c h e c k V e c C o s ( V e c L i n e a r C o o r d i n a t e s . V e c L i n e a r C o o r d i n a t e P o i n t   i _ c u r r e n t _ v e c ,   V e c L i n e a r C o o r d i n a t e s . V e c L i n e a r C o o r d i n a t e P o i n t   i _ p r e v _ v e c ,   d o u b l e   i _ a v e _ d x ,   d o u b l e   i _ a v e _ d y ) 
 
 	         { 
 
 	 	         d o u b l e   x 1 = i _ c u r r e n t _ v e c . d x ; 
 
 	 	         d o u b l e   y 1 = i _ c u r r e n t _ v e c . d y ; 
 
 	 	         d o u b l e   n = ( x 1 * x 1 + y 1 * y 1 ) ; 
 
 	 	         / / s^GW0000h0S0n00000L0C O S _ D E G _ 2 0 *gng0B00S0h00x( p o s _ p t r . g e t A b s V e c C o s ( i _ a v e _ d x , i _ a v e _ d y ) < N y A R M a t h . C O S _ D E G _ 2 0   h0TX0) 
 
 	 	         d o u b l e   d ; 
 
 	 	         d = ( x 1 * i _ a v e _ d x + y 1 * i _ a v e _ d y ) / N y A R M a t h . C O S _ D E G _ 2 0 ; 
 
 	 	         i f ( d * d < ( n * ( i _ a v e _ d x * i _ a v e _ d x + i _ a v e _ d y * i _ a v e _ d y ) ) ) { 
 
 	 	 	         / / c0000h0S0n00000L05 ^*gng0B00S0h00x( p o s _ p t r . g e t A b s V e c C o s ( i _ p r e v _ v e c ) < N y A R M a t h . C O S _ D E G _ 5 h0TX0) 
 
 	 	 	         d = ( x 1 * i _ p r e v _ v e c . d x + y 1 * i _ p r e v _ v e c . d y ) / N y A R M a t h . C O S _ D E G _ 5 ; 
 
 	 	 	         i f ( d * d < n * ( i _ p r e v _ v e c . d x * i _ p r e v _ v e c . d x + i _ p r e v _ v e c . d y * i _ p r e v _ v e c . d y ) ) { 
 
 	 	 	 	         r e t u r n   t r u e ; 
 
 	 	 	         } 
 
 	 	         } 
 
 	 	         r e t u r n   f a l s e ; 
 
 	         } 
 
 	         / * * 
 
 	           *   *}0S_W0~0Y00
 
 	           *   S_000000o00NNn00g0Y00
 
 	           *   1 . *퐧^j( n ) n0;u }hTn0;u }00000S_0
 
 	           *   2 . *퐧^j( n + 1 ) hTn0;u }0000h0k0
 
 	           *   3 . ]RL0 N[NNj000^jh07_^0OX[
 
 	           *   4 . 3 pN
Nn0ƖTk0j0c0_000 g\NWNlg0v}0{0
 
 	           *   5 . v}n0R͑$P0P0n0;u }0000n0Th0W0f0ԏtS0
 
 	           * / 
 
                 p u b l i c   b o o l   t r a c e C o n t u r e ( N y A R I n t C o o r d i n a t e s   i _ c o o r d ,   i n t   i _ p o s _ m a g ,   i n t   i _ c e l l _ s i z e ,   V e c L i n e a r C o o r d i n a t e s   o _ c o o r d ) 
 
 	         { 
 
                         V e c L i n e a r C o o r d i n a t e s . V e c L i n e a r C o o r d i n a t e P o i n t [ ]   p o s   =   t h i s . _ t m p _ c o o r d _ p o s ; 
 
 	 	         / /   0000S
 
                         i n t   M A X _ C O O R D   =   o _ c o o r d . i t e m s . L e n g t h ; 
 
 	 	         i n t   i _ c o o r d l e n   =   i _ c o o r d . l e n g t h ; 
 
 	 	         N y A R I n t P o i n t 2 d [ ]   c o o r d   =   i _ c o o r d . i t e m s ; 
 
                         V e c L i n e a r C o o r d i n a t e s . V e c L i n e a r C o o r d i n a t e P o i n t   p o s _ p t r ; 
 
 
 
 	 	         / / 0 Pvn0000c"}
 
 	 	         i n t   n u m b e r _ o f _ d a t a   =   0 ; 
 
 	 	         i n t   s q ; 
 
 	 	         l o n g   s q _ s u m = 0 ; 
 
 	 	         / / 0 juvn00000
 
 	 	         p o s [ 0 ] . s c a l a r = s q = t h i s . g e t A r e a V e c t o r 3 3 ( c o o r d [ 0 ] . x   *   i _ p o s _ m a g ,   c o o r d [ 0 ] . y   *   i _ p o s _ m a g , i _ c e l l _ s i z e ,   i _ c e l l _ s i z e , p o s [ 0 ] ) ; 
 
 	 	         s q _ s u m + = ( i n t ) s q ; 
 
 	 	         / / [ 2 ] k00 0O{
 
 
 
 	 	         / / 1 pv`0Q0o0MReh0_e0!Nek0c"}0K0Q000
 
 	 	         / / MRec"}n0B}p
 
 	 	         i n t   c o o r d _ l a s t _ e d g e = i _ c o o r d l e n ; 
 
 	 	         / / _ec"}
 
 	 	         i n t   s u m = 1 ; 
 
 	 	         d o u b l e   a v e _ d x = p o s [ 0 ] . d x ; 
 
 	 	         d o u b l e   a v e _ d y = p o s [ 0 ] . d y ; 
 
 	 	         f o r   ( i n t   i   =   i _ c o o r d l e n - 1 ;   i   > 0 ;   i - - ) 
 
 	 	         { 
 
 	 	 	         / /   0000S_
 
 	 	 	         p o s _ p t r = p o s [ s u m ] ; 
 
 	 	 	         p o s _ p t r . s c a l a r = s q = t h i s . g e t A r e a V e c t o r 3 3 ( c o o r d [ i ] . x   *   i _ p o s _ m a g , c o o r d [ i ] . y   *   i _ p o s _ m a g ,   i _ c e l l _ s i z e ,   i _ c e l l _ s i z e , p o s _ p t r ) ; 
 
                                 s q _ s u m   + =   ( i n t ) s q ; 
 
 	 	 	         / /   ^<O^$R[
 
 	 	 	         i f ( c h e c k V e c C o s ( p o s [ s u m ] , p o s [ s u m - 1 ] , a v e _ d x , a v e _ d y ) ) 
 
 	 	 	         { 
 
 	 	 	 	         / / vj0W0- > MRec"}x00
 
 	 	 	 	         a v e _ d x = p o s _ p t r . d x ; 
 
 	 	 	 	         a v e _ d y = p o s _ p t r . d y ; 
 
 	 	 	 	         c o o r d _ l a s t _ e d g e = i ; 
 
 	 	 	 	         b r e a k ; 
 
 	 	 	         }   e l s e   { 
 
 	 	 	 	         / / vB00-   pn0ĄMz
 
 	 	 	 	         a v e _ d x + = p o s _ p t r . d x ; 
 
 	 	 	 	         a v e _ d y + = p o s _ p t r . d y ; 
 
 	 	 	 	         s u m + + ; 
 
 	 	 	         } 
 
 	 	         } 
 
 	 	         / / MRec"}
 
 	 	         f o r   ( i n t   i   =   1 ;   i < c o o r d _ l a s t _ e d g e ;   i + + ) 
 
 	 	         { 
 
 	 	 	         / /   0000S_
 
 	 	 	         p o s _ p t r = p o s [ s u m ] ; 
 
 	 	 	         p o s _ p t r . s c a l a r = s q = t h i s . g e t A r e a V e c t o r 3 3 ( c o o r d [ i ] . x   *   i _ p o s _ m a g , c o o r d [ i ] . y   *   i _ p o s _ m a g ,   i _ c e l l _ s i z e ,   i _ c e l l _ s i z e , p o s _ p t r ) ; 
 
                                 s q _ s u m   + =   ( i n t ) s q ; 	 	 	 
 
 	 	 	         i f ( s q = = 0 ) { 
 
 	 	 	 	         c o n t i n u e ; 
 
 	 	 	         } 
 
 	 	 	         / / i f   ( p o s _ p t r . g e t A b s V e c C o s ( p o s [ s u m - 1 ] )   <   N y A R M a t h . C O S _ D E G _ 5   & &   p o s _ p t r . g e t A b s V e c C o s ( a v e _ d x , a v e _ d y ) < N y A R M a t h . C O S _ D E G _ 2 0 )   { 
 
 	 	 	         i f   ( c h e c k V e c C o s ( p o s [ s u m ] , p o s [ s u m - 1 ] , a v e _ d x , a v e _ d y ) )   { 
 
 	 	 	 	         / / vj0W0- > eW0D0 }0\O00
 
 	 	 	 	         i f ( t h i s . l e a s t S q u a r e s W i t h N o r m a l i z e ( p o s , s u m , o _ c o o r d . i t e m s [ n u m b e r _ o f _ d a t a ] , s q _ s u m / ( s u m * 5 ) ) ) { 
 
 	 	 	 	 	         n u m b e r _ o f _ d a t a + + ; 
 
 	 	 	 	         } 
 
 	 	 	 	         a v e _ d x = p o s _ p t r . d x ; 
 
 	 	 	 	         a v e _ d y = p o s _ p t r . d y ; 
 
 	 	 	 	         / / rs_W0_0$P00 x0yR
 
 	 	 	 	         p o s [ 0 ] . s e t V a l u e ( p o s [ s u m ] ) ; 
 
 	 	 	 	         s q _ s u m = 0 ; 
 
 	 	 	 	         s u m = 1 ; 
 
 	 	 	         }   e l s e   { 
 
 	 	 	 	         / / vB00-   pn0ĄMz
 
 	 	 	 	         a v e _ d x + = p o s _ p t r . d x ; 
 
 	 	 	 	         a v e _ d y + = p o s _ p t r . d y ; 	 	 	 	 
 
 	 	 	 	         s u m + + ; 
 
 	 	 	         } 
 
 	 	 	         / /   *-N_0QY0_00n0{
 
 	 	 	         i f   ( n u m b e r _ o f _ d a t a   = =   M A X _ C O O R D )   { 
 
 	 	 	 	         / /   *00000000n0 g'Y0H0_001YWe
 
 	 	 	 	         r e t u r n   f a l s e ; 
 
 	 	 	         } 
 
 	 	         } 
 
 	 	         i f ( t h i s . l e a s t S q u a r e s W i t h N o r m a l i z e ( p o s , s u m , o _ c o o r d . i t e m s [ n u m b e r _ o f _ d a t a ] , s q _ s u m / ( s u m * 5 ) ) ) { 
 
 	 	 	         n u m b e r _ o f _ d a t a + + ; 
 
 	 	         } 
 
 	 	         / /   0000S2 :  g_>\h0HQ-n0 }L0<Of0D00p0#P}Y000
 
 	 	         / /   s q _ d i s t n0T0{
 
 	 	         o _ c o o r d . l e n g t h   =   n u m b e r _ o f _ d a t a ; 
 
 
 
 	 	         r e t u r n   t r u e ; 
 
 	         } 
 
 	         / * * 
 
 	           *   0000W0D000000!qW0j0L00 g\NWNlg000000q}TY00pe
 
 	           *   @ p a r a m   i _ p o i n t s 
 
 	           *   @ p a r a m   i _ n u m b e r _ o f _ d a t a 
 
 	           *   @ p a r a m   o _ d e s t 
 
 	           *   @ p a r a m   i _ s c a l e _ t h 
 
 	           *   @ r e t u r n 
 
 	           * / 
 
                 p r i v a t e   b o o l   l e a s t S q u a r e s W i t h N o r m a l i z e ( V e c L i n e a r C o o r d i n a t e s . V e c L i n e a r C o o r d i n a t e P o i n t [ ]   i _ p o i n t s ,   i n t   i _ n u m b e r _ o f _ d a t a ,   V e c L i n e a r C o o r d i n a t e s . V e c L i n e a r C o o r d i n a t e P o i n t   o _ d e s t ,   d o u b l e   i _ s c a l e _ t h ) 
 
 	         { 
 
 	 	         i n t   i ; 
 
 	 	         i n t   n u m = 0 ; 
 
 	 	         d o u b l e   s u m _ x y   =   0 ,   s u m _ x   =   0 ,   s u m _ y   =   0 ,   s u m _ x 2   =   0 ; 
 
 	 	         f o r   ( i = i _ n u m b e r _ o f _ d a t a - 1 ;   i > = 0 ;   i - - ) { 
 
                                 V e c L i n e a r C o o r d i n a t e s . V e c L i n e a r C o o r d i n a t e P o i n t   p t r   =   i _ p o i n t s [ i ] ; 
 
 	 	 	         / / [00\U0D00000o0dYj0F0
 
 	 	 	         i f ( p t r . s c a l a r < i _ s c a l e _ t h ) 
 
 	 	 	         { 
 
 	 	 	 	         c o n t i n u e ; 
 
 	 	 	         } 
 
 	 	 	         d o u b l e   x w = p t r . x ; 
 
 	 	 	         s u m _ x y   + =   x w   *   p t r . y ; 
 
 	 	 	         s u m _ x   + =   x w ; 
 
 	 	 	         s u m _ y   + =   p t r . y ; 
 
 	 	 	         s u m _ x 2   + =   x w * x w ; 
 
 	 	 	         n u m + + ; 
 
 	 	         } 
 
 	 	         i f ( n u m < 3 ) { 
 
 	 	 	         r e t u r n   f a l s e ; 
 
 	 	         } 
 
 	 	         d o u b l e   l a = - ( n u m   *   s u m _ x 2   -   s u m _ x * s u m _ x ) ; 
 
 	 	         d o u b l e   l b = - ( n u m   *   s u m _ x y   -   s u m _ x   *   s u m _ y ) ; 
 
 	 	         d o u b l e   c c = ( s u m _ x 2   *   s u m _ y   -   s u m _ x y   *   s u m _ x ) ; 
 
 	 	         d o u b l e   l c = - ( l a * s u m _ x + l b * s u m _ y ) / n u m ; 
 
 	 	         / / Np0{
 
 	 	         d o u b l e   w 1   =   - l b   *   l b   -   l a   *   l a ; 
 
 	 	         i f   ( w 1   = =   0 . 0 )   { 
 
 	 	 	         r e t u r n   f a l s e ; 
 
 	 	         } 	 	 
 
 	 	         o _ d e s t . x = ( ( l a   *   l c   -   l b   *   c c )   /   w 1 ) ; 
 
 	 	         o _ d e s t . y =   ( ( l a   *   c c   + l b   *   l c )   /   w 1 ) ; 
 
 	 	         o _ d e s t . d y = - l b ; 
 
 	 	         o _ d e s t . d x = - l a ; 
 
 	 	         o _ d e s t . s c a l a r = n u m ; 
 
 	 	         r e t u r n   t r u e ; 
 
 	         } 	 
 
 
 
 	         p r i v a t e   N y A R I n t P o i n t 2 d [ ]   _ _ p t   =   N y A R I n t P o i n t 2 d . c r e a t e A r r a y ( 2 ) ; 
 
 	         p r i v a t e   N y A R L i n e a r   _ _ t e m p _ l   =   n e w   N y A R L i n e a r ( ) ; 
 
 
 
 	         / * * 
 
 	           *   000000NM0n00000000g0Y00
 
 	           *   
 
 	           *   @ p a r a m   i _ p o s 1 
 
 	           *   @ p a r a m   i _ p o s 2 
 
 	           *   @ p a r a m   i _ e d g e 
 
 	           *   @ p a r a m   o _ c o o r d 
 
 	           *   @ r e t u r n 
 
 	           *   @ 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   b o o l   t r a c e L i n e W i t h C l i p ( N y A R D o u b l e P o i n t 2 d   i _ p o s 1 , 
 
 	 	         N y A R D o u b l e P o i n t 2 d   i _ p o s 2 ,   i n t   i _ e d g e ,   V e c L i n e a r C o o r d i n a t e s   o _ c o o r d ) 
 
 	         { 
 
 	 	         N y A R I n t S i z e   s = t h i s . _ r e f _ b a s e _ r a s t e r . g e t S i z e ( ) ; 
 
                         b o o l   i s _ p 1 _ i n s i d e _ a r e a ,   i s _ p 2 _ i n s i d e _ a r e a ; 
 
 
 
 	 	         N y A R I n t P o i n t 2 d [ ]   p t   =   t h i s . _ _ p t ; 
 
 	 	         / /   }RL0{VQk0B00K00x
 
 	 	         i s _ p 1 _ i n s i d e _ a r e a   =   s . i s I n n e r P o i n t ( i _ p o s 1 ) ; 
 
 	 	         i s _ p 2 _ i n s i d e _ a r e a   =   s . i s I n n e r P o i n t ( i _ p o s 2 ) ; 
 
 	 	         / /   Ppeg0R\
 
 	 	         i f   ( i s _ p 1 _ i n s i d e _ a r e a   & &   i s _ p 2 _ i n s i d e _ a r e a )   { 
 
 	 	 	         / /   2 j00000000_j0W00
 
 	 	 	         i f   ( ! t h i s . t r a c e L i n e ( i _ p o s 1 ,   i _ p o s 2 ,   i _ e d g e ,   o _ c o o r d ) )   { 
 
 	 	 	 	         r e t u r n   f a l s e ; 
 
 	 	 	         } 
 
 	 	 	         r e t u r n   t r u e ; 
 
 
 
 	 	         } 
 
 	 	         / /   1 , 0 Pn04XTo00}R0Q[
 
 	 	         i f   ( ! t h i s . _ _ t e m p _ l . m a k e L i n e a r W i t h N o r m a l i z e ( i _ p o s 1 ,   i _ p o s 2 ) )   { 
 
 	 	 	         r e t u r n   f a l s e ; 
 
 	 	         } 
 
 	 	         i f   ( ! t h i s . _ _ t e m p _ l . m a k e S e g m e n t L i n e ( s . w , s . h , p t ) )   { 
 
 	 	 	         r e t u r n   f a l s e ; 
 
 	 	         } 
 
 	 	         i f   ( i s _ p 1 _ i n s i d e _ a r e a   ! =   i s _ p 2 _ i n s i d e _ a r e a )   { 
 
 	 	 	         / /   1 j00000000_k00Yk0Qf0D0_0pk0яD0*퐤Np0_00
 
 
 
 	 	 	         i f   ( i s _ p 1 _ i n s i d e _ a r e a )   { 
 
 	 	 	 	         / /   p 2 L0{VY
 
 	 	 	 	         p t [ ( i _ p o s 2 . s q D i s t ( p t [ 0 ] )   <   i _ p o s 2 . s q D i s t ( p t [ 1 ] ) )   ?   1   :   0 ] . s e t V a l u e ( i _ p o s 1 ) ; 
 
 	 	 	         }   e l s e   { 
 
 	 	 	 	         / /   p 1 L0{VY
 
 	 	 	 	         p t [ ( i _ p o s 1 . s q D i s t ( p t [ 0 ] )   <   i _ p o s 2 . s q D i s t ( p t [ 1 ] ) )   ?   1   :   0 ] . s e t V a l u e ( i _ p o s 2 ) ; 
 
 	 	 	         } 
 
 	 	         }   e l s e   { 
 
 	 	 	         / /   0 j00000000W0f0_00_0p0OF00
 
 	 	 	         i f   ( ! t h i s . _ _ t e m p _ l . m a k e L i n e a r W i t h N o r m a l i z e ( i _ p o s 1 ,   i _ p o s 2 ) )   { 
 
 	 	 	 	         r e t u r n   f a l s e ; 
 
 	 	 	         } 
 
 	 	 	         i f   ( ! t h i s . _ _ t e m p _ l . m a k e S e g m e n t L i n e ( s . w , s . h ,   p t ) )   { 
 
 	 	 	 	         r e t u r n   f a l s e ; 
 
 	 	 	         } 
 
 	 	         } 
 
 	 	         i f   ( ! t h i s . t r a c e L i n e ( p t [ 0 ] ,   p t [ 1 ] ,   i _ e d g e ,   o _ c o o r d ) )   { 
 
 	 	 	         r e t u r n   f a l s e ; 
 
 	 	         } 
 
 
 
 	 	         r e t u r n   t r u e ; 
 
 	         } 
 
                 p u b l i c   a b s t r a c t   i n t   g e t A r e a V e c t o r 3 3 ( i n t   i x ,   i n t   i y ,   i n t   i w ,   i n t   i h ,   N y A R V e c L i n e a r 2 d   o _ p o s v e c ) ; 
 
                 p u b l i c   a b s t r a c t   i n t   g e t A r e a V e c t o r 2 2 ( i n t   i x ,   i n t   i y ,   i n t   i w ,   i n t   i h ,   N y A R V e c L i n e a r 2 d   o _ p o s v e c ) ; 
 
         } 
 
 } 