creatumlibre.graphics.selection.selection
1class Selection: 2 """Handles selection areas within an image.""" 3 4 def __init__(self, x=100, y=100, width=300, height=200): 5 self.x = x 6 self.y = y 7 self.width = width 8 self.height = height 9 10 def get_rect(self): 11 """Returns the selection rectangle as a tuple.""" 12 return (self.x, self.y, self.width, self.height) 13 14 def set_rect(self, x, y, width, height): 15 """Update the selection rectangle.""" 16 self.x = x 17 self.y = y 18 self.width = width 19 self.height = height 20 print(f"{x} {y} {width} {height}") 21 22 def get_region(self, image): 23 """Extract the selected region from an image.""" 24 x, y, w, h = self.get_rect() 25 return image[y : y + h, x : x + w].copy() # Encapsulated selection extraction 26 27 def set_region(self, image, modified_region): 28 """Place the modified region back into the image.""" 29 x, y, w, h = self.get_rect() 30 image[y : y + h, x : x + w] = modified_region # Encapsulated region placement 31 return image 32 33 def contains_point(self, px, py): 34 """Check if a point is inside the selection.""" 35 return ( 36 self.x <= px <= self.x + self.width and self.y <= py <= self.y + self.height 37 )
class
Selection:
2class Selection: 3 """Handles selection areas within an image.""" 4 5 def __init__(self, x=100, y=100, width=300, height=200): 6 self.x = x 7 self.y = y 8 self.width = width 9 self.height = height 10 11 def get_rect(self): 12 """Returns the selection rectangle as a tuple.""" 13 return (self.x, self.y, self.width, self.height) 14 15 def set_rect(self, x, y, width, height): 16 """Update the selection rectangle.""" 17 self.x = x 18 self.y = y 19 self.width = width 20 self.height = height 21 print(f"{x} {y} {width} {height}") 22 23 def get_region(self, image): 24 """Extract the selected region from an image.""" 25 x, y, w, h = self.get_rect() 26 return image[y : y + h, x : x + w].copy() # Encapsulated selection extraction 27 28 def set_region(self, image, modified_region): 29 """Place the modified region back into the image.""" 30 x, y, w, h = self.get_rect() 31 image[y : y + h, x : x + w] = modified_region # Encapsulated region placement 32 return image 33 34 def contains_point(self, px, py): 35 """Check if a point is inside the selection.""" 36 return ( 37 self.x <= px <= self.x + self.width and self.y <= py <= self.y + self.height 38 )
Handles selection areas within an image.
def
get_rect(self):
11 def get_rect(self): 12 """Returns the selection rectangle as a tuple.""" 13 return (self.x, self.y, self.width, self.height)
Returns the selection rectangle as a tuple.
def
set_rect(self, x, y, width, height):
15 def set_rect(self, x, y, width, height): 16 """Update the selection rectangle.""" 17 self.x = x 18 self.y = y 19 self.width = width 20 self.height = height 21 print(f"{x} {y} {width} {height}")
Update the selection rectangle.
def
get_region(self, image):
23 def get_region(self, image): 24 """Extract the selected region from an image.""" 25 x, y, w, h = self.get_rect() 26 return image[y : y + h, x : x + w].copy() # Encapsulated selection extraction
Extract the selected region from an image.
def
set_region(self, image, modified_region):
28 def set_region(self, image, modified_region): 29 """Place the modified region back into the image.""" 30 x, y, w, h = self.get_rect() 31 image[y : y + h, x : x + w] = modified_region # Encapsulated region placement 32 return image
Place the modified region back into the image.