public async Task <IActionResult> Edit(Guid id, [Bind("ID,Name")] Affected affected) { if (id != affected.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(affected); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AffectedExists(affected.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(affected)); }
public static (int, int) FindBoxStart(int size, Affected isAffected) { var(lower, upper) = FindInitialBounds(i => HasDiagonalSize(isAffected, i, size - 2), guess: size * 10); var diagoinalRow = BinarySearchWhile(i => HasDiagonalSize(isAffected, i, size - 2), lower, upper); var(col, row) = FindStepByStep(isAffected, diagoinalRow, 0, size); return(col, row - size + 1); }
public static int ProbeLeftColOfBeam(Affected isAffected, int startRow, int startCol, bool target) { // Very naive way to find the left of the beam, could be optimized var col = startCol; while (isAffected(col, startRow) != target) { col++; } return(col); }
public async Task <IActionResult> Create([Bind("ID,Name")] Affected affected) { if (ModelState.IsValid) { affected.ID = Guid.NewGuid(); _context.Add(affected); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(affected)); }
public static (int, int) FindStepByStep(Affected isAffected, int row, int col, int size) { while (!DiagonalFits(isAffected, row, col, size)) { row++; while (!isAffected(col, row)) { col++; } } return(col, row); }
public static bool DiagonalFits(Affected isAffected, int startRow, int startCol, int size) => isAffected(startCol + size - 1, startRow - size + 1);
public static bool HasDiagonalSize(Affected isAffected, int startRow, int size) { var col = ProbeLeftColOfBeam(isAffected, startRow, 0, true); return(DiagonalFits(isAffected, startRow, col, size)); }
public static int FindBoxSize(int size, Affected isAffected) { var(col, row) = FindBoxStart(size, isAffected); return(col * 10000 + row); }