当前位置: 首页>>代码示例>>Python>>正文


Python Polygon.intersectsPolygon方法代码示例

本文整理汇总了Python中UM.Math.Polygon.Polygon.intersectsPolygon方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.intersectsPolygon方法的具体用法?Python Polygon.intersectsPolygon怎么用?Python Polygon.intersectsPolygon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UM.Math.Polygon.Polygon的用法示例。


在下文中一共展示了Polygon.intersectsPolygon方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_intersectsPolygon

# 需要导入模块: from UM.Math.Polygon import Polygon [as 别名]
# 或者: from UM.Math.Polygon.Polygon import intersectsPolygon [as 别名]
    def test_intersectsPolygon(self, data):
        p1 = Polygon(numpy.array([ #The base polygon to intersect with.
            [ 0,  0],
            [10,  0],
            [10, 10],
            [ 0, 10]
        ], numpy.float32))
        p2 = Polygon(numpy.array(data["polygon"])) #The parametrised polygon to intersect with.

        #Shift the order of vertices in both polygons around. The outcome should be independent of what the first vertex is.
        for n in range(0, len(p1.getPoints())):
            for m in range(0, len(data["polygon"])):
                result = p1.intersectsPolygon(p2)
                if not data["answer"]: #Result should be None.
                    assert result == None
                else:
                    assert result != None
                    for i in range(0, len(data["answer"])):
                        assert Float.fuzzyCompare(result[i], data["answer"][i])
                p2.setPoints(numpy.roll(p2.getPoints(), 1, axis = 0)) #Shift p2.
            p1.setPoints(numpy.roll(p1.getPoints(), 1, axis = 0)) #Shift p1.
开发者ID:senttech,项目名称:Uranium,代码行数:23,代码来源:TestPolygon.py

示例2: BuildVolume

# 需要导入模块: from UM.Math.Polygon import Polygon [as 别名]
# 或者: from UM.Math.Polygon.Polygon import intersectsPolygon [as 别名]

#.........这里部分代码省略.........
                [prime_x - PRIME_CLEARANCE, prime_y - PRIME_CLEARANCE],
                [prime_x + PRIME_CLEARANCE, prime_y - PRIME_CLEARANCE],
                [prime_x + PRIME_CLEARANCE, prime_y + PRIME_CLEARANCE],
                [prime_x - PRIME_CLEARANCE, prime_y + PRIME_CLEARANCE],
            ])

        bed_adhesion_size = self._getBedAdhesionSize(self._global_container_stack)

        if disallowed_areas:
            # Extend every area already in the disallowed_areas with the skirt size.
            for area in disallowed_areas:
                poly = Polygon(numpy.array(area, numpy.float32))
                poly = poly.getMinkowskiHull(Polygon(approximatedCircleVertices(bed_adhesion_size)))

                areas.append(poly)

        if self._prime_tower_area:
            self._prime_tower_area = self._prime_tower_area.getMinkowskiHull(Polygon(approximatedCircleVertices(bed_adhesion_size)))

        # Add the skirt areas around the borders of the build plate.
        if bed_adhesion_size > 0:
            half_machine_width = self._global_container_stack.getProperty("machine_width", "value") / 2
            half_machine_depth = self._global_container_stack.getProperty("machine_depth", "value") / 2

            areas.append(Polygon(numpy.array([
                [-half_machine_width, -half_machine_depth],
                [-half_machine_width, half_machine_depth],
                [-half_machine_width + bed_adhesion_size, half_machine_depth - bed_adhesion_size],
                [-half_machine_width + bed_adhesion_size, -half_machine_depth + bed_adhesion_size]
            ], numpy.float32)))

            areas.append(Polygon(numpy.array([
                [half_machine_width, half_machine_depth],
                [half_machine_width, -half_machine_depth],
                [half_machine_width - bed_adhesion_size, -half_machine_depth + bed_adhesion_size],
                [half_machine_width - bed_adhesion_size, half_machine_depth - bed_adhesion_size]
            ], numpy.float32)))

            areas.append(Polygon(numpy.array([
                [-half_machine_width, half_machine_depth],
                [half_machine_width, half_machine_depth],
                [half_machine_width - bed_adhesion_size, half_machine_depth - bed_adhesion_size],
                [-half_machine_width + bed_adhesion_size, half_machine_depth - bed_adhesion_size]
            ], numpy.float32)))

            areas.append(Polygon(numpy.array([
                [half_machine_width, -half_machine_depth],
                [-half_machine_width, -half_machine_depth],
                [-half_machine_width + bed_adhesion_size, -half_machine_depth + bed_adhesion_size],
                [half_machine_width - bed_adhesion_size, -half_machine_depth + bed_adhesion_size]
            ], numpy.float32)))

        # Check if the prime tower area intersects with any of the other areas.
        # If this is the case, keep the polygon seperate, so it can be drawn in red.
        # If not, add it back to disallowed area's, so it's rendered as normal.
        collision = False
        if self._prime_tower_area:
            for area in areas:
                if self._prime_tower_area.intersectsPolygon(area) is not None:
                    collision = True
                    break
            if not collision:
                areas.append(self._prime_tower_area)
                self._prime_tower_area = None
        self._has_errors = collision
        self._disallowed_areas = areas

    ##  Convenience function to calculate the size of the bed adhesion in directions x, y.
    def _getBedAdhesionSize(self, container_stack):
        skirt_size = 0.0

        # If we are printing one at a time, we need to add the bed adhesion size to the disallowed areas of the objects
        if container_stack.getProperty("print_sequence", "value") == "one_at_a_time":
            return 0.1  # Return a very small value, so we do draw disallowed area's near the edges.

        adhesion_type = container_stack.getProperty("adhesion_type", "value")
        if adhesion_type == "skirt":
            skirt_distance = container_stack.getProperty("skirt_gap", "value")
            skirt_line_count = container_stack.getProperty("skirt_line_count", "value")
            skirt_size = skirt_distance + (skirt_line_count * container_stack.getProperty("skirt_brim_line_width", "value"))
        elif adhesion_type == "brim":
            skirt_size = container_stack.getProperty("brim_line_count", "value") * container_stack.getProperty("skirt_brim_line_width", "value")
        elif adhesion_type == "raft":
            skirt_size = container_stack.getProperty("raft_margin", "value")

        if container_stack.getProperty("draft_shield_enabled", "value"):
            skirt_size += container_stack.getProperty("draft_shield_dist", "value")

        if container_stack.getProperty("xy_offset", "value"):
            skirt_size += container_stack.getProperty("xy_offset", "value")

        return skirt_size

    def _clamp(self, value, min_value, max_value):
        return max(min(value, max_value), min_value)

    _skirt_settings = ["adhesion_type", "skirt_gap", "skirt_line_count", "skirt_brim_line_width", "brim_width", "brim_line_count", "raft_margin", "draft_shield_enabled", "draft_shield_dist", "xy_offset"]
    _raft_settings = ["adhesion_type", "raft_base_thickness", "raft_interface_thickness", "raft_surface_layers", "raft_surface_thickness", "raft_airgap"]
    _prime_settings = ["extruder_prime_pos_x", "extruder_prime_pos_y", "extruder_prime_pos_z"]
    _tower_settings = ["prime_tower_enable", "prime_tower_size", "prime_tower_position_x", "prime_tower_position_y"]
