@Test public void occupiedIntersectsMany() { List<Vector> seg = new ArrayList<>(); seg.add(new Vector(0, 2)); seg.add(new Vector(4, 6)); seg.add(new Vector(8, 10)); List<Vector> res = FreeSegmentsUtil.removeSegment(seg, new Vector(1, 9)); assertTrue(res.size() == 2); assertEquals(new Vector(0, 1), res.get(0)); assertEquals(new Vector(9, 10), res.get(1)); }
public static List<Vector> removeSegment(List<Vector> freeSegments, Vector occupiedSegment) { List<Vector> res = new ArrayList<>(); for (Vector seg: freeSegments) { if (seg.y <= occupiedSegment.x || seg.x >= occupiedSegment.y) { res.add(seg); } else { if (seg.x <= occupiedSegment.x) { res.add(new Vector(seg.x, occupiedSegment.x)); } if (occupiedSegment.y <= seg.y) { res.add(new Vector(occupiedSegment.y, seg.y)); } } } return res; }
FreeSegmentsUtil { public static List<Vector> removeSegment(List<Vector> freeSegments, Vector occupiedSegment) { List<Vector> res = new ArrayList<>(); for (Vector seg: freeSegments) { if (seg.y <= occupiedSegment.x || seg.x >= occupiedSegment.y) { res.add(seg); } else { if (seg.x <= occupiedSegment.x) { res.add(new Vector(seg.x, occupiedSegment.x)); } if (occupiedSegment.y <= seg.y) { res.add(new Vector(occupiedSegment.y, seg.y)); } } } return res; } }
FreeSegmentsUtil { public static List<Vector> removeSegment(List<Vector> freeSegments, Vector occupiedSegment) { List<Vector> res = new ArrayList<>(); for (Vector seg: freeSegments) { if (seg.y <= occupiedSegment.x || seg.x >= occupiedSegment.y) { res.add(seg); } else { if (seg.x <= occupiedSegment.x) { res.add(new Vector(seg.x, occupiedSegment.x)); } if (occupiedSegment.y <= seg.y) { res.add(new Vector(occupiedSegment.y, seg.y)); } } } return res; }  }
FreeSegmentsUtil { public static List<Vector> removeSegment(List<Vector> freeSegments, Vector occupiedSegment) { List<Vector> res = new ArrayList<>(); for (Vector seg: freeSegments) { if (seg.y <= occupiedSegment.x || seg.x >= occupiedSegment.y) { res.add(seg); } else { if (seg.x <= occupiedSegment.x) { res.add(new Vector(seg.x, occupiedSegment.x)); } if (occupiedSegment.y <= seg.y) { res.add(new Vector(occupiedSegment.y, seg.y)); } } } return res; }  static List<Vector> removeSegment(List<Vector> freeSegments, Vector occupiedSegment); }
FreeSegmentsUtil { public static List<Vector> removeSegment(List<Vector> freeSegments, Vector occupiedSegment) { List<Vector> res = new ArrayList<>(); for (Vector seg: freeSegments) { if (seg.y <= occupiedSegment.x || seg.x >= occupiedSegment.y) { res.add(seg); } else { if (seg.x <= occupiedSegment.x) { res.add(new Vector(seg.x, occupiedSegment.x)); } if (occupiedSegment.y <= seg.y) { res.add(new Vector(occupiedSegment.y, seg.y)); } } } return res; }  static List<Vector> removeSegment(List<Vector> freeSegments, Vector occupiedSegment);  }