/ *   
 
   *   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 
 
 { 
 
         p u b l i c   c l a s s   V e c L i n e a r C o o r d i n a t e s 
 
         { 	 
 
 	         / * * 
 
 	           *   000Wg0Y00
 
 	           *   *00000<h
}W0~0Y00
 
 	           * / 
 
 	         p u b l i c   c l a s 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   :   N y A R V e c L i n e a r 2 d 
 
 	         { 
 
 	 	         / * * 
 
 	 	           *   0000n02 WN$Pg0Y00*n07_^$Pk00j00~0Y00
 
 	 	           * / 
 
 	 	         p u b l i c   d o u b l e   s c a l a r ; 
 
 	 	         p u b l i c   n e w   s t a t i c   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 ( i n t   i _ l e n g t h ) 
 
 	 	         { 
 
 	 	 	         V e c L i n e a r C o o r d i n a t e P o i n t [ ]   r = n e w   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 _ l e n g t h ] ; 
 
 	 	 	         f o r ( i n t   i = 0 ; i < i _ l e n g t h ; i + + ) { 
 
 	 	 	 	         r [ i ] = n e w   V e c L i n e a r C o o r d i n a t e P o i n t ( ) ; 
 
 	 	 	         } 
 
 	 	 	         r e t u r n   r ; 
 
 	 	         } 
 
 	         } 	 
 
 	         p u b l i c   i n t   l e n g t h ; 
 
 	         p u b l i c   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 t e m s ; 
 
 
 
 	         p u b l i c   V e c L i n e a r C o o r d i n a t e s ( i n t   i _ l e n g t h ) 
 
 	         { 
 
 	 	         t h i s . l e n g t h   =   0 ; 
 
 	 	         t h i s . i t e m 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 ( i _ l e n g t h ) ; 
 
 	         } 
 
 	         / * * 
 
 	           *   000001 , 2 aPk06RPW0~0Y00
 
 	           * / 
 
 	         p u b l i c   v o i d   l i m i t Q u a d r a n t T o 1 2 ( ) 
 
 	         { 
 
 	 	         f o r   ( i n t   i   =   t h i s . l e n g t h   -   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   t a r g e t 1   =   t h i s . i t e m s [ i ] ; 
 
 	 	 	         i f   ( t a r g e t 1 . d y   <   0 )   { 
 
 	 	 	 	         t a r g e t 1 . d y   * =   - 1 ; 
 
 	 	 	 	         t a r g e t 1 . d x   * =   - 1 ; 
 
 	 	 	         } 
 
 	 	         } 
 
 	         } 
 
         	 
 
 
 
 	         / * * 
 
 	           *   *MRK000K00000n00000( v}[$Pn0'YM0D00000) 0^0XU0Z0k0bQW0~0Y00
 
 	           *   
 
 	           *   @ p a r a m   i _ v e c p o s 
 
 	           *                         bQCQn0
 
 	           *   @ p a r a m   i _ l e n 
 
 	           *   @ p a r a m   o _ i n d e x 
 
 	           *                         00000juS0SQ0S0MR0SQ0S0000000n0Ppeo00S0n0MRn0peh0TX0k0j00~0Y00
 
 	           * / 
 
 	         p u b l i c   v o i d   g e t O r d e r d K e y C o o r d I n d e x e s ( i n t [ ]   o _ i n d e x ) 
 
 	         { 
 
 	 	         g e t K e y C o o r d I n d e x e s ( o _ i n d e x ) ; 
 
 	 	         / /   i d x g0000
 
                         i n t   o u t _ l e n _ 1   =   o _ i n d e x . L e n g t h   -   1 ; 
 
 	 	         f o r   ( i n t   i   =   0 ;   i   <   o u t _ l e n _ 1 ; )   { 
 
 	 	 	         i f   ( o _ i n d e x [ i ]   >   o _ i n d e x [ i   +   1 ] )   { 
 
 	 	 	 	         i n t   t   =   o _ i n d e x [ i ] ; 
 
 	 	 	 	         o _ i n d e x [ i ]   =   o _ i n d e x [ i   +   1 ] ; 
 
 	 	 	 	         o _ i n d e x [ i   +   1 ]   =   t ; 
 
 	 	 	 	         i   =   0 ; 
 
 	 	 	 	         c o n t i n u e ; 
 
 	 	 	         } 
 
 	 	 	         i + + ; 
 
 	 	         } 
 
 	 	         r e t u r n ; 
 
 	         } 
 
 	         p u b l i c   v o i d   g e t K e y C o o r d I n d e x e s ( i n t [ ]   o _ i n d e x ) 
 
 	         { 
 
 	 	         V e c L i n e a r C o o r d i n a t e P o i n t [ ]   v p   =   t h i s . i t e m s ; 
 
                         D e b u g . A s s e r t ( o _ i n d e x . L e n g t h   < =   t h i s . l e n g t h ) ; 
 
 	 	         i n t   i ; 
 
                         i n t   o u t _ l e n   =   o _ i n d e x . L e n g t h ; 
 
 	 	         i n t   o u t _ l e n _ 1   =   o u t _ l e n   -   1 ; 
 
 	 	         f o r   ( i   =   o u t _ l e n   -   1 ;   i   > =   0 ;   i - - )   { 
 
 	 	 	         o _ i n d e x [ i ]   =   i ; 
 
 	 	         } 
 
 	 	         / /   s q d i s t g0000Y00( B - > S ) 
 
 	 	         f o r   ( i   =   0 ;   i   <   o u t _ l e n _ 1 ; )   { 
 
 	 	 	         i f   ( v p [ o _ i n d e x [ i ] ] . s c a l a r   <   v p [ o _ i n d e x [ i   +   1 ] ] . s c a l a r )   { 
 
 	 	 	 	         i n t   t   =   o _ i n d e x [ i ] ; 
 
 	 	 	 	         o _ i n d e x [ i ]   =   o _ i n d e x [ i   +   1 ] ; 
 
 	 	 	 	         o _ i n d e x [ i   +   1 ]   =   t ; 
 
 	 	 	 	         i   =   0 ; 
 
 	 	 	 	         c o n t i n u e ; 
 
 	 	 	         } 
 
 	 	 	         i + + ; 
 
 	 	         } 
 
 	 	         / /   HQk04 P0s q _ d i s t g0000W0j0L00<h
}
 
 	 	         f o r   ( i   =   o u t _ l e n ;   i   <   t h i s . l e n g t h ;   i + + )   { 
 
 	 	 	         / /   MRn0$Ph0k
 
 	 	 	         f o r   ( i n t   i 2   =   0 ;   i 2   <   o u t _ l e n ;   i 2 + + )   { 
 
 	 	 	 	         i f   ( v p [ i ] . s c a l a r   >   v p [ o _ i n d e x [ i 2 ] ] . s c a l a r )   { 
 
 	 	 	 	 	         / /   $P?ceQn0pn0000
 
 	 	 	 	 	         f o r   ( i n t   i 3   =   o u t _ l e n   -   1 ;   i 3   >   i 2 ;   i 3 - - )   { 
 
 	 	 	 	 	 	         o _ i n d e x [ i 3 ]   =   o _ i n d e x [ i 3   -   1 ] ; 
 
 	 	 	 	 	         } 
 
 	 	 	 	 	         / /   -[
 
 	 	 	 	 	         o _ i n d e x [ i 2 ]   =   i ; 
 
 	 	 	 	 	         b r e a k ; 
 
 	 	 	 	         } 
 
 	 	 	         } 
 
 	 	         } 
 
 	 	         r e t u r n ; 
 
 	         } 
 
 	         p u b l i c   v o i d   g e t K e y C o o r d ( 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 _ i n d e x ) 
 
 	         { 
 
 	 	         V e c L i n e a r C o o r d i n a t e P o i n t [ ]   v p   =   t h i s . i t e m s ; 
 
                         D e b u g . A s s e r t ( o _ i n d e x . L e n g t h   < =   t h i s . l e n g t h ) ; 
 
 	 	         i n t   i ; 
 
                         i n t   o u t _ l e n   =   o _ i n d e x . L e n g t h ; 
 
 	 	         i n t   o u t _ l e n _ 1   =   o u t _ l e n   -   1 ; 
 
 	 	         f o r   ( i   =   o u t _ l e n   -   1 ;   i   > =   0 ;   i - - )   { 
 
 	 	 	         o _ i n d e x [ i ]   =   v p [ i ] ; 
 
 	 	         } 
 
 	 	         / /   s q d i s t g0000Y00( B - > S ) 
 
 	 	         f o r   ( i   =   0 ;   i   <   o u t _ l e n _ 1 ; )   { 
 
 	 	 	         i f   ( o _ i n d e x [ i ] . s c a l a r   <   o _ i n d e x [ i   +   1 ] . s c a l a r )   { 
 
 	 	 	 	         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   =   o _ i n d e x [ i ] ; 
 
 	 	 	 	         o _ i n d e x [ i ]   =   o _ i n d e x [ i   +   1 ] ; 
 
 	 	 	 	         o _ i n d e x [ i   +   1 ]   =   t ; 
 
 	 	 	 	         i   =   0 ; 
 
 	 	 	 	         c o n t i n u e ; 
 
 	 	 	         } 
 
 	 	 	         i + + ; 
 
 	 	         } 
 
 	 	         / /   HQk04 P0s q _ d i s t g0000W0j0L00<h
}
 
 	 	         f o r   ( i   =   o u t _ l e n ;   i   <   t h i s . l e n g t h ;   i + + )   { 
 
 	 	 	         / /   MRn0$Ph0k
 
 	 	 	         f o r   ( i n t   i 2   =   0 ;   i 2   <   o u t _ l e n ;   i 2 + + )   { 
 
 	 	 	 	         i f   ( v p [ i ] . s c a l a r   >   o _ i n d e x [ i 2 ] . s c a l a r )   { 
 
 	 	 	 	 	         / /   $P?ceQn0pn0000
 
 	 	 	 	 	         f o r   ( i n t   i 3   =   o u t _ l e n   -   1 ;   i 3   >   i 2 ;   i 3 - - )   { 
 
 	 	 	 	 	 	         o _ i n d e x [ i 3 ]   =   o _ i n d e x [ i 3   -   1 ] ; 
 
 	 	 	 	 	         } 
 
 	 	 	 	 	         / /   -[
 
 	 	 	 	 	         o _ i n d e x [ i 2 ]   =   v p [ i ] ; 
 
 	 	 	 	 	         b r e a k ; 
 
 	 	 	 	         } 
 
 	 	 	         } 
 
 	 	         } 
 
 	 	         r e t u r n ; 
 
 	         }   	 
 
         	 
 
 	         / * * 
 
 	           *    g0'YM0D00000bRn0000000ԏW0~0Y00
 
 	           *   
 
 	           *   @ r e t u r n 
 
 	           * / 
 
 	         p u b l i c   i n t   g e t M a x C o o r d I n d e x ( ) 
 
 	         { 
 
 	 	         V e c L i n e a r C o o r d i n a t e P o i n t [ ]   v p   =   t h i s . i t e m s ; 
 
 	 	         i n t   i n d e x   =   0 ; 
 
 	 	         d o u b l e   m a x _ d i s t   =   v p [ 0 ] . s c a l a r ; 
 
 	 	         f o r   ( i n t   i   =   t h i s . l e n g t h   -   1 ;   i   >   0 ;   i - - )   { 
 
 	 	 	         i f   ( m a x _ d i s t   <   v p [ i ] . s c a l a r )   { 
 
 	 	 	 	         m a x _ d i s t   =   v p [ i ] . s c a l a r ; 
 
 	 	 	 	         i n d e x   =   i ; 
 
 	 	 	         } 
 
 	 	         } 
 
 	 	         r e t u r n   i n d e x ; 
 
 	         } 
 
 
 
 
 
 	         / * * 
 
 	           *   0000000c[W0f00000`0h0`000	00000JRdW0~0Y00
 
 	           * / 
 
 	         / * * 
 
 	           *   'YM0U0( s q _ d i s t ) L00 n000000JRdW0f00 }0MRek0p0~0Y00
 
 	           * / 
 
 	         p u b l i c   v o i d   r e m o v e Z e r o D i s t I t e m ( ) 
 
 	         { 
 
 	 	         / / MRep0
 
 	 	         i n t   i d x = 0 ; 
 
 	 	         i n t   l e n = t h i s . l e n g t h ; 
 
 	 	         f o r ( i n t   i = 0 ; i < l e n ; i + + ) { 
 
 	 	 	         i f ( t h i s . i t e m s [ i ] . s c a l a r ! = 0 ) { 
 
 	 	 	 	         i d x + + ; 
 
 	 	 	 	         c o n t i n u e ; 
 
 	 	 	         } 
 
 	 	 	         f o r ( i = i + 1 ; i < l e n ; i + + ) { 
 
 	 	 	 	         i f ( t h i s . i t e m s [ i ] . s c a l a r ! = 0 ) { 
 
 	 	 	 	 	         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 e m p   =   t h i s . i t e m s [ i ] ; 
 
 	 	 	 	 	         t h i s . i t e m s [ i ] = t h i s . i t e m s [ i d x ] ; 
 
 	 	 	 	 	         t h i s . i t e m s [ i d x ] = t e m p ; 
 
 	 	 	 	 	         i d x + + ; 
 
 	 	 	 	 	         i - - ; 
 
 	 	 	 	 	         b r e a k ; 
 
 	 	 	 	         } 
 
 	 	 	         } 
 
 	 	         } 
 
 	 	         t h i s . l e n g t h = i d x ; 
 
 	 	         r e t u r n ; 
 
 	         } 
 
         } 
 
 } 