开发者ID:msutas,项目名称:Cura-1,代码行数:104,代码来源:BuildVolume.py

示例3: test_intersectsPolygon

# 需要导入模块: from UM.Math.Polygon import Polygon [as 别名]
# 或者: from UM.Math.Polygon.Polygon import intersectsPolygon [as 别名]
    def test_intersectsPolygon(self):
        p1 = Polygon(numpy.array([
            [0.0, 0.0],
            [1.0, 0.0],
            [1.0, 1.0],
            [0.0, 1.0]
        ], numpy.float32))

        p2 = Polygon(numpy.array([
            [0.5, 0.5],
            [1.5, 0.5],
            [1.5, 1.5],
            [0.5, 1.5]
        ], numpy.float32))
        result = p1.intersectsPolygon(p2)
        print(result)

        p2 = Polygon(numpy.array([
            [2.5, 2.5],
            [3.5, 2.5],
            [3.5, 3.5],
            [2.5, 3.5]
        ], numpy.float32))
        result = p1.intersectsPolygon(p2)
        print(result)

        p1 = Polygon(numpy.array([
            [0, 0],
            [10, 0],
            [10, 10],
            [0, 10]
        ], numpy.float32))

        p2 = Polygon(numpy.array([
            [5, 5],
            [15, 5],
            [15, 15],
            [5, 15]
        ], numpy.float32))
        result = p1.intersectsPolygon(p2)
        print(result)

        p2 = Polygon(numpy.array([
            [5, 5],
            [5, 15],
            [-10, 15],
            [-10, 5]
        ], numpy.float32))
        result = p1.intersectsPolygon(p2)
        print(result)

        p2 = Polygon(numpy.array([
            [2.5, 7.5],
            [7.5, 7.5],
            [7.5, 15.0],
            [2.5, 15.0]
        ]))
        result = p1.intersectsPolygon(p2)
        print(result)

        p2 = Polygon(numpy.array([
            [2.5, 7.5],
            [-2.5, 7.5],
            [-2.5, -5.0],
            [2.5, -5.0]
        ]))
        result = p1.intersectsPolygon(p2)
        print(result)
开发者ID:derekhe,项目名称:Uranium,代码行数:70,代码来源:TestPolygon.py


注:本文中的UM.Math.Polygon.Polygon.intersectsPolygon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。