Created
April 15, 2012 18:24
-
-
Save TheBatScripts/2394241 to your computer and use it in GitHub Desktop.
DTM more methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Gets an array of all valid template points inside the given rectangle | |
| * | |
| * @param Rectangle - The sub rectangle of the image to search in. | |
| * | |
| * @return An array of CPoint. | |
| */ | |
| public Point[] getPoints(Rectangle rect) { | |
| return getPoints(rect, false); | |
| } | |
| /** | |
| * Gets an array of all valid template points inside the given rectangle | |
| * | |
| * @param int - The y coord of the rectangle | |
| * @param int - The y coord of the rectangle | |
| * @param int - The width of the rectangle | |
| * @param int - The height of the rectangle | |
| * | |
| * @return An array of CPoint. | |
| */ | |
| public Point[] getPoints(int x, int y, int width, int height) { | |
| return getPoints(new Rectangle(x,y,width,height), false); | |
| } | |
| /** | |
| * Gets an array of all valid template points inside the given rectangle | |
| * | |
| * @param int - The y coord of the rectangle | |
| * @param int - The y coord of the rectangle | |
| * @param int - The width of the rectangle | |
| * @param int - The height of the rectangle | |
| * @param boolean - True - All sub points must be inside of the rectangle | |
| * False - Only the main point needs to be in the given rectangle | |
| * | |
| * @return An array of CPoint. | |
| */ | |
| public Point[] getPoints(int x, int y, int width, int height, boolean inclusive) { | |
| return getPoints(new Rectangle(x,y,width,height), inclusive); | |
| } | |
| /** | |
| * | |
| * @param Rectangle - The sub rectangle of the image to search in. | |
| * @param boolean - True - All sub points must be inside of the rectangle | |
| * False - Only the main point needs to be in the given rectangle | |
| * @return An array of CPoint. | |
| */ | |
| public Point[] getPoints(Rectangle rect, boolean inclusive) { | |
| final ArrayList<Point> ret = new ArrayList<Point>(); | |
| if (points != null && center != null) { | |
| final ArrayList<Point> bases = new ArrayList<Point>(); | |
| final BufferedImage game = Game.getImage(); | |
| // if(rect.x + rect.width > game.getWidth() || rect.y + rect.height > game.getHeight() | |
| // || rect.x < 0 || rect.y < 0) | |
| // throw new IllegalArgumentException("The rectangle bounds are outside of the screen."); | |
| if(rect.x < 0){ | |
| rect.width = rect.width + rect.x; | |
| rect.x = 0; | |
| } | |
| if(rect.x > game.getWidth()){ | |
| rect.x = game.getWidth(); | |
| } | |
| if(rect.x + rect.width > game.getWidth()){ | |
| rect.width = (rect.x + rect.width) - game.getWidth(); | |
| } | |
| if(rect.y < 0){ | |
| rect.height = rect.height + rect.y; | |
| rect.y = 0; | |
| } | |
| if(rect.y > game.getHeight()){ | |
| rect.y = game.getHeight(); | |
| } | |
| if(rect.y + rect.height > game.getHeight()){ | |
| rect.height = (rect.y + rect.height) - game.getHeight(); | |
| } | |
| for (int x = rect.x; x < rect.x + rect.width - 1; x++) { | |
| for (int y = rect.y; y < rect.x + rect.height - 1; y++) { | |
| final Color c = Game.getColorAt(x, y); | |
| if (isTolerable(c.getRed(), center.getColor().getRed(), center.getTolerance()) | |
| && isTolerable(c.getGreen(), center.getColor().getGreen(), center.getTolerance()) | |
| && isTolerable(c.getBlue(), center.getColor().getBlue(), center.getTolerance())) { | |
| bases.add(new Point(x, y)); | |
| } | |
| } | |
| } | |
| bases: for (final Point p : bases) { | |
| for (final DTMPoint cpt : points) { | |
| final int x = p.x + cpt.getX(); | |
| final int y = p.y + cpt.getY(); | |
| if(inclusive && !rect.contains(x,y))continue bases; | |
| final Color c = Game.getColorAt(x, y); | |
| if (!isTolerable(c.getRed(), cpt.getColor().getRed(), cpt.getTolerance()) | |
| || !isTolerable(c.getGreen(), cpt.getColor().getGreen(), cpt.getTolerance()) | |
| || !isTolerable(c.getBlue(), cpt.getColor().getBlue(), cpt.getTolerance())) { | |
| continue bases; | |
| } | |
| } | |
| ret.add(p); | |
| } | |
| } | |
| return ret.toArray(new Point[ret.size()]); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment