[934] | 1 | package org.expeditee.items.MagneticConstraint.Utilities;
|
---|
| 2 |
|
---|
| 3 | import java.awt.Rectangle;
|
---|
| 4 | import java.util.Collection;
|
---|
| 5 | import java.util.LinkedList;
|
---|
| 6 | import java.util.List;
|
---|
| 7 |
|
---|
| 8 | import org.expeditee.gui.Frame;
|
---|
| 9 | import org.expeditee.items.Dot;
|
---|
| 10 | import org.expeditee.items.Item;
|
---|
| 11 |
|
---|
| 12 | public class BoxLogic {
|
---|
| 13 | public static List<org.expeditee.items.Line> getVerticalLines(
|
---|
| 14 | final Frame frame) {
|
---|
| 15 | final List<org.expeditee.items.Line> ret = new LinkedList<org.expeditee.items.Line>();
|
---|
| 16 | final Collection<Item> allItems = frame.getAllItems();
|
---|
| 17 | final List<Dot> dots = new LinkedList<Dot>();
|
---|
| 18 | for (final Item canditate : allItems)
|
---|
| 19 | if (canditate instanceof Dot)
|
---|
| 20 | dots.add((Dot) canditate);
|
---|
| 21 | for (final Dot dot : dots) {
|
---|
| 22 | final List<org.expeditee.items.Line> lines = dot.getLines();
|
---|
| 23 | for (final org.expeditee.items.Line vertCanditate : lines) {
|
---|
| 24 | if (!ret.contains(vertCanditate)
|
---|
| 25 | && vertCanditate.getStartItem().getX() == vertCanditate
|
---|
| 26 | .getEndItem().getX())
|
---|
| 27 | ret.add(vertCanditate);
|
---|
| 28 | }
|
---|
| 29 | }
|
---|
| 30 | return ret;
|
---|
| 31 | }
|
---|
[954] | 32 |
|
---|
[934] | 33 | public static boolean boxCollision(final Item item) {
|
---|
[960] | 34 | if(item.getParent() == null) return false;
|
---|
[934] | 35 | final List<org.expeditee.items.Line> verticalLines = BoxLogic
|
---|
| 36 | .getVerticalLines(item.getParent());
|
---|
| 37 | for (final org.expeditee.items.Line canditate : verticalLines) {
|
---|
| 38 | final int topPos = Math.min(canditate.getStartItem().getY(),
|
---|
| 39 | canditate.getEndItem().getY());
|
---|
| 40 | final int bottomPos = Math.max(canditate.getStartItem().getY(),
|
---|
| 41 | canditate.getEndItem().getY());
|
---|
[960] | 42 | final Rectangle itemHitBox = item.getArea().getBounds();
|
---|
| 43 | if (topPos < itemHitBox.getY() && bottomPos > itemHitBox.getY()) {
|
---|
| 44 | if (itemHitBox.getX() + itemHitBox.getWidth() > canditate
|
---|
[934] | 45 | .getStartItem().getX()
|
---|
[960] | 46 | && itemHitBox.getX() < canditate.getStartItem().getX()) {
|
---|
[934] | 47 | return true;
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | return false;
|
---|
| 52 | }
|
---|
[960] | 53 |
|
---|
| 54 | // private static boolean lineShadowsItem(final org.expeditee.items.Line line, final Item item) {
|
---|
| 55 | // final int topPos = Math.min(line.getStartItem().getY(),
|
---|
| 56 | // line.getEndItem().getY());
|
---|
| 57 | // final int bottomPos = Math.max(line.getStartItem().getY(),
|
---|
| 58 | // line.getEndItem().getY());
|
---|
| 59 | // final Rectangle itemHitBox = item.getArea().getBounds();
|
---|
| 60 | // return topPos < itemHitBox.
|
---|
| 61 | // }
|
---|
[934] | 62 |
|
---|
[963] | 63 | // public static void resolveCollision(final Item item, final MagneticConstraintAction remagnet) {
|
---|
| 64 | // boolean updateCursor = FrameUtils.getCurrentItem() == item;
|
---|
| 65 | // final Line currentLine = Line.getLineContainingToken(item);
|
---|
| 66 | // final Paragraph currentParagraph = Paragraph.getParagraphFromLine(currentLine);
|
---|
| 67 | // final Point newLineAt = currentParagraph.split(currentLine);
|
---|
| 68 | // final Line lineFromToken = Line.getLineFromToken(item);
|
---|
| 69 | // lineFromToken.deltaX((int) newLineAt.getX() - lineFromToken.getFirst().getX());
|
---|
| 70 | // lineFromToken.deltaY((int) newLineAt.getY() - lineFromToken.getFirst().getY());
|
---|
| 71 | // remagnet.callback(null);
|
---|
| 72 | // final Line nextLine = lineFromToken.next();
|
---|
| 73 | // if(nextLine != null && nextLine.getBoundingBox().getX() >= lineFromToken.getBoundingBox().getX()) {
|
---|
| 74 | // final Paragraph paragraphFromNewLine = Paragraph.getParagraphFromLine(lineFromToken);
|
---|
| 75 | // final Paragraph paragraphFromNextLine = Paragraph.getParagraphFromLine(nextLine);
|
---|
| 76 | // if(paragraphFromNewLine.containsAll(paragraphFromNextLine)) {
|
---|
| 77 | // final Rectangle newLineBoundingBox = lineFromToken.getBoundingBox();
|
---|
| 78 | // nextLine.setX((int) newLineBoundingBox.getMaxX());
|
---|
| 79 | // nextLine.setY((int) newLineBoundingBox.getY());
|
---|
| 80 | // }
|
---|
| 81 | // }
|
---|
| 82 | // if(updateCursor) DisplayIO.MoveCursorToEndOfItem(item);
|
---|
| 83 | // FrameIO.ForceSaveFrame(item.getParent());
|
---|
| 84 | // }
|
---|
[934] | 85 | }
|
---|