Changeset 970


Ignore:
Timestamp:
10/27/15 12:11:12 (9 years ago)
Author:
bln4
Message:

Ok, now when following a daisy chain it properly looks for loops. If it sees a loop it won't walk into it twice.

Location:
trunk/src/org/expeditee
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/io/flowlayout/XGroupItem.java

    r969 r970  
    410410                }
    411411        }
    412 
     412       
     413        protected boolean daisyChainContainsLoop(final XGroupItem toplevel_xgroup, final Item exitingDot, Collection<XGroupItem> groupsSeen) {
     414                final Item start_item = exitingDot;
     415                final Item end_item = start_item.getLines().get(0).getEndItem();
     416                final XGroupItem xgroup = innermostXGroup(end_item,toplevel_xgroup.getGroupedItemList());
     417               
     418                if(groupsSeen.contains(xgroup)) return true;
     419               
     420                groupsSeen.add(xgroup);
     421               
     422                for(final Item i : xgroup.remaining_item_list) {
     423                        final List<Line> lines = i.getLines();
     424                        if(lines.size() == 1 && lines.get(0).getStartItem() == i) {
     425                                return daisyChainContainsLoop(toplevel_xgroup, i, groupsSeen);
     426                        }
     427                }
     428               
     429                return false;                   
     430        }
    413431       
    414432        protected void repositionOutOfFlowGroupsFollowLine(XGroupItem toplevel_xgroup, Item remaining_item, Collection<XGroupItem> out_of_flow)
     
    419437                //   See if the arrow-head falls inside an XGroup area
    420438                //   => Ignore endings that are in the same XGroupItem as the line started in
    421                
    422439                List<Line> used_in_lines = remaining_item.getLines();
    423440                if (used_in_lines.size()==1) {
     
    452469                                               
    453470                                                if (xgroup_item != this) {
    454                                                        
    455                                                         if(out_of_flow.contains(xgroup_item)) {
    456                                                                 final Collection<Item> remaining_dots = new ArrayList<Item>(xgroup_item.remaining_item_list);
    457                                                                 boolean hasExit = false;
    458                                                                 for(final Item i : remaining_dots) {
    459                                                                         final List<Line> lines = i.getLines();
    460                                                                         if(lines.size() == 1 && lines.get(0).getStartItem() == i) {
    461                                                                                 hasExit = true;
    462                                                                                 break;
    463                                                                         }
     471                                               
     472                                                        if(out_of_flow.contains(xgroup_item) && daisyChainContainsLoop(toplevel_xgroup, start_item, new ArrayList<XGroupItem>())) {
     473                                                                System.err.println("#Found infinite loop; not following.");
     474                                                                continue;
     475                                                        }
     476                                                       
     477
     478                                                       
     479                                                        if(!out_of_flow.contains(xgroup_item)) {
     480                                                                for (Item remaining_item_deeper: xgroup_item.getRemainingItemList()) {
     481                                                                        xgroup_item.repositionOutOfFlowGroupsFollowLine(toplevel_xgroup,remaining_item_deeper,out_of_flow);
    464482                                                                }
    465                                                                 if(hasExit) continue;
    466483                                                        }
    467                                                        
    468                                                         out_of_flow.add(xgroup_item);
    469                                                        
    470                                                         for (Item remaining_item_deeper: xgroup_item.getRemainingItemList()) {
    471                                                                 xgroup_item.repositionOutOfFlowGroupsFollowLine(toplevel_xgroup,remaining_item_deeper,out_of_flow);
    472                                                         }
    473                                                                                                                
     484
     485                                                        out_of_flow.add(xgroup_item);                                                   
    474486                                                       
    475487                                                       
     
    535547                repositionOutOfFlowGroupsRecursive(toplevel_xgroup,out_of_flow);
    536548               
    537                 List<XGroupItem >toplevel_grouped_item_list = toplevel_xgroup.getGroupedItemList();
     549//              List<XGroupItem >toplevel_grouped_item_list = toplevel_xgroup.getGroupedItemList();
    538550
    539551                // ****
     
    622634                         List<Text> raw_text_item_list, List<XGroupItem> grouped_item_list, List<Item> remaining_item_list)
    623635        {
     636                final List<Item> origonal_item_list = new ArrayList<Item>(item_list);
    624637                // raw_text_items_list => all the non-enclosed text items
    625638                // grouped_items_list  => list of all enclosures containing text items
     
    760773                                if (area_polygon.isPerimeterPoint(enclosed_item.getPosition())) {
    761774                                        enclosed_item_list.remove(i);
    762                                 }
     775                                        //Don't include items the user hasn't asked us to.
     776                                }
     777                                //Only include items the user has asked to to include.
     778                                else if(!origonal_item_list.contains(enclosed_item)) enclosed_item_list.remove(i);
    763779                                else {
    764780                                        i++;
  • trunk/src/org/expeditee/items/MagneticConstraint/Actions/RepelTextAction.java

    r966 r970  
    33import java.awt.Point;
    44
     5import org.expeditee.gui.Browser;
    56import org.expeditee.gui.FrameUtils;
    67import org.expeditee.items.Item;
     8import org.expeditee.items.Text;
    79import org.expeditee.items.MagneticConstraint.MagneticConstraintActionWithArguments;
    810import org.expeditee.items.MagneticConstraint.MagneticConstraints;
     
    4244                        return false;
    4345                } else {
     46                        final int charDistance = Browser._theBrowser.getFontMetrics(((Text)item).getFont()).stringWidth("X");
    4447                        final Line tokensToMove = Line.getLineFromToken(item);
    45                         System.err.println("#Repeling tokens: " + tokensToMove);
    4648                        tokensToMove.removeFirst();
     49                        boolean afterGap = false;
     50                        for(int i = 1; i < tokensToMove.size();) {
     51                                if(afterGap) tokensToMove.remove(i);
     52                                else if((tokensToMove.get(i).getX() - charDistance) > (tokensToMove.get(i - 1).getX() + tokensToMove.get(i - 1).getBoundsWidth())) {
     53                                        afterGap = true;
     54                                        tokensToMove.remove(i);
     55                                } else i++;
     56                        }
    4757                        tokensToMove.deltaX(args[0].intValue());
    4858                        for(final Item token : tokensToMove) {
Note: See TracChangeset for help on using the changeset viewer.