How to use the vector.Vector.vectorize function in vector

To help you get started, we’ve selected a few vector 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 Kobzol / debug-visualizer / gui / drawing / drawable.py View on Github external
def draw_arrow(canvas, point_from, point_to, color=Color(), width=1.0):
        """
        @type canvas: drawing.canvas.Canvas
        @type point_from: vector.Vector
        @type point_to: vector.Vector
        @type color: Color
        @type width: float
        """
        point_from = Vector.vectorize(point_from)
        point_to = Vector.vectorize(point_to)

        DrawingUtils.draw_line(canvas, point_from, point_to, color, width)

        vec_arrow = point_to.sub(point_from)

        wing = vec_arrow.inverse().normalized().scaled(10)
        wing_right = wing.rotate(45)
        wing_left = wing.rotate(-45)

        DrawingUtils.draw_line(canvas, point_to,
                               wing_right.add(point_to), color,
                               width)
        DrawingUtils.draw_line(canvas, point_to,
                               wing_left.add(point_to), color,
                               width)
github Kobzol / debug-visualizer / gui / drawing / drawable.py View on Github external
def draw_image_from_surface(canvas, position, img, size=None,
                                center=False):
        """
        Draws an image given by a cairo.ImageSurface object.
        @type canvas: canvas.Canvas
        @type position: vector.Vector
        @type img: cairo.ImageSurface
        @type size: size.Size
        @type center: boolean
        """
        if not size:
            size = Size(img.get_width(), img.get_height())
        else:
            size = Size.make_size(size)

        position = Vector.vectorize(position)
        width = img.get_width()
        height = img.get_height()

        cr = canvas.cr

        cr.save()

        if center:
            cr.translate(position.x - size.width / 2.0,
                         position.y - size.height / 2.0)
        else:
            cr.translate(position.x, position.y)

        x_ratio = float(size.width) / width
        y_ratio = float(size.height) / height
        cr.scale(x_ratio, y_ratio)
github Kobzol / debug-visualizer / gui / drawing / geometry.py View on Github external
def __init__(self, position=(0, 0), size=(0, 0)):
        self.position = Vector.vectorize(position)
        self.size = Size.make_size(size)

        self.x = self.position.x
        self.y = self.position.y
        self.width = self.size.width
        self.height = self.size.height
github Kobzol / debug-visualizer / gui / drawing / drawable.py View on Github external
def draw_arrow(canvas, point_from, point_to, color=Color(), width=1.0):
        """
        @type canvas: drawing.canvas.Canvas
        @type point_from: vector.Vector
        @type point_to: vector.Vector
        @type color: Color
        @type width: float
        """
        point_from = Vector.vectorize(point_from)
        point_to = Vector.vectorize(point_to)

        DrawingUtils.draw_line(canvas, point_from, point_to, color, width)

        vec_arrow = point_to.sub(point_from)

        wing = vec_arrow.inverse().normalized().scaled(10)
        wing_right = wing.rotate(45)
        wing_left = wing.rotate(-45)

        DrawingUtils.draw_line(canvas, point_to,
                               wing_right.add(point_to), color,
                               width)
        DrawingUtils.draw_line(canvas, point_to,
                               wing_left.add(point_to), color,
                               width)
github Kobzol / debug-visualizer / gui / drawing / drawable.py View on Github external
def __init__(self, canvas, **properties):
        """
        @type canvas: drawing.canvas.Canvas
        """
        self.canvas = canvas

        self._position = self._parse_property(properties, "position",
                                              Vector(0, 0), Vector.vectorize)
        """@type _position: drawing.vector.Vector"""
        self._margin = self._parse_property(properties, "margin",
                                            Margin.all(0))
        """@type _margin: drawing.geometry.Margin"""
        self._padding = self._parse_property(properties, "padding",
                                             Padding.all(0))
        """@type _padding: drawing.geometry.Padding"""
        self._request_size = self._parse_property(properties, "size",
                                                  Size(-1, -1), Size.make_size)
        """@type _request_size: drawing.size.Size"""
        self._min_size = self._parse_property(properties, "min_size",
                                              Size(0, 0), Size.make_size)
        """@type _min_size: drawing.size.Size"""
        self._max_size = self._parse_property(properties, "max_size",
                                              Size(999, 999), Size.make_size)
        """@type _max_size: drawing.size.Size"""
github Kobzol / debug-visualizer / gui / drawing / drawable.py View on Github external
def draw_line(canvas, point_from, point_to, color=Color(), width=1.0):
        """
        @type canvas: drawing.canvas.Canvas
        @type point_from: drawing.vector.Vector
        @type point_to: drawing.vector.Vector
        @type color: Color
        @type width: float
        """
        cr = canvas.cr
        cr.save()

        point_from = Vector.vectorize(point_from)
        point_to = Vector.vectorize(point_to)

        DrawingUtils.set_color(canvas, color)
        cr.set_line_width(width)

        cr.move_to(point_from.x, point_from.y)
        cr.line_to(point_to.x, point_to.y)
        cr.stroke()

        cr.restore()