示例#1
0
    def _set_showing_image_index(self, idx: Optional[int]) -> None:
        if idx is None:
            return

        idx = clamp(idx, 0, self.bn_num_images.get() - 1)
        self._showing_image_index = idx
        self._update_showing_image()
示例#2
0
    def commit_define(self, end_pos: Vector2[float]) -> None:
        assert self.is_defining
        start_pos = self._begin_define_pos
        self._begin_define_pos = None

        region = Rect2(
            pt0=start_pos,
            pt1=end_pos,
        ).map(int)

        clip = self._bn_clip.get()

        if clip is not None:
            region = Rect2(
                x0=clamp(region.x0, clip.x0, clip.x1),
                y0=clamp(region.y0, clip.y0, clip.y1),
                x1=clamp(region.x1, clip.x0, clip.x1),
                y1=clamp(region.y1, clip.y0, clip.y1),
            )

        if region.w == 0 or region.h == 0:
            return

        self.bn_region.set(region)
示例#3
0
def test_clamp(x, lower, upper, expected):
    if math.isnan(expected):
        assert math.isnan(clamp(x, lower, upper))
    else:
        assert clamp(x, lower, upper) == expected