- Timestamp:
- 05/10/18 16:04:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/MagneticConstraint/Utilities/Paragraph.java
r962 r1102 1 1 package org.expeditee.items.MagneticConstraint.Utilities; 2 2 3 import java.awt.*;4 3 import java.util.LinkedList; 4 5 import org.expeditee.core.Point; 6 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 5 7 import org.expeditee.items.Text; 6 8 … … 30 32 } 31 33 32 public Rectangle getBoundingBox() { 33 final Rectangle rect = new Rectangle(); 34 for(final Line ln : this) rect.add(ln.getBoundingBox()); 34 public AxisAlignedBoxBounds getBoundingBox() { 35 AxisAlignedBoxBounds rect = null; 36 for(final Line ln : this) { 37 if (rect == null) rect = ln.getBoundingBox(); 38 else rect.combineWith(ln.getBoundingBox()); 39 } 35 40 return rect; 36 41 } … … 50 55 if(nextLine == null) { 51 56 //2a. No; then we simply need to calculate the position of where it would be and return that. 52 final RectangleboundingBox = splitAt.getBoundingBox();53 return new Point((int)boundingBox.get X(), (int)boundingBox.getMaxY() + lineHeight);57 final AxisAlignedBoxBounds boundingBox = splitAt.getBoundingBox(); 58 return new Point((int)boundingBox.getMinX(), (int)boundingBox.getMaxY() + lineHeight); 54 59 } 55 60 //3. Get paragraph starting from the next line … … 58 63 if(!this.containsAll(paragraphStartingAtNextLine)) { 59 64 //4b. No; then we simply need to calculate the position of the next line and return that. 60 final RectangleboundingBox = splitAt.getBoundingBox();65 final AxisAlignedBoxBounds boundingBox = splitAt.getBoundingBox(); 61 66 return new Point(((Text) splitAt.getFirst()).getX(), (int)boundingBox.getMaxY() + lineHeight); 62 67 } … … 66 71 //6. Return the position of the new line we have made space for. 67 72 68 final RectangleboundingBox = splitAt.getBoundingBox();73 final AxisAlignedBoxBounds boundingBox = splitAt.getBoundingBox(); 69 74 final int x = ((Text) splitAt.getFirst()).getX(); 70 75 return new Point(x, (int)boundingBox.getMaxY() + lineHeight); … … 72 77 73 78 private static int getLineHeight(final Line line) { 74 return (int) (line.get(0).get Area().getBounds().getHeight() * 1.2);79 return (int) (line.get(0).getBoundingBox().getHeight() * 1.2); 75 80 } 76 81 … … 89 94 private static boolean isInSameParagraph(final Line thisLine, final Line nextLine, final int lineHeight) { 90 95 if(!XGroupLogic.areInSameXGroup(thisLine.get(0), nextLine.get(0))) return false; 91 final RectanglethisLineBoundingBox = thisLine.getBoundingBox();92 final RectanglenextLineBoundingBox = nextLine.getBoundingBox();93 final Point toAdd = new Point(Math.min((int)thisLineBoundingBox.get X(),(int) nextLineBoundingBox.getX()), (int)thisLineBoundingBox.getMaxY() + lineHeight);94 final Rectangle overlappingSection = new Rectangle(thisLineBoundingBox);95 overlappingSection. add(toAdd);96 final AxisAlignedBoxBounds thisLineBoundingBox = thisLine.getBoundingBox(); 97 final AxisAlignedBoxBounds nextLineBoundingBox = nextLine.getBoundingBox(); 98 final Point toAdd = new Point(Math.min((int)thisLineBoundingBox.getMinX(),(int) nextLineBoundingBox.getMinX()), (int)thisLineBoundingBox.getMaxY() + lineHeight); 99 final AxisAlignedBoxBounds overlappingSection = new AxisAlignedBoxBounds(thisLineBoundingBox); 100 overlappingSection.combineWith(toAdd); 96 101 return overlappingSection.intersects(nextLineBoundingBox); 97 102 }
Note:
See TracChangeset
for help on using the changeset viewer.