public void moveRight() { BoxDrawing selectedBox = getSelectedBox(); if (selectedBox == null) { logs.Add("Selected Box is null"); return; } double left = selectedBox.left; double right = selectedBox.getRight(); double width = window.canvas.Width; if (Double.IsNaN(left) || Double.IsNaN(right) || Double.IsNaN(width)) { logs.Add("Could not move right"); return; } // check if we've hit the right side of the screen if (right >= width) { return; } selectedBox.left++; boxes[selected] = selectedBox; }
// check intersection, adjacency and containment private bool intersection() { bool result = false; if (boxes.Count < 2) { logs.Add("Not enough objects."); return(false); } BoxDrawing selectedBox = getSelectedBox(); BoxDrawing staticBox = getStaticBox(); if (selectedBox == null || staticBox == null) { logs.Add("Could not retrieve boxes."); return(false); } double t1 = selectedBox.top; double t2 = staticBox.top; double l1 = selectedBox.left; double l2 = staticBox.left; double r1 = selectedBox.getRight(); double r2 = staticBox.getRight(); double b1 = selectedBox.getBottom(); double b2 = staticBox.getBottom(); if (Double.IsNaN(t1) || Double.IsNaN(t2) || Double.IsNaN(l1) || Double.IsNaN(l2) || Double.IsNaN(r1) || Double.IsNaN(r2) || Double.IsNaN(b1) || Double.IsNaN(b2)) { logs.Add("Could not calculate intersection"); return(false); } if (!(l2 > r1 || r2 < l1 || t2 > b1 || b2 < t1)) { result = true; } return(result); }
private bool adjacency() { bool result = false; if (boxes.Count < 2) { logs.Add("There aren't enough boxes to compute adjacency"); return(false); } BoxDrawing selectedBox = getSelectedBox(); BoxDrawing staticBox = getStaticBox(); if (selectedBox == null || staticBox == null) { logs.Add("Could not get boxes for computing adjacency"); return(false); } double hDiff1 = selectedBox.top - staticBox.getBottom(); double hDiff2 = staticBox.top - selectedBox.getBottom(); double wDiff1 = selectedBox.left - staticBox.getRight(); double wDiff2 = staticBox.left - selectedBox.getRight(); if (Double.IsNaN(hDiff1) || Double.IsNaN(hDiff2) || Double.IsNaN(wDiff1) || Double.IsNaN(wDiff2)) { logs.Add("Could not compute adjacency"); return(false); } if ((hDiff1 > -1 && hDiff1 < 2 && hDiff2 < 0 && wDiff1 < 1 && wDiff2 < 1) || (hDiff2 > -1 && hDiff2 < 2 && hDiff1 < 0 && wDiff1 < 1 && wDiff2 < 1) || (wDiff1 > -1 && wDiff1 < 2 && wDiff2 < 0 && hDiff1 < 1 && hDiff2 < 1) || (wDiff2 > -1 && wDiff2 < 2 && wDiff1 < 0 && hDiff1 < 1 && hDiff2 < 1)) { result = true; } return(result); }
private bool containment() { bool result = false; if (boxes.Count < 2) { logs.Add("Not enough objects."); return(false); } BoxDrawing selectedBox = getSelectedBox(); BoxDrawing staticBox = getStaticBox(); if (selectedBox == null || staticBox == null) { logs.Add("Could not retrieve boxes."); return(false); } double tDiff = selectedBox.top - staticBox.top; double bDiff = staticBox.getBottom() - selectedBox.getBottom(); double lDiff = selectedBox.left - staticBox.left; double rDiff = staticBox.getRight() - selectedBox.getRight(); if (Double.IsNaN(tDiff) || Double.IsNaN(bDiff) || Double.IsNaN(lDiff) || Double.IsNaN(rDiff)) { logs.Add("Could not calculate containment"); return(false); } if ((tDiff > -1 && bDiff > -1 && lDiff > -1 && rDiff > -1) || (tDiff < 1 && bDiff < 1 && lDiff < 1 && rDiff < 1)) { result = true; } return(result); }