Changeset 1102 for trunk/src/org/expeditee/items/Line.java
- Timestamp:
- 05/10/18 16:04:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/Line.java
r919 r1102 19 19 package org.expeditee.items; 20 20 21 import java.awt.BasicStroke;22 import java.awt.Color;23 import java.awt.Graphics2D;24 import java.awt.Point;25 import java.awt.Polygon;26 import java.awt.Rectangle;27 import java.awt.RenderingHints;28 import java.awt.Shape;29 import java.awt.Stroke;30 import java.awt.geom.AffineTransform;31 import java.awt.geom.Point2D;32 21 import java.util.ArrayList; 33 22 import java.util.Collection; … … 37 26 import java.util.List; 38 27 39 import org.expeditee.gui.DisplayIO; 28 import org.expeditee.core.Colour; 29 import org.expeditee.core.Dimension; 30 import org.expeditee.core.Fill; 31 import org.expeditee.core.Point; 32 import org.expeditee.core.Stroke; 33 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 34 import org.expeditee.core.bounds.CombinationBoxBounds; 35 import org.expeditee.core.bounds.PolygonBounds; 36 import org.expeditee.gio.EcosystemManager; 37 import org.expeditee.gio.GraphicsManager; 38 import org.expeditee.gui.DisplayController; 40 39 import org.expeditee.gui.Frame; 41 40 import org.expeditee.gui.FrameGraphics; … … 59 58 60 59 61 public static Polygon createArrowheadPolygon(double x0, double y0, float arrowLength0, double arrowRatio0, double arrowNibPerc0)60 public static PolygonBounds createArrowheadPolygon(double x0, double y0, float arrowLength0, double arrowRatio0, double arrowNibPerc0) 62 61 { 63 64 Polygon arrowhead = new Polygon(); 62 PolygonBounds arrowhead = new PolygonBounds(); 65 63 66 64 int ix0 = (int)Math.round(x0); … … 73 71 int flange_iy_left = (int) Math.round((y0 - flange_y_width)); 74 72 int flange_iy_right = (int) Math.round((y0 + flange_y_width)); 75 76 77 arrowhead.addPoint(ix0, iy0); 78 arrowhead.addPoint(flange_ix_project, flange_iy_left); 79 80 arrowhead.addPoint(ix_nib, iy0); 81 82 arrowhead.addPoint(flange_ix_project, flange_iy_right); 73 74 arrowhead.addPoint(new Point(ix0, iy0)); 75 arrowhead.addPoint(new Point(flange_ix_project, flange_iy_left)); 76 arrowhead.addPoint(new Point(ix_nib, iy0)); 77 arrowhead.addPoint(new Point(flange_ix_project, flange_iy_right)); 83 78 84 79 return arrowhead; … … 95 90 96 91 // brush strokes used for painting this line and highlighting 97 private Stroke _lineStroke = new BasicStroke(DEFAULT_THICKNESS, CAP, JOIN, 4.0F);92 private Stroke _lineStroke = new Stroke(DEFAULT_THICKNESS, DEFAULT_CAP, DEFAULT_JOIN); 98 93 99 94 Stroke getStroke() { … … 143 138 for (int i = 0; i < pattern.length; i++) 144 139 dash[i] = (float) pattern[i]; 145 _lineStroke = new BasicStroke(Math.max(thick, 146 MINIMUM_PAINT_THICKNESS), CAP, JOIN, 10f, dash, 0.0f); 140 _lineStroke = new Stroke(Math.max(thick, MINIMUM_PAINT_THICKNESS), DEFAULT_CAP, DEFAULT_JOIN, dash, 0.0f); 147 141 } else { 148 _lineStroke = new BasicStroke(Math.max(thick, 149 MINIMUM_PAINT_THICKNESS), CAP, JOIN); 150 } 151 152 updatePolygon(); 142 _lineStroke = new Stroke(Math.max(thick, MINIMUM_PAINT_THICKNESS), DEFAULT_CAP, DEFAULT_JOIN); 143 } 144 145 invalidateBounds(); 153 146 } 154 147 … … 240 233 _start = start; 241 234 _start.addLine(this); 242 updatePolygon();235 invalidateBounds(); 243 236 } 244 237 } … … 258 251 _end = end; 259 252 _end.addLine(this); 260 updatePolygon();253 invalidateBounds(); 261 254 } 262 255 } … … 317 310 for (int i = 0; i < pattern.length; i++) 318 311 dash[i] = (float) pattern[i]; 319 _lineStroke = new BasicStroke(Math.max(thick, MINIMUM_THICKNESS), 320 CAP, JOIN, 10f, dash, 0.0f); 312 _lineStroke = new Stroke(Math.max(thick, MINIMUM_THICKNESS), DEFAULT_CAP, DEFAULT_JOIN, dash, 0.0f); 321 313 } else 322 _lineStroke = new BasicStroke(Math.max(thick, MINIMUM_THICKNESS), 323 CAP, JOIN); 314 _lineStroke = new Stroke(Math.max(thick, MINIMUM_THICKNESS), DEFAULT_CAP, DEFAULT_JOIN); 324 315 325 316 if (_start.getLinePattern() != pattern) … … 333 324 334 325 @Override 335 public void paint(Graphics2D g) { 336 if (!isVisible()) 337 return; 338 339 // Dont paint lines with thickness 0 if they are the border on a filled 340 // shape 341 if (dontPaint()) 342 return; 343 344 g.setColor(getPaintColor()); 326 public void paint() 327 { 328 if (!isVisible()) return; 329 330 // Dont paint lines with thickness 0 if they are the border on a filled shape 331 if (dontPaint()) return; 345 332 346 333 // if (this._mode == Item.SelectedMode.Disconnect) 347 334 // System.out.println("Disconnect mode!"); 348 g.setStroke(_lineStroke);349 335 // Get a path of points 350 int[][][] paths = getPaths(); 351 for (int i = 0; i < paths.length; i++) { 352 int[][] path = paths[i]; 353 int last = path[0].length - 1; 354 if (path[0][0] == path[0][last] && path[1][0] == path[1][last]) { 355 g.drawPolygon(path[0], path[1], last); 356 } else { 357 g.drawPolyline(path[0], path[1], last + 1); 358 } 359 } 336 PolygonBounds[] paths = getPaths(); 337 for (PolygonBounds path : paths) { 338 EcosystemManager.getGraphicsManager().drawPolygon(path, null, null, 0.0f, null, getPaintColor(), _lineStroke); 339 } 340 360 341 // paint the arrowhead (if necessary) 361 paintArrows(g); 362 363 if (showLineHighlight() && isHighlighted()) { 364 g.setColor(getHighlightColor()); 365 g.setStroke(HIGHLIGHT_STROKE); 366 ((Graphics2D) g).draw(this.getArea()); 342 paintArrows(); 343 344 if (shouldShowLineHighlight() && isHighlighted()) { 345 PolygonBounds poly = (PolygonBounds) getBounds(); 346 EcosystemManager.getGraphicsManager().drawPolygon(poly, null, null, 0.0f, null, getHighlightColor(), HIGHLIGHT_STROKE); 367 347 } 368 348 } … … 371 351 // enable invisible shapes (for web browser divs) only when XRayMode is off 372 352 return getThickness() <= 0 && _start.isEnclosed() 373 && (_start.getFillColor() != null || ! FrameGraphics.isXRayMode());374 } 375 376 protected int[][][] getPaths() {353 && (_start.getFillColor() != null || !DisplayController.isXRayMode()); 354 } 355 356 protected PolygonBounds[] getPaths() { 377 357 List<List<Point>> pointPaths = new LinkedList<List<Point>>(); 378 358 Collection<Line> visited = new HashSet<Line>(); … … 388 368 } 389 369 // Put the paths into int arrays 390 int[][][] paths = new int[pointPaths.size()][][];370 PolygonBounds[] paths = new PolygonBounds[pointPaths.size()]; 391 371 Iterator<List<Point>> iter = pointPaths.iterator(); 392 372 393 373 for (int i = 0; i < paths.length; i++) { 394 374 List<Point> pointPath = iter.next(); 395 int[][] path = new int[2][pointPath.size()];375 PolygonBounds path = new PolygonBounds(); 396 376 paths[i] = path; 397 377 // Add all the x and y's to the array 398 for (int j = 0; j < p ath[0].length; j++) {399 path [0][j] = pointPath.get(j).x;400 path[1][j] = pointPath.get(j).y;401 402 }378 for (int j = 0; j < pointPath.size(); j++) { 379 path.addPoint(pointPath.get(j).x, pointPath.get(j).y); 380 } 381 } 382 403 383 return paths; 404 384 } 405 385 406 protected List<Point> getPath(Collection<Line> visited, 407 LinkedList<Line> toExplore){386 protected List<Point> getPath(Collection<Line> visited, LinkedList<Line> toExplore) 387 { 408 388 LinkedList<Point> points = new LinkedList<Point>(); 409 389 // put the start item points into our list … … 417 397 } 418 398 419 public void paintArrows(Graphics2D g) { 420 if (dontPaint()) 421 return; 422 423 g.setColor(getPaintColor()); 424 g.setStroke(new BasicStroke(getPaintThickness(), CAP, 425 BasicStroke.JOIN_MITER)); 426 paintArrow(g, getStartArrow()); 427 paintArrow(g, getEndArrow()); 428 399 public void paintArrows() 400 { 401 if (dontPaint()) return; 402 403 paintArrow(getStartArrow()); 404 paintArrow(getEndArrow()); 405 406 // TODO: What is a virtual spot? cts16 429 407 if (_virtualSpot != null) { 430 _virtualSpot.paint( g);408 _virtualSpot.paint(); 431 409 invalidateVirtualSpot(); 432 410 _virtualSpot = null; … … 456 434 * @return 457 435 */ 458 private Shape getArrow(Item withArrow, Point startOffset, Point endOffset) { 459 boolean disconnectMode = withArrow._mode == Item.HighlightMode.Disconnect; 436 private PolygonBounds getArrow(Item withArrow, Point startOffset, Point endOffset) 437 { 438 boolean disconnectMode = withArrow._highlightMode == Item.HighlightMode.Disconnect; 439 460 440 // only draw an arrowhead if necessary 461 if (!(this._mode == Item.HighlightMode.Disconnect && disconnectMode) 462 && (!withArrow.hasVisibleArrow() || withArrow.getLines().size() > 1)) 441 if ( !(this._highlightMode == Item.HighlightMode.Disconnect && disconnectMode) && 442 (!withArrow.hasVisibleArrow() || withArrow.getLines().size() > 1)) 443 { 463 444 return null; 464 445 } 446 465 447 int x0, x1, y0, y1; 466 448 … … 475 457 476 458 // set the size of the disconnect indicator arrowhead 477 if (this._ mode == Item.HighlightMode.Disconnect) {459 if (this._highlightMode == Item.HighlightMode.Disconnect) { 478 460 arrowLength = 15; 479 461 arrowRatio = 0.3; … … 494 476 // The length of the line must at least be as long as the arrow or we 495 477 // wont show the arrow 496 if (length <= MINIMUM_ARROW_HEAD_LENGTH) 497 return null;478 if (length <= MINIMUM_ARROW_HEAD_LENGTH) return null; 479 498 480 if (arrowLength == AUTO_ARROWHEAD_LENGTH) { 499 481 arrowLength = getAutoArrowheadLength(length); … … 508 490 509 491 // only calculate the arrowhead polygon if necessary 510 Polygon arrowhead = withArrow.getArrowhead();492 PolygonBounds arrowhead = withArrow.getArrowhead(); 511 493 if (arrowhead == null || disconnectMode) { 512 arrowhead = createArrowheadPolygon(x0, y0,arrowLength,arrowRatio,arrowNibPerc);494 arrowhead = createArrowheadPolygon(x0, y0, arrowLength, arrowRatio, arrowNibPerc); 513 495 514 496 if (!disconnectMode) 515 withArrow.setArrowhead(arrowhead); 516 } 497 withArrow.setArrowhead(new PolygonBounds(arrowhead)); 498 } 499 arrowhead = arrowhead.clone(); 517 500 double rad = calcAngle((float) x0, (float) y0, (float) x1, (float) y1); 518 arrowhead.translate((x0 + length) - arrowhead.xpoints[0], y0 519 - arrowhead.ypoints[0]); 520 AffineTransform tx = AffineTransform.getRotateInstance(rad, x0, y0); 521 522 int[] rx = new int[arrowhead.npoints]; 523 int[] ry = new int[arrowhead.npoints]; 524 525 for(int i = 0; i < arrowhead.npoints; i++){ 526 Point2D p = new Point2D.Double(arrowhead.xpoints[i], arrowhead.ypoints[i]); 527 tx.transform(p,p); 528 rx[i] = (int) p.getX(); 529 ry[i] = (int) p.getY(); 530 } 531 532 return new Polygon(rx, ry, arrowhead.npoints); 501 arrowhead.translate((x0 + length) - arrowhead.toArray()[0].x, y0 - arrowhead.toArray()[0].y); 502 arrowhead.rotate(rad, x0, y0); 503 504 return arrowhead; 533 505 } 534 506 535 public Polygon getStartArrow() {536 return (Polygon)getArrow(_start, _startOffset, _endOffset);507 public PolygonBounds getStartArrow() { 508 return getArrow(_start, _startOffset, _endOffset); 537 509 } 538 510 539 public Polygon getEndArrow() {540 return (Polygon)getArrow(_end, _endOffset, _startOffset);511 public PolygonBounds getEndArrow() { 512 return getArrow(_end, _endOffset, _startOffset); 541 513 } 542 514 … … 544 516 * Based on code from DeSL (Arrow2D) http://sourceforge.net/projects/desl/ 545 517 */ 546 private void paintArrow(Graphics2D g, Shape arrow) { 518 private void paintArrow(PolygonBounds arrow) 519 { 520 Colour arrowColour = getPaintColor(); 521 Fill arrowFill = new Fill(arrowColour); 522 Stroke arrowStroke = new Stroke(getPaintThickness(), DEFAULT_CAP, Stroke.JOIN.MITER); 547 523 548 524 if(arrow == null) { … … 557 533 // **** 558 534 559 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);560 561 g. draw(arrow);562 g. fill(arrow);535 GraphicsManager g = EcosystemManager.getGraphicsManager(); 536 537 g.setAntialiasing(true); 538 g.drawPolygon(arrow.close(), null, null, 0.0f, arrowFill, arrowColour, arrowStroke); 563 539 564 540 } … … 630 606 return temp; 631 607 } 608 609 public Item getEndPointToDisconnect(Point p) 610 { 611 return getEndPointToDisconnect(p.x, p.y); 612 } 632 613 633 614 public Item getEndPointToDisconnect(int x, int y) { … … 653 634 654 635 if (distStart < NORMAL_THRESHHOLD) { 655 start._ mode = Item.HighlightMode.Normal;636 start._highlightMode = Item.HighlightMode.Normal; 656 637 return start; 657 638 } else if (distEnd < NORMAL_THRESHHOLD) { 658 end._ mode = Item.HighlightMode.Normal;639 end._highlightMode = Item.HighlightMode.Normal; 659 640 return end; 660 641 } else if (distStart < DISCONNECT_THRESHHOLD) { 661 642 if (start.getLines().size() > 1 662 643 || start.getConstraints().size() > 0) 663 start._ mode = Item.HighlightMode.Disconnect;644 start._highlightMode = Item.HighlightMode.Disconnect; 664 645 else 665 start._ mode = Item.HighlightMode.Normal;646 start._highlightMode = Item.HighlightMode.Normal; 666 647 return start; 667 648 } else if (distEnd < DISCONNECT_THRESHHOLD) { 668 649 if (end.getLines().size() > 1 || end.getConstraints().size() > 0) 669 end._ mode = Item.HighlightMode.Disconnect;650 end._highlightMode = Item.HighlightMode.Disconnect; 670 651 else 671 end._ mode = Item.HighlightMode.Normal;652 end._highlightMode = Item.HighlightMode.Normal; 672 653 return end; 673 654 } … … 677 658 678 659 @Override 679 public int setHighlightColor() {680 super.setHighlightColor ();681 682 return Item.UNCHANGED_CURSOR;660 public void setHighlightColorToDefault() { 661 super.setHighlightColorToDefault(); 662 663 //return Item.UNCHANGED_CURSOR; 683 664 } 684 665 … … 690 671 */ 691 672 @Override 692 public void setColor(Colo r c) {673 public void setColor(Colour c) { 693 674 super.setColor(c); 694 675 … … 698 679 699 680 @Override 700 public Colo r getFillColor() {681 public Colour getFillColor() { 701 682 return _start.getFillColor(); 702 683 } … … 882 863 private Item _virtualSpot = null; 883 864 884 public void showVirtualSpot(Item orig, int mouseX, int mouseY) {885 if (orig.getLines().size() != 1)886 865 public void showVirtualSpot(Item orig, int mouseX, int mouseY) 866 { 867 if (orig.getLines().size() != 1) return; 887 868 888 869 // lines that are in 'connected' mode, also cannot be attached 889 if (orig.getLines().get(0).getOppositeEnd(orig).isFloating()) 890 return; 870 if (orig.getLines().get(0).getOppositeEnd(orig).isFloating()) return; 891 871 892 872 Item spot = new Dot(-1, orig.getX(), orig.getY()); 893 873 Item.DuplicateItem(orig, spot); 894 874 spot.setThickness(Math.max(this.getThickness(), 5)); 895 if (this.getColor() != Color.RED) 896 spot.setColor(Color.RED); 897 else 898 spot.setColor(Color.BLUE); 899 875 if (!this.getColor().equals(Colour.RED)) { 876 spot.setColor(Colour.RED); 877 } else { 878 spot.setColor(Colour.BLUE); 879 } 880 900 881 // unhighlight all the dots 901 882 for (Item conn : getAllConnected()) { 902 883 conn.setHighlightMode(Item.HighlightMode.None); 903 } 884 conn.setHighlightColorToDefault(); 885 } 886 887 // calculate nearest point on line from spot 888 org.expeditee.core.Line line = new org.expeditee.core.Line(_start.getPosition(), _end.getPosition()); 889 Point nearest = line.getPointNearestTo(spot.getPosition()); 890 891 // position spot on the line 892 spot.setPosition(nearest); 893 _virtualSpot = spot; 894 invalidateVirtualSpot(); 895 } 896 897 public void showVirtualSpot(int mouseX, int mouseY) { 898 Item spot = new Dot(mouseX, mouseY, -1); 899 spot.setThickness(Math.max(this.getThickness(), 5)); 900 if (DEFAULT_HIGHLIGHT.equals(this.getColor())) 901 spot.setColor(ALTERNATE_HIGHLIGHT); 902 else 903 spot.setColor(DEFAULT_HIGHLIGHT); 904 905 906 // calculate nearest point on line from spot 907 org.expeditee.core.Line line = new org.expeditee.core.Line(_start.getPosition(), _end.getPosition()); 908 Point nearest = line.getPointNearestTo(spot.getPosition()); 909 910 // position spot on the line 911 spot.setPosition(nearest); 912 _virtualSpot = spot; 913 invalidateVirtualSpot(); 914 } 915 916 public Item forceMerge(Item spot, int mouseX, int mouseY) { 904 917 905 918 // calculate nearest point on line from spot … … 930 943 // position spot on the line 931 944 spot.setPosition((int) x, (int) y); 932 _virtualSpot = spot;933 invalidateVirtualSpot();934 }935 936 public void showVirtualSpot(int mouseX, int mouseY) {937 Item spot = new Dot(mouseX, mouseY, -1);938 spot.setThickness(Math.max(this.getThickness(), 5));939 if (DEFAULT_HIGHLIGHT.equals(this.getColor()))940 spot.setColor(ALTERNATE_HIGHLIGHT);941 else942 spot.setColor(DEFAULT_HIGHLIGHT);943 944 // calculate nearest point on line from spot945 double slope1;946 double slope2;947 double x, y;948 949 slope1 = (_start.getY() - _end.getY() * 1.0)950 / (_start.getX() - _end.getX());951 slope2 = -1 / slope1;952 953 // if the line is horizontal954 if (slope1 == 0) {955 x = spot.getX();956 y = _start.getY();957 // if the line is vertical958 } else if (slope2 == 0) {959 x = _start.getX();960 y = spot.getY();961 // otherwise, the line is sloped962 } else {963 x = (-1 * slope2 * spot.getX() + spot.getY() - _start.getY() + slope1964 * _start.getX())965 / (slope1 - slope2);966 y = slope1 * (x - _start.getX()) + _start.getY();967 }968 969 // position spot on the line970 spot.setPosition((int) x, (int) y);971 _virtualSpot = spot;972 invalidateVirtualSpot();973 }974 975 public Item forceMerge(Item spot, int mouseX, int mouseY) {976 977 // calculate nearest point on line from spot978 double slope1;979 double slope2;980 double x, y;981 982 slope1 = (_start.getY() - _end.getY() * 1.0)983 / (_start.getX() - _end.getX());984 slope2 = -1 / slope1;985 986 // if the line is horizontal987 if (slope1 == 0) {988 x = spot.getX();989 y = _start.getY();990 // if the line is vertical991 } else if (slope2 == 0) {992 x = _start.getX();993 y = spot.getY();994 // otherwise, the line is sloped995 } else {996 x = (-1 * slope2 * spot.getX() + spot.getY() - _start.getY() + slope1997 * _start.getX())998 / (slope1 - slope2);999 y = slope1 * (x - _start.getX()) + _start.getY();1000 }1001 1002 // position spot on the line1003 spot.setPosition((int) x, (int) y);1004 945 1005 946 // Keep constraints … … 1018 959 Line temp = copy(); 1019 960 1020 Frame currentFrame = Display IO.getCurrentFrame();961 Frame currentFrame = DisplayController.getCurrentFrame(); 1021 962 temp.setID(currentFrame.getNextItemID()); 1022 963 temp.setEndItem(_end); … … 1101 1042 1102 1043 @Override 1103 public void updatePolygon() {1104 _poly = new Polygon();1105 1106 Rectangleone;1107 Rectangletwo;1044 public PolygonBounds updateBounds() { 1045 PolygonBounds ret = new PolygonBounds(); 1046 1047 AxisAlignedBoxBounds one; 1048 AxisAlignedBoxBounds two; 1108 1049 1109 1050 /** … … 1121 1062 Item e = new Dot(_end.getX(), _end.getY(), -1); 1122 1063 1123 one = s.getPolygon().getBounds();1124 two = e.getPolygon().getBounds();1064 one = AxisAlignedBoxBounds.getEnclosing(s.getBounds()); 1065 two = AxisAlignedBoxBounds.getEnclosing(e.getBounds()); 1125 1066 } else { 1126 1067 Item s = new Dot(_start.getX(), _start.getY(), -1); 1127 1068 Item e = new Dot(_end.getX(), _end.getY(), -1); 1128 1069 1129 one = e.getPolygon().getBounds();1130 two = s.getPolygon().getBounds();1070 one = AxisAlignedBoxBounds.getEnclosing(e.getBounds()); 1071 two = AxisAlignedBoxBounds.getEnclosing(s.getBounds()); 1131 1072 /* 1132 1073 * one = _end.getPolygon().getBounds(); two = … … 1136 1077 1137 1078 // if one is above two 1138 if (one.get Y() < two.getY()) {1139 _poly.addPoint((int) one.getMaxX(), (int)one.getMinY());1140 _poly.addPoint((int) two.getMaxX(), (int)two.getMinY());1141 _poly.addPoint((int) two.getMinX(), (int)two.getMaxY());1142 _poly.addPoint((int) one.getMinX(), (int)one.getMaxY());1079 if (one.getMinY() < two.getMinY()) { 1080 ret.addPoint(one.getMaxX(), one.getMinY()); 1081 ret.addPoint(two.getMaxX(), two.getMinY()); 1082 ret.addPoint(two.getMinX(), two.getMaxY()); 1083 ret.addPoint(one.getMinX(), one.getMaxY()); 1143 1084 // if one is below two 1144 1085 } else { 1145 _poly.addPoint((int) one.getMinX(), (int) one.getMinY()); 1146 _poly.addPoint((int) two.getMinX(), (int) two.getMinY()); 1147 _poly.addPoint((int) two.getMaxX(), (int) two.getMaxY()); 1148 _poly.addPoint((int) one.getMaxX(), (int) one.getMaxY()); 1149 } 1150 1086 ret.addPoint(one.getMinX(), one.getMinY()); 1087 ret.addPoint(two.getMinX(), two.getMinY()); 1088 ret.addPoint(two.getMaxX(), two.getMaxY()); 1089 ret.addPoint(one.getMaxX(), one.getMaxY()); 1090 } 1091 1092 return ret.close(); 1151 1093 } 1152 1094 … … 1199 1141 1200 1142 public double getLength() { 1201 return getLength(_start.getPosition(), _end.getPosition());1143 return Point.distanceBetween(_start.getPosition(), _end.getPosition()); 1202 1144 } 1203 1145 … … 1210 1152 } 1211 1153 1212 public static double getLength(Point p1, Point p2) {1213 return Point.distance(p1 .x, p1.y, p2.x, p2.y);1214 } 1215 1216 @Override 1217 public Rectangle[]getDrawingArea() { // TODO: CACHE - LIKE UPDATE POLYGON1154 /* public static double getLength(Point p1, Point p2) { 1155 return Point.distance(p1, p2); 1156 }*/ 1157 1158 @Override 1159 public AxisAlignedBoxBounds getDrawingArea() { // TODO: CACHE - LIKE UPDATE POLYGON 1218 1160 1219 1161 float currentThickness = this.getThickness() + 4; … … 1236 1178 y -= halfThickness; 1237 1179 1238 Rectangle bounds = new Rectangle(x, y, w, h);1180 AxisAlignedBoxBounds bounds = new AxisAlignedBoxBounds(x, y, w, h); 1239 1181 1240 1182 // TODO: Cap bounds … … 1257 1199 overall as opposed to advanced/expensive calculations for getting exact 1258 1200 bounding box */ 1259 Rectangle arrowBounds = new Rectangle(_end.getX() - nArrowLength,1201 AxisAlignedBoxBounds arrowBounds = new AxisAlignedBoxBounds(_end.getX() - nArrowLength, 1260 1202 _end.getY() - nArrowLength, 2 * nArrowLength, 1261 1203 2 * nArrowLength); … … 1263 1205 if (currentThickness > 0.0f) { 1264 1206 1265 arrowBounds = new Rectangle(arrowBounds.x- halfThickness,1266 arrowBounds. y - halfThickness, arrowBounds.width1267 + thickness, arrowBounds. height+ thickness);1268 } 1269 1270 return new Rectangle[] { bounds, arrowBounds };1207 arrowBounds = new AxisAlignedBoxBounds(arrowBounds.getMinX() - halfThickness, 1208 arrowBounds.getMinY() - halfThickness, arrowBounds.getWidth() 1209 + thickness, arrowBounds.getHeight() + thickness); 1210 } 1211 1212 return bounds.combineWith(arrowBounds); 1271 1213 } else { 1272 return new Rectangle[] { bounds };1214 return bounds; 1273 1215 } 1274 1216 … … 1294 1236 public void scale(Float scale, int originX, int originY) { 1295 1237 } 1238 1239 @Override 1240 public float getSize() 1241 { 1242 return getThickness(); 1243 } 1296 1244 }
Note:
See TracChangeset
for help on using the changeset viewer.