/ *   
 
   *   P R O J E C T :   N y A R T o o l k i t C S 
 
   *   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
   *   T h i s   w o r k   i s   b a s e d   o n   t h e   o r i g i n a l   A R T o o l K i t   d e v e l o p e d   b y 
 
   *       H i r o k a z u   K a t o 
 
   *       M a r k   B i l l i n g h u r s t 
 
   *       H I T L a b ,   U n i v e r s i t y   o f   W a s h i n g t o n ,   S e a t t l e 
 
   *   h t t p : / / w w w . h i t l . w a s h i n g t o n . e d u / a r t o o l k i t / 
 
   * 
 
   *   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 1 0   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 > 
 
   *   
 
   * / 
 
 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0tepeWn0!kCQ*}0<h
}W0~0Y00
 
           *   *}o00!kCQ^j{ @ l i n k   N y A R I n t P o i n t 2 d } n0ƖTg0Y00
 
           * / 
 
         p u b l i c   c l a s s   N y A R I n t C o o r d i n a t e s 
 
         { 
 
                 / * *   p0<h
}Y00MRg0Y00* / 
 
                 p u b l i c   N y A R I n t P o i n t 2 d [ ]   i t e m s ; 
 
                 / * *   	gRj0 }n0wU0g0Y00* / 
 
                 p u b l i c   i n t   l e n g t h ; 
 
                 / * * 
 
                   *   0000000g0Y00
 
                   *    g'YwU00c[W0f00	gR }pe0 n00000000\O0~0Y00
 
                   *   @ p a r a m   i _ l e n g t h 
 
                   *   *n0 g'Yw
 
                   * / 
 
                 p u b l i c   N y A R I n t 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 . i t e m s   =   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 ( i _ l e n g t h ) ; 
 
                         t h i s . l e n g t h   =   0 ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo0p0P}v0v}0{W0f00*}0OX[W0~0Y00
 
                   *   *}o00B r e s e n h a m n0000000g0{W0~0Y00
 
                   *   pn0ݍL00<h
}Sj0 g'YwU0NNk0j000F0k0laW0f0O0`0U0D00
 
                   *   @ p a r a m   i _ x 0 
 
                   *   p1 n0X ^j
 
                   *   @ p a r a m   i _ y 0 
 
                   *   p1 n0Y ^j
 
                   *   @ p a r a m   i _ x 1 
 
                   *   p2 n0X ^j
 
                   *   @ p a r a m   i _ y 1 
 
                   *   p2 n0Y ^j
 
                   *   @ r e t u r n 
 
                   *   bRY00h0t r u e 0ԏW0~0Y00
 
                   * / 
 
                 p u b l i c   b o o l   s e t L i n e C o o r d i n a t e s ( i n t   i _ x 0 ,   i n t   i _ y 0 ,   i n t   i _ x 1 ,   i n t   i _ y 1 ) 
 
                 { 
 
                         N y A R I n t P o i n t 2 d [ ]   p t r   =   t h i s . i t e m s ; 
 
                         / /   }R0[
 
                         i n t   d x   =   ( i _ x 1   >   i _ x 0 )   ?   i _ x 1   -   i _ x 0   :   i _ x 0   -   i _ x 1 ; 
 
                         i n t   d y   =   ( i _ y 1   >   i _ y 0 )   ?   i _ y 1   -   i _ y 0   :   i _ y 0   -   i _ y 1 ; 
 
                         i n t   s x   =   ( i _ x 1   >   i _ x 0 )   ?   1   :   - 1 ; 
 
                         i n t   s y   =   ( i _ y 1   >   i _ y 0 )   ?   1   :   - 1 ; 
 
 
 
                         / /   B r e s e n h a m 
 
                         i n t   i d x   =   0 ; 
 
                         i f   ( d x   > =   d y ) 
 
                         { 
 
                                 / /   PM0L01 NNn04XT
 
                                 i f   ( d x   > =   p t r . L e n g t h ) 
 
                                 { 
 
                                         r e t u r n   f a l s e ; 
 
                                 } 
 
                                 i n t   E   =   - d x ; 
 
                                 f o r   ( i n t   i   =   0 ;   i   < =   d x ;   i + + ) 
 
                                 { 
 
                                         p t r [ i d x ] . x   =   i _ x 0 ; 
 
                                         p t r [ i d x ] . y   =   i _ y 0 ; 
 
                                         i d x + + ; 
 
                                         i _ x 0   + =   s x ; 
 
                                         E   + =   2   *   d y ; 
 
                                         i f   ( E   > =   0 ) 
 
                                         { 
 
                                                 i _ y 0   + =   s y ; 
 
                                                 E   - =   2   *   d x ; 
 
                                         } 
 
                                 } 
 
                         } 
 
                         e l s e 
 
                         { 
 
                                 / /   PM0L01 00'YM0D04XT
 
                                 i f   ( d y   > =   t h i s . i t e m s . L e n g t h ) 
 
                                 { 
 
                                         r e t u r n   f a l s e ; 
 
                                 } 
 
                                 i n t   E   =   - d y ; 
 
                                 f o r   ( i n t   i   =   0 ;   i   < =   d y ;   i + + ) 
 
                                 { 
 
                                         p t r [ i d x ] . x   =   i _ x 0 ; 
 
                                         p t r [ i d x ] . y   =   i _ y 0 ; 
 
                                         i d x + + ; 
 
                                         i _ y 0   + =   s y ; 
 
                                         E   + =   2   *   d x ; 
 
                                         i f   ( E   > =   0 ) 
 
                                         { 
 
                                                 i _ x 0   + =   s x ; 
 
                                                 E   - =   2   *   d y ; 
 
                                         } 
 
                                 } 
 
                         } 
 
                         t h i s . l e n g t h   =   i d x ; 
 
                         r e t u r n   t r u e ; 
 
                 } 
 
         } 
 
 } 