/ *   
 
   *   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 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 ; 
 
 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00 = a * x + b * y + c n0000000<h
}W0~0Y00
 
           *   x , y n0XReTo00x = L !R , y = B !T g0Y00  y L0SW0f0D00n0g0laW0f0O0`0U0D00
 
           * 
 
           * / 
 
         p u b l i c   c l a s s   N y A R L i n e a r 
 
         { 
 
                 / * *   v}_n0Ope  b * / 
 
                 p u b l i c   d o u b l e   b ; 
 
                 / * *   v}_n0Ope  a * / 
 
                 p u b l i c   d o u b l e   a ; 
 
                 / * *   v}_n0Ope  c * / 
 
                 p u b l i c   d o u b l e   c ; 
 
 
 
                 / * * 
 
                   *   S0n0peo00c[000n0000000MR0\O0~0Y00
 
                   *   @ p a r a m   i _ n u m b e r 
 
                   *   \ObY00MRn0wU0
 
                   *   @ r e t u r n 
 
                   *   eW0D0MR0
 
                   * / 
 
                 p u b l i c   s t a t i c   N y A R L i n e a r [ ]   c r e a t e A r r a y ( i n t   i _ n u m b e r ) 
 
                 { 
 
                         N y A R L i n e a r [ ]   r e t   =   n e w   N y A R L i n e a r [ i _ n u m b e r ] ; 
 
                         f o r   ( i n t   i   =   0 ;   i   <   i _ n u m b e r ;   i + + ) 
 
                         { 
 
                                 r e t [ i ]   =   n e w   N y A R L i n e a r ( ) ; 
 
                         } 
 
                         r e t u r n   r e t ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00_pe$PK00000000000000x0000W0~0Y00
 
                   *   @ p a r a m   i _ s o u r c e 
 
                   *   000CQn0000000
 
                   * / 
 
                 p u b l i c   v o i d   c o p y F r o m ( N y A R L i n e a r   i _ s o u r c e ) 
 
                 { 
 
                         t h i s . b   =   i _ s o u r c e . b ; 
 
                         t h i s . a   =   i _ s o u r c e . a ; 
 
                         t h i s . c   =   i _ s o u r c e . c ; 
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00v}n0Np0{W0~0Y00
 
                   *   @ p a r a m   l _ l i n e _ 2 
 
                   *   Np0{Y00v}_
 
                   *   @ p a r a m   o _ p o i n t 
 
                   *   Np^j0<h
}Y00000000
 
                   *   @ r e t u r n 
 
                   *   NpL0Bl~00p0t r u e 
 
                   * / 
 
                 p u b l i c   b o o l   c r o s s P o s ( N y A R L i n e a r   l _ l i n e _ 2 ,   N y A R D o u b l e P o i n t 2 d   o _ p o i n t ) 
 
                 { 
 
                         d o u b l e   w 1   =   t h i s . a   *   l _ l i n e _ 2 . b   -   l _ l i n e _ 2 . a   *   t h i s . b ; 
 
                         i f   ( w 1   = =   0 . 0 ) 
 
                         { 
 
                                 r e t u r n   f a l s e ; 
 
                         } 
 
                         o _ p o i n t . x   =   ( t h i s . b   *   l _ l i n e _ 2 . c   -   l _ l i n e _ 2 . b   *   t h i s . c )   /   w 1 ; 
 
                         o _ p o i n t . y   =   ( l _ l i n e _ 2 . a   *   t h i s . c   -   t h i s . a   *   l _ l i n e _ 2 . c )   /   w 1 ; 
 
                         r e t u r n   t r u e ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00v}n0Np0{W0~0Y00
 
                   *   @ p a r a m   i _ a 
 
                   *   Np0Bl00v}_n0Opea 
 
                   *   @ p a r a m   i _ b 
 
                   *   Np0Bl00v}_n0Opeb 
 
                   *   @ p a r a m   i _ c 
 
                   *   Np0Bl00v}_n0Opec 
 
                   *   @ p a r a m   o _ p o i n t 
 
                   *   Np^j0<h
}Y00000000
 
                   *   @ r e t u r n 
 
                   *   NpL0Bl~00p0t r u e 
 
                   * / 
 
                 p u b l i c   b o o l   c r o s s P o s ( d o u b l e   i _ a ,   d o u b l e   i _ b ,   d o u b l e   i _ c ,   N y A R D o u b l e P o i n t 2 d   o _ p o i n t ) 
 
                 { 
 
                         d o u b l e   w 1   =   t h i s . a   *   i _ b   -   i _ a   *   t h i s . b ; 
 
                         i f   ( w 1   = =   0 . 0 ) 
 
                         { 
 
                                 r e t u r n   f a l s e ; 
 
                         } 
 
                         o _ p o i n t . x   =   ( t h i s . b   *   i _ c   -   i _ b   *   t h i s . c )   /   w 1 ; 
 
                         o _ p o i n t . y   =   ( i _ a   *   t h i s . c   -   t h i s . a   *   i _ c )   /   w 1 ; 
 
                         r e t u r n   t r u e ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00v}n0Np0{W0~0Y00
 
                   *   @ p a r a m   i _ a 
 
                   *   Np0Bl00v}_n0Opea 
 
                   *   @ p a r a m   i _ b 
 
                   *   Np0Bl00v}_n0Opeb 
 
                   *   @ p a r a m   i _ c 
 
                   *   Np0Bl00v}_n0Opec 
 
                   *   @ p a r a m   o _ p o i n t 
 
                   *   Np^j0<h
}Y00000000
 
                   *   @ r e t u r n 
 
                   *   NpL0Bl~00p0t r u e 
 
                   * / 
 
                 p u b l i c   b o o l   c r o s s P o s ( d o u b l e   i _ a ,   d o u b l e   i _ b ,   d o u b l e   i _ c ,   N y A R I n t P o i n t 2 d   o _ p o i n t ) 
 
                 { 
 
                         d o u b l e   w 1   =   t h i s . a   *   i _ b   -   i _ a   *   t h i s . b ; 
 
                         i f   ( w 1   = =   0 . 0 ) 
 
                         { 
 
                                 r e t u r n   f a l s e ; 
 
                         } 
 
                         o _ p o i n t . x   =   ( i n t ) ( ( t h i s . b   *   i _ c   -   i _ b   *   t h i s . c )   /   w 1 ) ; 
 
                         o _ p o i n t . y   =   ( i n t ) ( ( i _ a   *   t h i s . c   -   t h i s . a   *   i _ c )   /   w 1 ) ; 
 
                         r e t u r n   t r u e ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo002 v}L0N]W0f0D00K00ԏW0~0Y00
 
                   *   @ p a r a m   l _ l i n e _ 2 
 
                   *   N]W0f0D00K0xY00000000
 
                   *   @ r e t u r n 
 
                   *   N]W0f0D00p0t r u e 
 
                   * / 
 
                 p u b l i c   b o o l   i s C r o s s ( N y A R L i n e a r   l _ l i n e _ 2 ) 
 
                 { 
 
                         d o u b l e   w 1   =   t h i s . a   *   l _ l i n e _ 2 . b   -   l _ l i n e _ 2 . a   *   t h i s . b ; 
 
                         r e t u r n   ( w 1   = =   0 . 0 )   ?   f a l s e   :   t r u e ; 
 
                 } 
 
 
 
                 / * * 
 
                   *   S0n0peo002 p0P}v0v}_0{W0f00000000k0<h
}W0~0Y00
 
                   *   _n0Ope$Po00ckSU00~0Y00
 
                   *   @ p a r a m   i _ p o i n t 1 
 
                   *   p
 
                   *   @ p a r a m   i _ p o i n t 2 
 
                   *   p
 
                   *   @ r e t u r n 
 
                   *   v}_L0Bl~00p00t r u e 
 
                   * / 
 
                 p u b l i c   b o o l   m a k e L i n e a r W i t h N o r m a l i z e ( N y A R I n t P o i n t 2 d   i _ p o i n t 1 ,   N y A R I n t P o i n t 2 d   i _ p o i n t 2 ) 
 
                 { 
 
                         r e t u r n   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 i n t 1 . x ,   i _ p o i n t 1 . y ,   i _ p o i n t 2 . x ,   i _ p o i n t 2 . y ) ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo002 p0P}v0v}_0{W0f00000000k0<h
}W0~0Y00
 
                   *   _n0Ope$Po00ckSU00~0Y00
 
                   *   @ p a r a m   i _ p o i n t 1 
 
                   *   p
 
                   *   @ p a r a m   i _ p o i n t 2 
 
                   *   p
 
                   *   @ r e t u r n 
 
                   *   v}_L0Bl0h0t r u e 0ԏW0~0Y00
 
                   * / 
 
                 p u b l i c   b o o l   m a k e L i n e a r W i t h N o r m a l i z e ( N y A R D o u b l e P o i n t 2 d   i _ p o i n t 1 ,   N y A R D o u b l e P o i n t 2 d   i _ p o i n t 2 ) 
 
                 { 
 
                         r e t u r n   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 i n t 1 . x ,   i _ p o i n t 1 . y ,   i _ p o i n t 2 . x ,   i _ p o i n t 2 . y ) ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo002 p0P}v0v}_0{W0f00000000k0<h
}W0~0Y00
 
                   *   _n0Ope$Po00ckSU00~0Y00
 
                   *   @ p a r a m   x 1 
 
                   *   p1 n0^j( X ) 
 
                   *   @ p a r a m   y 1 
 
                   *   p1 n0^j( Y ) 
 
                   *   @ p a r a m   x 2 
 
                   *   p2 n0^j( X ) 
 
                   *   @ p a r a m   y 2 
 
                   *   p2 n0^j( Y ) 
 
                   *   @ r e t u r n 
 
                   *   v}_L0Bl0h0t r u e 0ԏW0~0Y00
 
                   * / 
 
                 p u b l i c   b o o l   m a k e L i n e a r W i t h N o r m a l i z e ( d o u b l e   x 1 ,   d o u b l e   y 1 ,   d o u b l e   x 2 ,   d o u b l e   y 2 ) 
 
                 { 
 
                         d o u b l e   d x   =   y 2   -   y 1 ; 
 
                         d o u b l e   d y   =   x 1   -   x 2 ; 
 
                         d o u b l e   s q   =   M a t h . S q r t ( d x   *   d x   +   d y   *   d y ) ; 
 
                         i f   ( s q   = =   0 ) 
 
                         { 
 
                                 r e t u r n   f a l s e ; 
 
                         } 
 
                         s q   =   1   /   s q ; 
 
                         t h i s . a   =   d x   *   s q ; 
 
                         t h i s . b   =   d y   *   s q ; 
 
                         t h i s . c   =   ( x 1   *   ( y 1   -   y 2 )   +   y 1   *   ( x 2   -   x 1 ) )   *   s q ; 
 
                         r e t u r n   t r u e ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00PM0h0NpK00v}_0{W0f00000000x0000W0~0Y00
 
                   *   @ p a r a m   i _ d x 
 
                   *   X n0PM0
 
                   *   @ p a r a m   i _ d y 
 
                   *   Y n0PM0
 
                   *   @ p a r a m   i _ x 
 
                   *   Npn0^jX 
 
                   *   @ p a r a m   i _ y 
 
                   *   Npn0^jY 
 
                   * / 
 
                 p u b l i c   v o i d   s e t V e c t o r ( d o u b l e   i _ d x ,   d o u b l e   i _ d y ,   d o u b l e   i _ x ,   d o u b l e   i _ y ) 
 
                 { 
 
                         t h i s . a   =   i _ d y ; 
 
                         t h i s . b   =   - i _ d x ; 
 
                         t h i s . c   =   ( i _ d x   *   i _ y   -   i _ d y   *   i _ x ) ; 
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00{ @ l i n k   N y A R V e c L i n e a r 2 d } 0v}_k0	YcW0f00000000x0000W0~0Y00
 
                   *   @ p a r a m   i _ v e c t o r 
 
                   *   000Y00000000
 
                   * / 
 
                 p u b l i c   v o i d   s e t V e c t o r ( N y A R V e c L i n e a r 2 d   i _ v e c t o r ) 
 
                 { 
 
                         t h i s . a   =   i _ v e c t o r . d y ; 
 
                         t h i s . b   =   - i _ v e c t o r . d x ; 
 
                         t h i s . c   =   ( i _ v e c t o r . d x   *   i _ v e c t o r . y   -   i _ v e c t o r . d y   *   i _ v e c t o r . x ) ; 
 
                         r e t u r n ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00{ @ l i n k   N y A R V e c L i n e a r 2 d } 0ckSU00_0v}_k0	YcW0f00000000x0000W0~0Y00
 
                   *   @ p a r a m   i _ v e c t o r 
 
                   *   000Y00000000
 
                   * / 
 
                 p u b l i c   b o o l   s e t V e c t o r W i t h N o r m a l i z e ( N y A R V e c L i n e a r 2 d   i _ v e c t o r ) 
 
                 { 
 
                         d o u b l e   d x   =   i _ v e c t o r . d x ; 
 
                         d o u b l e   d y   =   i _ v e c t o r . d y ; 
 
                         d o u b l e   s q   =   M a t h . S q r t ( d x   *   d x   +   d y   *   d y ) ; 
 
                         i f   ( s q   = =   0 ) 
 
                         { 
 
                                 r e t u r n   f a l s e ; 
 
                         } 
 
                         s q   =   1   /   s q ; 
 
                         t h i s . a   =   d y   *   s q ; 
 
                         t h i s . b   =   - d x   *   s q ; 
 
                         t h i s . c   =   - ( t h i s . a   *   i _ v e c t o r . x   +   t h i s . b   *   i _ v e c t o r . y ) ; 
 
                         r e t u r n   t r u e ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00i _ x , i _ y 0NY000i _ l i n e a r n0l}0{W0f00000000x0<h
}W0~0Y00
 
                   *   @ p a r a m   i _ x 
 
                   *   NpX 
 
                   *   @ p a r a m   i _ y 
 
                   *   NpY 
 
                   *   @ p a r a m   i _ l i n e a r 
 
                   *   l}0{Y00v}_( S0n0_pek0o0t h i s 0c[g0M0~0Y00) 
 
                   * / 
 
                 p u b l i c   v o i d   n o r m a l L i n e ( d o u b l e   i _ x ,   d o u b l e   i _ y ,   N y A R L i n e a r   i _ l i n e a r ) 
 
                 { 
 
                         d o u b l e   l a   =   i _ l i n e a r . a ; 
 
                         d o u b l e   l b   =   i _ l i n e a r . b ; 
 
                         t h i s . a   =   l b ; 
 
                         t h i s . b   =   - l a ; 
 
                         t h i s . c   =   - ( l b   *   i _ x   -   l a   *   i _ y ) ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00i _ x , i _ y 00S0n0v}n0l}h00i _ l i n e a r L0N00p0ԏW0~0Y00
 
                   *   @ p a r a m   i _ x 
 
                   *   l}L0NY00pX 
 
                   *   @ p a r a m   i _ y 
 
                   *   l}L0NY00pY 
 
                   *   @ p a r a m   i _ l i n e a r 
 
                   *   Np0{Y00v}_
 
                   *   @ p a r a m   o _ p o i n t 
 
                   *   Np0ԏtSY00000000
 
                   *   @ r e t u r n 
 
                   *   NpL0Bl~00p00t r u e 0ԏW0~0Y00
 
                   * / 
 
                 p u b l i c   b o o l   n o r m a l L i n e C r o s s P o s ( d o u b l e   i _ x ,   d o u b l e   i _ y ,   N y A R L i n e a r   i _ l i n e a r ,   N y A R D o u b l e P o i n t 2 d   o _ p o i n t ) 
 
                 { 
 
                         / / t h i s 0l}k0	Yc
 
                         d o u b l e   l a   =   t h i s . b ; 
 
                         d o u b l e   l b   =   - t h i s . a ; 
 
                         d o u b l e   l c   =   - ( l a   *   i _ x   +   l b   *   i _ y ) ; 
 
                         / / Np0{
 
                         d o u b l e   w 1   =   i _ l i n e a r . a   *   l b   -   l a   *   i _ l i n e a r . b ; 
 
                         i f   ( w 1   = =   0 . 0 ) 
 
                         { 
 
                                 r e t u r n   f a l s e ; 
 
                         } 
 
                         o _ p o i n t . x   =   ( ( i _ l i n e a r . b   *   l c   -   l b   *   i _ l i n e a r . c )   /   w 1 ) ; 
 
                         o _ p o i n t . y   =   ( ( l a   *   i _ l i n e a r . c   -   i _ l i n e a r . a   *   l c )   /   w 1 ) ; 
 
                         r e t u r n   t r u e ; 
 
                 } 
 
                 / / 	 / * * 
 
                 / / 	   *   i _ x , i _ y 00S0n0v}n0l}
Ng0n00S0n0v}h0i _ l i n e a r n0ݍn0NWN$P0ԏW0~0Y00
 
                 / / 	   *   i _ x , i _ y k0v}
Nn0p0c[Y00h00S0n0v}n0W}
Ng0n000F0 Nen0v}h0n0ݍn0NWN$PL0_00~0Y00
 
                 / / 	   *   @ p a r a m   i _ l i n e a r 
 
                 / / 	   *   @ p a r a m   i _ x 
 
                 / / 	   *   @ p a r a m   i _ y 
 
                 / / 	   *   @ p a r a m   o _ p o i n t 
 
                 / / 	   *   @ r e t u r n 
 
                 / / 	   *   NpL0!qD04XT0!qP'Y0ԏW0~0Y00
 
                 / / 	   * / 
 
                 / / 	 p u b l i c   c o n s t   d o u b l e   s q D i s t W i t h L i n e a r ( N y A R L i n e a r   i _ l i n e a r ,   d o u b l e   i _ x , d o u b l e   i _ y ) 
 
                 / / 	 { 
 
                 / / 	 	 / / t h i s 0l}k0	Yc
 
                 / / 	 	 d o u b l e   l a = t h i s . b ; 
 
                 / / 	 	 d o u b l e   l b = - t h i s . a ; 
 
                 / / 	 	 d o u b l e   l c = - ( l a * i _ x + l b * i _ y ) ; 
 
                 / / 	 	 / / Np0{
 
                 / / 	 	 c o n s t   d o u b l e   w 1   =   i _ l i n e a r . a   *   l b   -   l a   *   i _ l i n e a r . b ; 
 
                 / / 	 	 i f   ( w 1   = =   0 . 0 )   { 
 
                 / / 	 	 	 r e t u r n   D o u b l e . P O S I T I V E _ I N F I N I T Y ; 
 
                 / / 	 	 } 
 
                 / / 	 	 d o u b l e   x = i _ x - ( ( i _ l i n e a r . b   *   l c   -   l b   *   i _ l i n e a r . c )   /   w 1 ) ; 
 
                 / / 	 	 d o u b l e   y = i _ y - ( ( l a   *   i _ l i n e a r . c   -   i _ l i n e a r . a   *   l c )   /   w 1 ) ; 
 
                 / / 	 	 r e t u r n   x * x + y * y ; 
 
                 / / 	 } 
 
 
 
                 / * * 
 
                   *   S0n0peo00v}00 , 0 Wp( ]
N) n0wb_g0000000W0_0h0M0n00zp0{W0~0Y00
 
                   *   @ p a r a m   i _ w i d t h 
 
                   *   wb_n0E^
 
                   *   @ p a r a m   i _ h e i g h t 
 
                   *   wb_n0ؚU0
 
                   *   @ p a r a m   o _ p o i n t 
 
                   *   zp0ԏY0000000MR02  }g0B00_L0B00~0Y00
 
                   *   @ r e t u r n 
 
                   *   zpL0Bl~00p0t r u e 
 
                   * / 
 
                 p u b l i c   b o o l   m a k e S e g m e n t L i n e ( i n t   i _ w i d t h ,   i n t   i _ h e i g h t ,   N y A R I n t P o i n t 2 d [ ]   o _ p o i n t ) 
 
                 { 
 
                         i n t   i d x   =   0 ; 
 
                         N y A R I n t P o i n t 2 d   p t r   =   o _ p o i n t [ 0 ] ; 
 
                         i f   ( t h i s . c r o s s P o s ( 0 ,   - 1 ,   0 ,   p t r )   & &   p t r . x   > =   0   & &   p t r . x   <   i _ w i d t h ) 
 
                         { 
 
                                 / / y = r e c t . y n0}
 
                                 i d x + + ; 
 
                                 p t r   =   o _ p o i n t [ i d x ] ; 
 
                         } 
 
                         i f   ( t h i s . c r o s s P o s ( 0 ,   - 1 ,   i _ h e i g h t   -   1 ,   p t r )   & &   p t r . x   > =   0   & &   p t r . x   <   i _ w i d t h ) 
 
                         { 
 
                                 / / y = ( r e c t . y + r e c t . h - 1 ) n0}
 
                                 i d x + + ; 
 
                                 i f   ( i d x   = =   2 ) 
 
                                 { 
 
                                         r e t u r n   t r u e ; 
 
                                 } 
 
                                 p t r   =   o _ p o i n t [ i d x ] ; 
 
                         } 
 
                         i f   ( t h i s . c r o s s P o s ( - 1 ,   0 ,   0 ,   p t r )   & &   p t r . y   > =   0   & &   p t r . y   <   i _ h e i g h t ) 
 
                         { 
 
                                 / / x = i _ l e f t n0}
 
                                 i d x + + ; 
 
                                 i f   ( i d x   = =   2 ) 
 
                                 { 
 
                                         r e t u r n   t r u e ; 
 
                                 } 
 
                                 p t r   =   o _ p o i n t [ i d x ] ; 
 
                         } 
 
                         i f   ( t h i s . c r o s s P o s ( - 1 ,   0 ,   i _ w i d t h   -   1 ,   p t r )   & &   p t r . y   > =   0   & &   p t r . y   <   i _ h e i g h t ) 
 
                         { 
 
                                 / / x = i _ r i g h t - 1 n0}
 
                                 i d x + + ; 
 
                                 i f   ( i d x   = =   2 ) 
 
                                 { 
 
                                         r e t u r n   t r u e ; 
 
                                 } 
 
                         } 
 
                         r e t u r n   f a l s e ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00v}0wb_g0000000W0_0h0M0n00zp0{W0~0Y00
 
                   *   @ p a r a m   i _ l e f t 
 
                   *   wb_n0]
N^j( X ) 
 
                   *   @ p a r a m   i _ t o p 
 
                   *   wb_n0]
N^j( Y ) 
 
                   *   @ p a r a m   i _ w i d t h 
 
                   *   wb_n0E^
 
                   *   @ p a r a m   i _ h e i g h t 
 
                   *   wb_n0ؚU0
 
                   *   @ p a r a m   o _ p o i n t 
 
                   *   zp0ԏY0000000MR02  }g0B00_L0B00~0Y00
 
                   *   @ r e t u r n 
 
                   *   zpL0Bl~00p0t r u e 
 
                   * / 
 
                 p u b l i c   b o o l   m a k e S e g m e n t L i n e ( i n t   i _ l e f t ,   i n t   i _ t o p ,   i n t   i _ w i d t h ,   i n t   i _ h e i g h t ,   N y A R I n t P o i n t 2 d [ ]   o _ p o i n t ) 
 
                 { 
 
                         i n t   b o t t o m   =   i _ t o p   +   i _ h e i g h t ; 
 
                         i n t   r i g h t   =   i _ l e f t   +   i _ w i d t h ; 
 
                         i n t   i d x   =   0 ; 
 
                         N y A R I n t P o i n t 2 d   p t r   =   o _ p o i n t [ 0 ] ; 
 
                         i f   ( t h i s . c r o s s P o s ( 0 ,   - 1 ,   i _ t o p ,   p t r )   & &   p t r . x   > =   i _ l e f t   & &   p t r . x   <   r i g h t ) 
 
                         { 
 
                                 / / y = r e c t . y n0}
 
                                 i d x + + ; 
 
                                 p t r   =   o _ p o i n t [ i d x ] ; 
 
                         } 
 
                         i f   ( t h i s . c r o s s P o s ( 0 ,   - 1 ,   b o t t o m   -   1 ,   p t r )   & &   p t r . x   > =   i _ l e f t   & &   p t r . x   <   r i g h t ) 
 
                         { 
 
                                 / / y = ( r e c t . y + r e c t . h - 1 ) n0}
 
                                 i d x + + ; 
 
                                 i f   ( i d x   = =   2 ) 
 
                                 { 
 
                                         r e t u r n   t r u e ; 
 
                                 } 
 
                                 p t r   =   o _ p o i n t [ i d x ] ; 
 
                         } 
 
                         i f   ( t h i s . c r o s s P o s ( - 1 ,   0 ,   i _ l e f t ,   p t r )   & &   p t r . y   > =   i _ t o p   & &   p t r . y   <   b o t t o m ) 
 
                         { 
 
                                 / / x = i _ l e f t n0}
 
                                 i d x + + ; 
 
                                 i f   ( i d x   = =   2 ) 
 
                                 { 
 
                                         r e t u r n   t r u e ; 
 
                                 } 
 
                                 p t r   =   o _ p o i n t [ i d x ] ; 
 
                         } 
 
                         i f   ( t h i s . c r o s s P o s ( - 1 ,   0 ,   r i g h t   -   1 ,   p t r )   & &   p t r . y   > =   i _ t o p   & &   p t r . y   <   b o t t o m ) 
 
                         { 
 
                                 / / x = i _ r i g h t - 1 n0}
 
                                 i d x + + ; 
 
                                 i f   ( i d x   = =   2 ) 
 
                                 { 
 
                                         r e t u r n   t r u e ; 
 
                                 } 
 
                         } 
 
                         r e t u r n   f a l s e ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00S0n0v}h00i _ s p 1 h0i _ s p 2 n0\O0}Rh0n00NWNݍ$Pn0T0ԏW0~0Y00
 
                   *   {elo00}Rn0zp0NY00v}n0l}
Ng0n00zph0v}n0ݍn0Tg0Y00
 
                   *   }Rh0v}n0^<O^0$R[Y00pe$Pk0j00~0Y00
 
                   *   @ p a r a m   i _ s p 1 
 
                   *   }Rn0zp1 
 
                   *   @ p a r a m   i _ s p 2 
 
                   *   }Rn0zp2 
 
                   *   @ r e t u r n 
 
                   *   NWNݍ$Pn0T0ݍL0S0j0D0h0M0o0!qP'Yg0Y00
 
                   * / 
 
                 p u b l i c   d o u b l e   s q D i s t B y S e g m e n t L i n e E d g e ( N y A R D o u b l e P o i n t 2 d   i _ s p 1 ,   N y A R D o u b l e P o i n t 2 d   i _ s p 2 ) 
 
                 { 
 
                         d o u b l e   l a ,   l b ,   l c ; 
 
                         d o u b l e   x ,   y ,   w 1 ; 
 
                         / / t h i s 0l}k0	Yc
 
                         l a   =   t h i s . b ; 
 
                         l b   =   - t h i s . a ; 
 
 
 
                         / / Np0{
 
                         w 1   =   t h i s . a   *   l b   -   l a   *   t h i s . b ; 
 
                         i f   ( w 1   = =   0 . 0 ) 
 
                         { 
 
                                 r e t u r n   D o u b l e . P o s i t i v e I n f i n i t y ; 
 
                         } 
 
                         / / i _ s p 1 h00i _ l i n e r n0Np
 
                         l c   =   - ( l a   *   i _ s p 1 . x   +   l b   *   i _ s p 1 . y ) ; 
 
                         x   =   ( ( t h i s . b   *   l c   -   l b   *   t h i s . c )   /   w 1 )   -   i _ s p 1 . x ; 
 
                         y   =   ( ( l a   *   t h i s . c   -   t h i s . a   *   l c )   /   w 1 )   -   i _ s p 1 . y ; 
 
                         d o u b l e   s q d i s t   =   x   *   x   +   y   *   y ; 
 
 
 
                         l c   =   - ( l a   *   i _ s p 2 . x   +   l b   *   i _ s p 2 . y ) ; 
 
                         x   =   ( ( t h i s . b   *   l c   -   l b   *   t h i s . c )   /   w 1 )   -   i _ s p 2 . x ; 
 
                         y   =   ( ( l a   *   t h i s . c   -   t h i s . a   *   l c )   /   w 1 )   -   i _ s p 2 . y ; 
 
 
 
                         r e t u r n   s q d i s t   +   x   *   x   +   y   *   y ; 
 
                 } 
 
                 / * * 
 
                   *   S0n0peo00pK00 g\NWNl0O(uW0f0v}0{W0~0Y00
 
                   *   @ p a r a m   i _ p o i n t s 
 
                   *   p0<h
}W0_0MR0
 
                   *   @ p a r a m   i _ n u m b e r _ o f _ d a t a 
 
                   *   {[an0pn0pe
 
                   *   @ r e t u r n 
 
                   *   {k0bRY00h00t r u e 0ԏW0~0Y00
 
                   * / 
 
                 p u b l i c   b o o l   l e a s t S q u a r e s ( N y A R D o u b l e P o i n t 2 d [ ]   i _ p o i n t s ,   i n t   i _ n u m b e r _ o f _ d a t a ) 
 
                 { 
 
                         D e b u g . A s s e r t ( i _ n u m b e r _ o f _ d a t a   >   1 ) ; 
 
                         i n t   i ; 
 
                         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   =   0 ;   i   <   i _ n u m b e r _ o f _ d a t a ;   i + + ) 
 
                         { 
 
                                 N y A R D o u b l e P o i n t 2 d   p t r   =   i _ p o i n t s [ i ] ; 
 
                                 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 ; 
 
                         } 
 
                         t h i s . b   =   - ( i _ n u m b e r _ o f _ d a t a   *   s u m _ x 2   -   s u m _ x   *   s u m _ x ) ; 
 
                         t h i s . a   =   ( i _ n u m b e r _ o f _ d a t a   *   s u m _ x y   -   s u m _ x   *   s u m _ y ) ; 
 
                         t h i s . c   =   ( s u m _ x 2   *   s u m _ y   -   s u m _ x y   *   s u m _ x ) ; 
 
                         r e t u r n   t r u e ; 
 
                 } 
 
         } 
 
 } 
 
 