/ *   
 
   *   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   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 ; 
 
 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 . c o r e 
 
 { 
 
 
 
 
 
 
 
         / * * 
 
           *   S0n0000o00ݍ0000)R(uW0_00pƖTTXn000000Qt_j0cOW0~0Y00
 
           *   2 d0n0pƖTTX0kW0f00ƖTn0TpTXn0ݍL0 g0яO0k0j00D}0T0[00{W0~0Y00
 
           *   < p > 000000  -   
 
           *   2 d0n0pƖTn0}S__00n0ݍ0000\O00]0n0ݍL0\U0D0n00n0K00k0bQY00S0h0g00
 
           *   vQ0n0pn0yRݍL0 g\k0j00D}0T0[00{W0~0Y00
 
           *   < / p > 
 
           *   < p > OD0e 0- 
 
           *   S0n0000o00~0Z0ݍ0000\O0_00k0ݍ$P0000W0f00!kk0D}0T0[00_0Kbg0OD0~0Y00
 
           *   ݍ000k0o0Lh0RL0B00~0Y00R0Wn$P0L0k$Ph0W0f00]0n0ݍ$P0<h
}W0~0Y00
 
           *   Lh0Rn0ݍ0000\O0B}H0_000D}T[00{W0~0Y00
 
           *   < o l > 
 
           *   < l i > { @ l i n k   # s e t M a p S i z e } peg00000000kY00ppe	0-[Y000
 
           *   < l i > { @ l i n k   # s e t D i s t } , ~0_0o0{ @ l i n k   # s e t P o i n t D i s t s } g00ݍ000k0hQf0n0$P0fM000
 
           *   < l i > 
 
           *   < / o l > 
 
           *   < / p > 
 
           * / 
 
         p u b l i c   c l a s s   N y A R D i s t M a p 
 
         { 
 
                 / * *   Qt(un0000W* / 
 
                 p r o t e c t e d   c l a s s   D i s t I t e m 
 
                 { 
 
                         p u b l i c   i n t   r o w ; 
 
                         p u b l i c   i n t   c o l ; 
 
                         p u b l i c   i n t   d i s t ; 
 
                 } 
 
                 / * *  0ݍ000(un0MR* / 
 
                 p r o t e c t e d   D i s t I t e m [ ]   _ m a p ; 
 
                 / * *  0000	Ype* / 
 
                 p r o t e c t e d   i n t   _ m i n _ d i s t ; 
 
                 / * *  0000	Ype* / 
 
                 p r o t e c t e d   i n t   _ m i n _ d i s t _ i n d e x ; 
 
                 / * *  0000	Ype* / 
 
                 p r o t e c t e d   i n t   _ s i z e _ r o w ; 
 
                 / * *  0000	Ype* / 
 
                 p r o t e c t e d   i n t   _ s i z e _ c o l ; 
 
                 / * * 
 
                   *   0000000g0Y00
 
                   *   000n0 g'Y0000c[W0f000000000\ObW0~0Y00
 
                   *   @ p a r a m   i _ m a x _ c o l 
 
                   *   000n0 g'YRpe
 
                   *   @ p a r a m   i _ m a x _ r o w 
 
                   *   000n0 g'YLpe
 
                   * / 
 
                 p u b l i c   N y A R D i s t M a p ( i n t   i _ m a x _ c o l ,   i n t   i _ m a x _ r o w ) 
 
                 { 
 
                         t h i s . _ m i n _ d i s t   =   i n t . M a x V a l u e ; 
 
                         t h i s . _ m i n _ d i s t _ i n d e x   =   0 ; 
 
                         t h i s . _ s i z e _ c o l   =   i _ m a x _ c o l ; 
 
                         t h i s . _ s i z e _ r o w   =   i _ m a x _ r o w ; 
 
                         t h i s . _ m a p   =   n e w   D i s t I t e m [ i _ m a x _ c o l   *   i _ m a x _ r o w ] ; 
 
                         f o r   ( i n t   i   =   0 ;   i   <   i _ m a x _ c o l   *   i _ m a x _ r o w ;   i + + ) 
 
                         { 
 
                                 t h i s . _ m a p [ i ]   =   n e w   D i s t I t e m ( ) ; 
 
                         } 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00000n00000c[W0~0Y00
 
                   *   $Po0RgSU00~0[000
 
                   *   @ p a r a m   i _ c o l 
 
                   *   eW0D0Rpe0
 
                   *   @ p a r a m   i _ r o w 
 
                   *   eW0D0Lpe0
 
                   * / 
 
                 p u b l i c   v o i d   s e t M a p S i z e ( i n t   i _ c o l ,   i n t   i _ r o w ) 
 
                 { 
 
                         t h i s . _ s i z e _ r o w   =   i _ r o w ; 
 
                         t h i s . _ s i z e _ c o l   =   i _ c o l ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00Rh0L0c[W0f00ݍ$P1 P0000k0000W0~0Y00
 
                   *   < p > la  - 
 
                   *   S0n0A P I o0NOg0Y00'`L0_j0Bfo00{ @ l i n k   # s e t P o i n t D i s t s } 0Sk00 Nbf0Y00pe0iW0f0O0`0U0D00
 
                   *   < / p > 
 
                   *   @ p a r a m   i _ c o l 
 
                   *   Rn0000000c[W0~0Y00
 
                   *   @ p a r a m   i _ r o w 
 
                   *   Ln0000000c[W0~0Y00
 
                   *   @ p a r a m   i _ d i s t 
 
                   *   ]0n0Lh0Rn0ݍ$P0c[W0~0Y00
 
                   * / 
 
                 p u b l i c   v o i d   s e t D i s t ( i n t   i _ c o l ,   i n t   i _ r o w ,   i n t   i _ d i s t ) 
 
                 { 
 
                         t h i s . _ m i n _ d i s t _ i n d e x   =   t h i s . _ s i z e _ c o l   *   i _ r o w   +   i _ c o l ; 
 
                         D i s t I t e m   i t e m   =   t h i s . _ m a p [ t h i s . _ m i n _ d i s t _ i n d e x ] ; 
 
                         i t e m . c o l   =   i _ c o l ; 
 
                         i t e m . r o w   =   i _ r o w ; 
 
                         i t e m . d i s t   =   i _ d i s t ; 
 
                         / /  g\$P0 g'Y$Pn0Q{
 
                         i f   ( i _ d i s t   <   t h i s . _ m i n _ d i s t ) 
 
                         { 
 
                                 t h i s . _ m i n _ d i s t   =   i _ d i s t ; 
 
                         } 
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00d0n0^jpMRTXn0ݍ$P0 NbW0f0000k0000W0~0Y00
 
                   *   < p > 
 
                   *   [ň00  -   
 
                   *   pn0000000L0T0j0D04XTo00S0n0peSk00000000W0f0O0`0U0D00
 
                   *   < / p > 
 
                   *   @ p a r a m   i _ v e r t e x _ r 
 
                   *   kY00p0<h
}W0_0MR0
 
                   *   @ p a r a m   i _ r o w _ l e n 
 
                   *   i _ v e r t e x _ r n0	gRj0 }pe
 
                   *   @ p a r a m   i _ v e r t e x _ c 
 
                   *   Wnh0j00p0<h
}W0_0MR
 
                   *   @ p a r a m   i _ c o l _ l e n 
 
                   *   i _ v e r t e x _ c n0	gRj0 }pe
 
                   * / 
 
                 p u b l i c   v o i d   s e t P o i n t D i s t s ( N y A R I n t P o i n t 2 d [ ]   i _ v e r t e x _ r ,   i n t   i _ r o w _ l e n ,   N y A R I n t P o i n t 2 d [ ]   i _ v e r t e x _ c ,   i n t   i _ c o l _ l e n ) 
 
                 { 
 
                         D i s t I t e m [ ]   m a p   =   t h i s . _ m a p ; 
 
                         / / d i s t o r t i o n M a p 0\Ob0d0D0g0k0 g\$Pn0000000S_
 
                         i n t   m i n _ i n d e x   =   0 ; 
 
                         i n t   m i n _ d i s t   =   i n t . M a x V a l u e ; 
 
                         i n t   i d x   =   0 ; 
 
                         f o r   ( i n t   r   =   0 ;   r   <   i _ r o w _ l e n ;   r + + ) 
 
                         { 
 
                                 f o r   ( i n t   c   =   0 ;   c   <   i _ c o l _ l e n ;   c + + ) 
 
                                 { 
 
                                         m a p [ i d x ] . c o l   =   c ; 
 
                                         m a p [ i d x ] . r o w   =   r ; 
 
                                         i n t   d   =   i _ v e r t e x _ r [ r ] . s q D i s t ( i _ v e r t e x _ c [ c ] ) ; 
 
                                         m a p [ i d x ] . d i s t   =   d ; 
 
                                         i f   ( m i n _ d i s t   >   d ) 
 
                                         { 
 
                                                 m i n _ i n d e x   =   i d x ; 
 
                                                 m i n _ d i s t   =   d ; 
 
                                         } 
 
                                         i d x + + ; 
 
                                 } 
 
                         } 
 
                         t h i s . _ m i n _ d i s t   =   m i n _ d i s t ; 
 
                         t h i s . _ m i n _ d i s t _ i n d e x   =   m i n _ i n d e x ; 
 
                         t h i s . _ s i z e _ c o l   =   i _ c o l _ l e n ; 
 
                         t h i s . _ s i z e _ r o w   =   i _ r o w _ l e n ; 
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00s(Wn0ݍ000K000c o l  }k0[Y00r o w  }n0D}T[00{W0~0Y00
 
                   *   c o l k0[W0f0iW0_0r o w  }L0d0K00j0D04XTo00o _ r o w i n d e x n0rS_ }k0- 1 0-[W0~0Y00
 
                   *   S0n0peo0Q0000
NSk0	YfW0~0Y00{_o00ݍ000n0Q000L0_g0Y00
 
                   *   @ p a r a m   o _ r o w i n d e x 
 
                   *   D}T[00SQ0S0MRg0Y00
 
                   *   c o l [ n ] k0[Y00r o w [ m ] n000000juSm 00o _ r o w i n d e x [ n ] k0ԏW0~0Y00
 
                   * / 
 
                 p u b l i c   v o i d   g e t M i n i m u m P a i r ( i n t [ ]   o _ r o w i n d e x ) 
 
                 { 
 
                         D i s t I t e m [ ]   m a p   =   t h i s . _ m a p ; 
 
                         i n t   m a p _ l e n g t h   =   t h i s . _ s i z e _ c o l   *   t h i s . _ s i z e _ r o w ; 
 
                         i n t   c o l _ l e n   =   t h i s . _ s i z e _ c o l ; 
 
                         / / [ 0 ] h0]W0fH0
 
                         D i s t I t e m   t e m p _ m a p ; 
 
                         t e m p _ m a p   =   m a p [ 0 ] ; 
 
                         m a p [ 0 ]   =   m a p [ t h i s . _ m i n _ d i s t _ i n d e x ] ; 
 
                         m a p [ t h i s . _ m i n _ d i s t _ i n d e x ]   =   t e m p _ m a p ; 
 
                         f o r   ( i n t   i   =   0 ;   i   <   o _ r o w i n d e x . L e n g t h ;   i + + ) 
 
                         { 
 
                                 o _ r o w i n d e x [ i ]   =   - 1 ; 
 
                         } 
 
                         i f   ( m a p _ l e n g t h   = =   0 ) 
 
                         { 
 
                                 r e t u r n ; 
 
                         } 
 
                         / / $Pn0O{
 
                         o _ r o w i n d e x [ m a p [ 0 ] . c o l ]   =   m a p [ 0 ] . r o w ; 
 
 
 
                         / / 000W0f000 juvNMn00000cY0
 
                         f o r   ( i n t   i   =   1 ;   i   <   c o l _ l e n ;   i + + ) 
 
                         { 
 
                                 i n t   m i n _ i n d e x   =   0 ; 
 
                                 / / r , c n00n00dYW0j0L00 g\$P0_00
 
                                 i n t   r e j e c t _ c   =   m a p [ i   -   1 ] . c o l ; 
 
                                 i n t   r e j e c t _ r   =   m a p [ i   -   1 ] . r o w ; 
 
                                 i n t   m i n _ d i s t   =   i n t . M a x V a l u e ; 
 
                                 i f   ( 1   > =   m a p _ l e n g t h   -   c o l _ l e n ) 
 
                                 { 
 
                                         b r e a k ; 
 
                                 } 
 
                                 f o r   ( i n t   i 2   =   i ;   i 2   <   m a p _ l e n g t h ;   ) 
 
                                 { 
 
                                         / / dYagN
 
                                         i f   ( m a p [ i 2 ] . c o l   = =   r e j e c t _ c   | |   m a p [ i 2 ] . r o w   = =   r e j e c t _ r ) 
 
                                         { 
 
                                                 / / ^i"}[a!000000n0]W0fH0h00i"}wn0n{
 
                                                 t e m p _ m a p   =   m a p [ i 2 ] ; 
 
                                                 m a p [ i 2 ]   =   m a p [ m a p _ l e n g t h   -   1 ] ; 
 
                                                 m a p [ m a p _ l e n g t h   -   1 ]   =   t e m p _ m a p ; 
 
                                                 m a p _ l e n g t h - - ; 
 
                                         } 
 
                                         e l s e 
 
                                         { 
 
                                                 i n t   d   =   m a p [ i 2 ] . d i s t ; 
 
                                                 i f   ( m i n _ d i s t   >   d ) 
 
                                                 { 
 
                                                         m i n _ i n d e x   =   i 2 ; 
 
                                                         m i n _ d i s t   =   d ; 
 
                                                 } 
 
                                                 i 2 + + ; 
 
                                         } 
 
                                 } 
 
                                 / / [ i ] n0$Pn0]W0fH0
 
                                 t e m p _ m a p   =   m a p [ i ] ; 
 
                                 m a p [ i ]   =   m a p [ m i n _ i n d e x ] ; 
 
                                 m a p [ m i n _ i n d e x ]   =   t e m p _ m a p ; 
 
                                 / / $Pn0O{
 
                                 o _ r o w i n d e x [ m a p [ i ] . c o l ]   =   m a p [ i ] . r o w ; 
 
                         } 
 
                         r e t u r n ; 
 
                 } 
 
         } 
 
 } 