@Test public void notIntersecting() { List<Vector> seg = new ArrayList<>(); seg.add(new Vector(0, 10)); List<Vector> res = FreeSegmentsUtil.removeSegment(seg, new Vector(-10, 0)); assertTrue(res.size() == 1); assertEquals(new Vector(0, 10), res.get(0)); res = FreeSegmentsUtil.removeSegment(seg, new Vector(10, 100)); assertTrue(res.size() == 1); assertEquals(new Vector(0, 10), res.get(0)); }
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);  }