@@ -132,6 +132,14 @@ public PBlock(Device dev, Set<Site> sites) {
132132 else slices .addAll (slicems == null ? Collections .emptyList () : slicems );
133133 PBlockRange sliceRange = createPBlockRange (dev , slices );
134134 if (sliceRange != null ) add (sliceRange );
135+
136+ // IRI_QUADs are a special case
137+ List <Site > iriQuadOdds = typeSets .remove (SiteTypeEnum .IRI_QUAD_ODD );
138+ List <Site > iriQuadEvens = typeSets .remove (SiteTypeEnum .IRI_QUAD_EVEN );
139+ if (iriQuadOdds == null ) iriQuadOdds = iriQuadEvens == null ? Collections .emptyList () : iriQuadEvens ;
140+ else iriQuadOdds .addAll (iriQuadEvens == null ? Collections .emptyList () : iriQuadEvens );
141+ PBlockRange iriQuadRange = createPBlockRange (dev , iriQuadOdds );
142+ if (iriQuadRange != null ) add (iriQuadRange );
135143 // Rest of site types
136144 for (Entry <SiteTypeEnum ,ArrayList <Site >> e : typeSets .entrySet ()) {
137145 add (createPBlockRange (dev , e .getValue ()));
@@ -429,100 +437,38 @@ public PBlock createNewPblockAt(Site placement) {
429437 /**
430438 * Attempts to move the pblock by an offset of tiles in the x and y directions.
431439 * @param dx The number of tiles to move the pblock in the x direction.
432- * @param dy The number of tiles to mvoe the pblock in the y direction.
440+ * @param dy The number of tiles to move the pblock in the y direction.
433441 * @return True if the pblock ranges changed, false if no move was made.
434442 */
435443 public boolean movePBlock (int dx , int dy ) {
436444 if (dx == 0 && dy == 0 ) return false ;
437- Tile bl = getBottomLeftTile ();
438- Tile tr = getTopRightTile ();
439- Device d = tr .getDevice ();
440- boolean hasMoved = false ;
441- if (dx != 0 ) {
442- if (dx > 0 ) {
443- // moving to the right, check the columns to the right most tile
444- for (PBlockRange pbr : this ) {
445- int x = 0 ;
446- Site right = pbr .getUpperRightSite ().getNeighborSite (x , 0 );
447- int target = right .getTile ().getColumn () + dx ;
448- while (right .getTile ().getColumn () < target ) {
449- x ++;
450- right = pbr .getUpperRightSite ().getNeighborSite (x , 0 );
451- if (right .getTile ().getColumn () <= target ) {
452- hasMoved = true ;
453- }
454- }
455- if (hasMoved ) {
456- pbr .setUpperRight (right );
457- Site otherCorner = pbr .getLowerLeftSite ().getNeighborSite (x , 0 );
458- pbr .setLowerLeft (otherCorner );
459- }
460- }
461- } else {
462- // moving to the left, check the columns to the left most tile
463- for (PBlockRange pbr : this ) {
464- int x = 0 ;
465- Site left = pbr .getLowerLeftSite ().getNeighborSite (x , 0 );
466- int target = left .getTile ().getColumn () + dx ;
467- while (left .getTile ().getColumn () > target ) {
468- x --;
469- left = pbr .getLowerLeftSite ().getNeighborSite (x , 0 );
470- if (left .getTile ().getColumn () >= target ) {
471- hasMoved = true ;
472- }
473- }
474- if (hasMoved ) {
475- pbr .setLowerLeft (left );
476- Site otherCorner = pbr .getUpperRightSite ().getNeighborSite (x , 0 );
477- pbr .setUpperRight (otherCorner );
478- }
479- }
480-
445+ List <PBlockRange > pBlockRanges = new ArrayList <>();
446+ for (PBlockRange pbr : this ) {
447+ Tile left = pbr .getBottomLeftTile ();
448+ int siteIndex = pbr .getLowerLeftSite ().getSiteIndexInTile ();
449+ Tile newLeft = left .getTileNeighbor (dx , -dy );
450+ Site leftSite = pbr .getLowerLeftSite ();
451+ if (newLeft == null || leftSite .getCorrespondingSite (leftSite .getSiteTypeEnum (), newLeft ) == null ) {
452+ return false ;
481453 }
482- }
483- if (dy != 0 ) {
484- if (dy > 0 ) {
485- // moving down, check tiles below
486- for (PBlockRange pbr : this ) {
487- int y = 0 ;
488- Site left = pbr .getLowerLeftSite ().getNeighborSite (0 , y );
489- int target = left .getTile ().getRow () + dy ;
490- while (left .getTile ().getRow () < target ) {
491- y --;
492- left = pbr .getLowerLeftSite ().getNeighborSite (0 , y );
493- if (left .getTile ().getRow () <= target ) {
494- hasMoved = true ;
495- }
496- }
497- if (hasMoved ) {
498- pbr .setLowerLeft (left );
499- Site otherCorner = pbr .getUpperRightSite ().getNeighborSite (0 , y );
500- pbr .setUpperRight (otherCorner );
501- }
502- }
503- } else {
504- // moving up, check the rows above
505- for (PBlockRange pbr : this ) {
506- int y = 0 ;
507- Site right = pbr .getUpperRightSite ().getNeighborSite (0 , y );
508- int target = right .getTile ().getRow () + dy ;
509- while (right .getTile ().getRow () > target ) {
510- y ++;
511- right = pbr .getUpperRightSite ().getNeighborSite (0 , y );
512- if (right .getTile ().getRow () >= target ) {
513- hasMoved = true ;
514- }
515- }
516- if (hasMoved ) {
517- pbr .setUpperRight (right );
518- Site otherCorner = pbr .getLowerLeftSite ().getNeighborSite (0 , y );
519- pbr .setLowerLeft (otherCorner );
520- }
521- }
522-
454+ Site newLeftSite = newLeft .getSites ()[siteIndex ];
455+ Tile right = pbr .getTopRightTile ();
456+ Tile newRight = right .getTileNeighbor (dx , -dy );
457+ Site rightSite = pbr .getUpperRightSite ();
458+ if (newRight == null || rightSite .getCorrespondingSite (rightSite .getSiteTypeEnum (), newRight ) == null ) {
459+ return false ;
523460 }
461+ int upperRightSiteIndex = pbr .getUpperRightSite ().getSiteIndexInTile ();
462+ Site otherCorner = newRight .getSites ()[upperRightSiteIndex ];
463+ pBlockRanges .add (new PBlockRange (newLeftSite , otherCorner ));
464+ }
465+ int i = 0 ;
466+ for (PBlockRange pbr : pBlockRanges ) {
467+ this .get (i ).setLowerLeft (pbr .getLowerLeftSite ());
468+ this .get (i ).setUpperRight (pbr .getUpperRightSite ());
469+ i ++;
524470 }
525- return hasMoved ;
471+ return true ;
526472 }
527473
528474 public static void main (String [] args ) {
0 commit comments