/ *   
 
   *   P R O J E C T :   N y A R T o o l k i t ( E x t e n s i o n ) 
 
   *   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
   *   T h e   N y A R T o o l k i t   i s   J a v a   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 . C o l l e c t i o n s . G e n e r i c ; 
 
 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 . m a r k e r s y s t e m . u t i l s 
 
 { 
 
         p u b l i c   c l a s s   T r a c k i n g L i s t   :   L i s t < T M a r k e r D a t a > 
 
         { 
 
                 p r i v a t e   V e r t e x S o r t T a b l e   _ t r a c k i n g _ l i s t ; 
 
                 p u b l i c   T r a c k i n g L i s t ( ) 
 
                 { 
 
                         t h i s . _ t r a c k i n g _ l i s t   =   n e w   V e r t e x S o r t T a b l e ( 1 ) ; 
 
                 } 
 
                 p u b l i c   v o i d   p r e p a r e ( ) 
 
                 { 
 
                         / / 00000000000000
 
                         t h i s . _ t r a c k i n g _ l i s t . r e s e t ( ) ; 
 
                         / / iQn0_00k0Rg$P-[
 
                         f o r   ( i n t   i   =   t h i s . C o u n t   -   1 ;   i   > =   0 ;   i - - ) 
 
                         { 
 
                                 T M a r k e r D a t a   t a r g e t   =   t h i s [ i ] ; 
 
                                 / / vMRn0s q n00000
 
                                 t a r g e t . s q   =   n u l l ; 
 
                                 / / m1Y0000n00000000
 
                                 i f   ( t a r g e t . l i f e   >   0 ) 
 
                                 { 
 
                                         t a r g e t . l o s t _ c o u n t + + ; 
 
                                 } 
 
                         } 
 
                 } 
 
                 p r i v a t e   i n t [ ]   _ _ r e t   =   n e w   i n t [ 2 ] ; 
 
                 p u b l i c   b o o l   u p d a t e ( S q u a r e S t a c k . I t e m   i _ n e w _ s q ) 
 
                 { 
 
                         i n t [ ]   r e t   =   t h i s . _ _ r e t ; 
 
                         i n t   n e w _ a r e a   =   i _ n e w _ s q . r e c t _ a r e a ; 
 
                         / / pn0[҉ݍ
 
                         i n t   n e w _ s q _ d i s t   =   i _ n e w _ s q . v e r t e x _ a r e a . g e t D i a g o n a l S q D i s t ( ) ; 
 
                         b o o l   i s _ d i s p a t c h e d   =   f a l s e ; 
 
                         f o r   ( i n t   i   =   t h i s . C o u n t   -   1 ;   i   > =   0 ;   i - - ) 
 
                         { 
 
                                 T M a r k e r D a t a   t a r g e t   =   t h i s [ i ] ; 
 
                                 i f   ( t a r g e t . l o s t _ c o u n t   >   1 ) 
 
                                 { 
 
                                         c o n t i n u e ; 
 
                                 } 
 
                                 / / bMzkL0%`o0 . 8 - 1 . 2 
PNYn0	YRj00!q
 
                                 i n t   a _ r a t e   =   n e w _ a r e a   *   1 0 0   /   t a r g e t . t l _ r e c t _ a r e a ; 
 
                                 i f   ( a _ r a t e   <   5 0   | |   1 5 0   <   a _ r a t e ) 
 
                                 { 
 
                                         c o n t i n u e ; 
 
                                 } 
 
                                 / / yRݍ^ 2 n0NWNL0[҉}ݍ^ 2 n04 
PN
Nj00!q
 
                                 l o n g   s q _ m o v e   =   t a r g e t . t l _ c e n t e r . s q D i s t ( i _ n e w _ s q . c e n t e r 2 d ) ; 
 
                                 i f   ( s q _ m o v e   *   4   /   n e w _ s q _ d i s t   >   0 ) 
 
                                 { 
 
                                         c o n t i n u e ; 
 
                                 } 
 
                                 c o m p a r e V e r t e x S e t ( i _ n e w _ s q . o b _ v e r t e x ,   t a r g e t . t l _ v e r t e x ,   r e t ) ; 
 
                                 i n t   s q d i s t   =   r e t [ 1 ] ; 
 
                                 i n t   s h i f t   =   r e t [ 0 ] ; 
 
                                 / / pyRݍn0TL00( -N_pyRݍ+ 8 ) n01 0 
P0H0f0_00N G   < - 
 
                                 i f   ( s q d i s t   >   ( s q _ m o v e   +   8 )   *   1 0 ) 
 
                                 { 
 
                                         c o n t i n u e ; 
 
                                 } 
 
                                 / / {v2SK0x
 
                                 V e r t e x S o r t T a b l e . I t e m   i t e m   =   t h i s . _ t r a c k i n g _ l i s t . g e t I n s e r t P o i n t ( s q d i s t ) ; 
 
                                 i f   ( i t e m   = =   n u l l ) 
 
                                 { 
 
                                         c o n t i n u e ; 
 
                                 } 
 
                                 / / {v2
 
                                 i t e m   =   t h i s . _ t r a c k i n g _ l i s t . i n s e r t F r o m T a i l B e f o r e ( i t e m ) ; 
 
                                 i t e m . m a r k e r   =   t a r g e t ; 
 
                                 i t e m . s h i f t   =   s h i f t ; 
 
                                 i t e m . s q _ d i s t   =   s q d i s t ; 
 
                                 i t e m . r e f _ s q   =   i _ n e w _ s q ; 
 
                                 i s _ d i s p a t c h e d   =   t r u e ; 
 
                         } 
 
                         r e t u r n   i s _ d i s p a t c h e d ; 
 
                 } 
 
 
 
                 / * * 
 
                   *   S0n0peo00p000TXn0000ϑ0{W0f00MRk0$P0ԏW0~0Y00
 
                   *   &Ns0L0TX0g0B00p000TXn0 gNOn0yRϑ0{W0f00]0n0Bfn0000ϑh0NWNyRϑn0T0ԏW0~0Y00
 
                   *   @ p a r a m   i _ s q u a r e 
 
                   *   k[an0wb_
 
                   *   @ r e t u r n 
 
                   *   [ 0 ] k0000ϑ0ԏW0~0Y00
 
                   *   [ 1 ] k0pyRݍn0Tn0NWN$P0ԏW0~0Y00
 
                   *   000ϑo0t h i s - i _ s q u a r e g0Y001 n04XT0i _ v 1 [ 0 ] h0i _ v 2 [ 1 ] L0[_pk0j00( s h i f t ϑ1 ) g0B00S0h00:yW0~0Y00
 
                   * / 
 
                 p u b l i c   s t a t i c   v o i d   c o m p a r e V e r t e x S e t ( N y A R I n t P o i n t 2 d [ ]   i _ v 1 ,   N y A R I n t P o i n t 2 d [ ]   i _ v 2 ,   i n t [ ]   r e t ) 
 
                 { 
 
                         / / 3 - 0 juv
 
                         i n t   m i n _ d i s t   =   i n t . M a x V a l u e ; 
 
                         i n t   m i n _ i n d e x   =   0 ; 
 
                         i n t   x d ,   y d ; 
 
                         f o r   ( i n t   i   =   3 ;   i   > =   0 ;   i - - ) 
 
                         { 
 
                                 i n t   d   =   0 ; 
 
                                 f o r   ( i n t   i 2   =   3 ;   i 2   > =   0 ;   i 2 - - ) 
 
                                 { 
 
                                         x d   =   ( i n t ) ( i _ v 1 [ i 2 ] . x   -   i _ v 2 [ ( i 2   +   i )   %   4 ] . x ) ; 
 
                                         y d   =   ( i n t ) ( i _ v 1 [ i 2 ] . y   -   i _ v 2 [ ( i 2   +   i )   %   4 ] . y ) ; 
 
                                         d   + =   x d   *   x d   +   y d   *   y d ; 
 
                                 } 
 
                                 i f   ( m i n _ d i s t   >   d ) 
 
                                 { 
 
                                         m i n _ d i s t   =   d ; 
 
                                         m i n _ i n d e x   =   i ; 
 
                                 } 
 
                         } 
 
                         r e t [ 0 ]   =   m i n _ i n d e x ; 
 
                         r e t [ 1 ]   =   m i n _ d i s t ; 
 
                 } 
 
                 / * * 
 
                   *   000000000x0R0S0n0a d d NYO0j0D0g0m00
 
                   * / 
 
                 p u b l i c   v o i d   a d d ( T M a r k e r D a t a   e ) 
 
                 { 
 
                         / / 1 0000n0 g'YP܈pe
 
                         f o r   ( i n t   i   =   0 ;   i   <   2 ;   i + + ) 
 
                         { 
 
                                 t h i s . _ t r a c k i n g _ l i s t . a p p e n d ( ) ; 
 
                         } 
 
                         b a s e . A d d ( e ) ; 
 
                 } 
 
                 p u b l i c   v o i d   f i n i s h ( ) 
 
                 { 
 
                         / /  Nsn0 g0ؚD000000_00
 
                         V e r t e x S o r t T a b l e . I t e m   t o p _ i t e m   =   t h i s . _ t r a c k i n g _ l i s t . g e t T o p I t e m ( ) ; 
 
                         / / 00000iQg0M0j0O0j00~0g00 NsL0ؚD0k000000_00
 
                         w h i l e   ( t o p _ i t e m   ! =   n u l l ) 
 
                         { 
 
                                 / / iQW0_00000n0A R m a r k e r I n d e x n00000000
 
                                 T M a r k e r D a t a   t a r g e t   =   t o p _ i t e m . m a r k e r ; 
 
                                 / / iQ0000L01 N
N*giQn04XTn00iQ	
 
                                 i f   ( t a r g e t . l o s t _ c o u n t   >   0 ) 
 
                                 { 
 
                                         t a r g e t . l o s t _ c o u n t   =   0 ; 
 
                                         t a r g e t . l i f e + + ; 
 
                                         t a r g e t . s q   =   t o p _ i t e m . r e f _ s q ; 
 
                                         t a r g e t . s q . r o t a t e V e r t e x L ( 4   -   t o p _ i t e m . s h i f t ) ; 
 
                                         N y A R I n t P o i n t 2 d . s h i f t C o p y ( t o p _ i t e m . r e f _ s q . o b _ v e r t e x ,   t a r g e t . t l _ v e r t e x ,   4   -   t o p _ i t e m . s h i f t ) ; 
 
                                         t a r g e t . t l _ c e n t e r . s e t V a l u e ( t o p _ i t e m . r e f _ s q . c e n t e r 2 d ) ; 
 
                                         t a r g e t . t l _ r e c t _ a r e a   =   t o p _ i t e m . r e f _ s q . r e c t _ a r e a ; 
 
                                 } 
 
                                 / / Wn0000h0͑Y0000000JRdY000
 
                                 t h i s . _ t r a c k i n g _ l i s t . d i s a b l e M a t c h I t e m ( t o p _ i t e m ) ; 
 
                                 t o p _ i t e m   =   t h i s . _ t r a c k i n g _ l i s t . g e t T o p I t e m ( ) ; 
 
                         } 
 
                 } 
 
         } 
 
 } 