e=packs.get (i). get ( j); cVx=middle.x-pt.x; cVy=middle.y-pt.y; cL=sqrt (pow (cVx, 2) + pow (cVy, 2)); s_tmp=((double) pVx / pL) * ((double) cVx / cL) +
((double) pVy / pL) * ((double) cVy / cL); (s_tmp>=s) {= s_tmp;
}
}
/ / <-find the best point
(s> scalar && s> minScal) {= s;=new ArrayList ();. add (packs.get (i));
}
} (! out.isEmpty ()) {= out;
}
} else {d=0; pack=new ArrayList (); (int i=0; i d) {= packs.get (i); p>
}
}. clear ();. add (pack); packs;
} result;
}
6. Реалізація допоміжного алгоритму
private void ordAction (Point in, double ord_angel) {dim=this.getSize (); dx=dim.width / 2 - image.getWidth (null) / 2; dy=dim.height / 2 - image.getHeight (null) / 2; p_tmp=this.toInitCord (p); pt=new Point (p_tmp.x - dx, p_tmp.y - dy); bimage=new BufferedImage (image.getWidth (null),
image.getHeight (null), BufferedImage.TYPE_INT_RGB);
/ / Draw the image on to the buffered imageD g2=bimage.createGraphics ();. drawImage (image, 0, 0, null);. dispose (); defColour=- 1; (isPtInBImg (bimage, pt.x, pt.y)) {= bimage.getRGB (pt.x, pt.y);
}
(defColour == - 1) {;
} radius=1; pair_ordInx_ptInx=new ArrayList (); ord_vectors=new ArrayList (); > packs=new ArrayList > ();
exit=true; (radius > (); content=new ArrayList (); contentwrite=false;
pt_tmp=new Point (pt.x - radius, pt.y - radius); (int i=0; i <= 8 * radius - 1; i + +) {alpha=PI / 2 * (i / (2 * radius));
(isPtInBImg (bimage, pt_tmp.x, pt_tmp.y) && defColour == bimage.getRGB (pt_tmp.x, pt_tmp.y)) {. add (pt_tmp);=true ;
} if (contentwrite) {. add (content);=new ArrayList ();=false;
} _tmp=new Point (pt_tmp.x + (int) cos (alpha), pt_tmp.y + (int) sin (alpha));
}
(contentwrite) {
(! packs.isEmpty () && (packs.get (0). get (0). x == pt.x - radius | |
packs.get (0). get (0). y == pt.y - radius)) {. addAll (0, packs.get (0));. set (0, content );=false;
} else {. add (content);=false;
}
}
(packs.size ()>=2 && packs.size ()!=3) {= false; (int i=0; i <4; i + +) {ord_tmp= new Point (pt.x - (int) (cos (ord_angel * PI/180 + PI / 2 * i) * 10000), pt.y +
(int) (sin (ord_angel * PI/180 + PI / 2 * i) * 10000)); best=0; bestPoint=0; s=- 3; pVx=ord_tmp.x -pt.x; pVy=ord_tmp.y - pt.y; pL=sqrt (pow (pVx, 2) + pow (pVy, 2));
/ / check all points-> (int k=0; k