How to use the pycaption.geometry.Point function in pycaption

To help you get started, we’ve selected a few pycaption examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pbs / pycaption / tests / test_geometry.py View on Github external
def test_point_is_relative(self):
        size_px = Size(30, UnitEnum.PIXEL)
        size_px2 = Size(30, UnitEnum.PIXEL)

        size_percent = Size(30, UnitEnum.PERCENT)
        size_percent2 = Size(30, UnitEnum.PERCENT)

        point_abs = Point(size_px, size_px2)
        point_mix = Point(size_percent, size_px)
        point_rel = Point(size_percent, size_percent2)

        self.assertFalse(point_abs.is_relative())
        self.assertFalse(point_mix.is_relative())
        self.assertTrue(point_rel.is_relative())
github pbs / pycaption / tests / test_geometry.py View on Github external
def test_point_is_valid(self):
        with self.assertRaises(TypeError):
            Point()

        with self.assertRaises(ValueError):
            Point(None, None)
github pbs / pycaption / tests / test_geometry.py View on Github external
def test_point_is_relative(self):
        size_px = Size(30, UnitEnum.PIXEL)
        size_px2 = Size(30, UnitEnum.PIXEL)

        size_percent = Size(30, UnitEnum.PERCENT)
        size_percent2 = Size(30, UnitEnum.PERCENT)

        point_abs = Point(size_px, size_px2)
        point_mix = Point(size_percent, size_px)
        point_rel = Point(size_percent, size_percent2)

        self.assertFalse(point_abs.is_relative())
        self.assertFalse(point_mix.is_relative())
        self.assertTrue(point_rel.is_relative())
github pbs / pycaption / tests / test_geometry.py View on Github external
def test_point_is_relative(self):
        size_px = Size(30, UnitEnum.PIXEL)
        size_px2 = Size(30, UnitEnum.PIXEL)

        size_percent = Size(30, UnitEnum.PERCENT)
        size_percent2 = Size(30, UnitEnum.PERCENT)

        point_abs = Point(size_px, size_px2)
        point_mix = Point(size_percent, size_px)
        point_rel = Point(size_percent, size_percent2)

        self.assertFalse(point_abs.is_relative())
        self.assertFalse(point_mix.is_relative())
        self.assertTrue(point_rel.is_relative())
github pbs / pycaption / pycaption / scc / specialized_collections.py View on Github external
The row can have a value from 1 to 15 inclusive. (vertical positioning)
    The column can have a value from 0 to 31 inclusive. (horizontal)

    :param position_tuple: a tuple of ints (row, col)
    :type position_tuple: tuple
    :rtype: Layout
    """
    if not position_tuple:
        return None

    row, column = position_tuple

    horizontal = Size(100 * column / 32.0, UnitEnum.PERCENT)
    vertical = Size(100 * (row - 1) / 15.0, UnitEnum.PERCENT)
    return Layout(origin=Point(horizontal, vertical),
                  alignment=Alignment(HorizontalAlignmentEnum.LEFT,
                                      VerticalAlignmentEnum.TOP)
                  )
github pbs / pycaption / pycaption / geometry.py View on Github external
def as_percentage_of(self, video_width, video_height):
        """
        Converts absolute units (e.g. px, pt etc) to percentage
        """
        return Point(
            self.x.as_percentage_of(video_width=video_width),
            self.y.as_percentage_of(video_height=video_height)
        )
github pbs / pycaption / pycaption / dfxp / base.py View on Github external
element itself.

        If the attributes can't be determined, default values are returned
        (where such values exist) - XXX this is incorrect. No default values
        should be provided.

        :param element: BeautifulSoup Tag or NavigableString
        :type even_invalid: bool
        :param even_invalid: if True, will search attributes on the element
            (when they really should be checked only on the region)
        :rtype: tuple
        """
        usable_elem = element if even_invalid else None

        origin = self._find_attribute(
            usable_elem, 'tts:origin', Point.from_xml_attribute, ['auto']
        ) or DFXP_DEFAULT_REGION.origin

        extent = self._find_attribute(
            usable_elem, 'tts:extent', Stretch.from_xml_attribute, ['auto'])

        if not extent:
            extent = self._find_root_extent() or DFXP_DEFAULT_REGION.extent

        padding = self._find_attribute(
            usable_elem, 'tts:padding', Padding.from_xml_attribute
        ) or DFXP_DEFAULT_REGION.padding

        # tts:textAlign is a special attribute, which can not be ignored when
        # specified on the element itself (only <p> nodes matter)
        # On elements like <span> it is also read, because this was legacy
        # behavior.</span></p>
github pbs / pycaption / pycaption / geometry.py View on Github external
def add_stretch(self, stretch):
        """Returns another Point instance, whose coordinates are the sum of the
         current Point's, and the Stretch instance's.
        """
        return Point(self.x + stretch.horizontal, self.y + stretch.vertical)
github pbs / pycaption / pycaption / geometry.py View on Github external
def lower_right_point(self):
        """The point furthest from the origin from the rectangle's 4 points
        """
        if hasattr(self, '_p2'):
            return Point.align_from_origin(self._p1, self._p2)[1]
        else:
            return self.origin.add_extent(self.extent)
github pbs / pycaption / pycaption / geometry.py View on Github external
def align_from_origin(cls, p1, p2):
        """Returns a tuple of 2 points. The first is closest to the origin
        on both axes than the second.

        If the 2 points fulfill this condition, returns them (ordered), if not,
        creates 2 new points.
        """
        if p1.x &lt;= p2.x and p1.y &lt;= p2.y:
            return p1
        if p1.x &gt;= p2.x and p1.y &gt;= p2.y:
            return p2
        else:
            return (Point(min(p1.x, p2.x), min(p1.y, p2.y)),
                    Point(max(p1.x, p2.x), max(p1.y, p2.y)))