From 0dc724405b79731972700906cc08a3985335311a Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Tue, 23 Dec 2025 09:05:36 +0100 Subject: [PATCH] Add minimum crop size and border detection constants to VideoEditor class Introduce CROP_MIN_SIZE and CROP_BORDER_DETECTION_MAX_DISTANCE constants for better maintainability and clarity in crop adjustment logic. Update crop resizing logic to utilize these constants, ensuring consistent minimum dimensions and border detection thresholds across the VideoEditor functionality. --- croppa/main.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/croppa/main.py b/croppa/main.py index 13b166d..6503ec5 100644 --- a/croppa/main.py +++ b/croppa/main.py @@ -757,6 +757,8 @@ class VideoEditor: # Crop adjustment settings CROP_SIZE_STEP = 5 # pixels to expand/contract crop + CROP_MIN_SIZE = 10 # minimum crop width/height in pixels + CROP_BORDER_DETECTION_MAX_DISTANCE = 800 # pixels - maximum distance for border hit detection # Motion tracking settings TRACKING_POINT_THRESHOLD = 10 # pixels for delete/snap radius @@ -3773,7 +3775,7 @@ class VideoEditor: # Handle crop border dragging (only when Shift and Ctrl are NOT pressed) if not (flags & cv2.EVENT_FLAG_SHIFTKEY) and not (flags & cv2.EVENT_FLAG_CTRLKEY) and self.crop_rect: - border_threshold = 800 # pixels - maximum distance to consider + border_threshold = self.CROP_BORDER_DETECTION_MAX_DISTANCE # Get effective crop in rotated coords and map to screen eff_x, eff_y, eff_w, eff_h = self._get_effective_crop_rect_for_frame(getattr(self, 'current_frame', 0)) @@ -4351,7 +4353,7 @@ class VideoEditor: self.crop_rect = (x, new_y, w, new_h) else: # Contract from bottom - decrease height - new_h = max(10, h - amount) # Minimum size of 10 pixels + new_h = max(self.CROP_MIN_SIZE, h - amount) self.crop_rect = (x, y, w, new_h) elif direction == 'down': @@ -4361,7 +4363,7 @@ class VideoEditor: self.crop_rect = (x, y, w, new_h) else: # Contract from top - increase y, decrease height - amount = min(amount, h - 10) # Don't make it smaller than 10 pixels + amount = min(amount, h - self.CROP_MIN_SIZE) # Don't make it smaller than 10 pixels new_y = y + amount new_h = h - amount self.crop_rect = (x, new_y, w, new_h) @@ -4374,7 +4376,7 @@ class VideoEditor: self.crop_rect = (new_x, y, new_w, h) else: # Contract from right - decrease width - new_w = max(10, w - amount) # Minimum size of 10 pixels + new_w = max(self.CROP_MIN_SIZE, w - amount) self.crop_rect = (x, y, new_w, h) elif direction == 'right': @@ -4384,7 +4386,7 @@ class VideoEditor: self.crop_rect = (x, y, new_w, h) else: # Contract from left - increase x, decrease width - amount = min(amount, w - 10) # Don't make it smaller than 10 pixels + amount = min(amount, w - self.CROP_MIN_SIZE) # Don't make it smaller than 10 pixels new_x = x + amount new_w = w - amount self.crop_rect = (new_x, y, new_w, h)