Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TestCuraSceneNode.py « tests - github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9e2fcb1188099f8a69a6f19c0cab4d866bc4a8f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from UM.Math.Polygon import Polygon
from UM.Scene.SceneNodeDecorator import SceneNodeDecorator
from cura.Scene.CuraSceneNode import CuraSceneNode
import pytest

from unittest.mock import patch


class MockedConvexHullDecorator(SceneNodeDecorator):
    def __init__(self):
        super().__init__()

    def getConvexHull(self):
        return Polygon([[5, 5], [-5, 5], [-5, -5], [5, -5]])

    def getPrintingArea(self):
        return Polygon([[5, 5], [-5, 5], [-5, -5], [5, -5]])


class InvalidConvexHullDecorator(SceneNodeDecorator):
    def __init__(self):
        super().__init__()

    def getConvexHull(self):
        return Polygon()


@pytest.fixture()
def cura_scene_node():
    # Replace the SettingOverrideDecorator with an empty decorator
    with patch("cura.Scene.CuraSceneNode.SettingOverrideDecorator", SceneNodeDecorator):
        return CuraSceneNode()


class TestCollidesWithAreas:
    def test_noConvexHull(self, cura_scene_node):
        assert not cura_scene_node.collidesWithAreas([Polygon([[10, 10], [-10, 10], [-10, -10], [10, -10]])])

    def test_convexHullIntersects(self, cura_scene_node):
        cura_scene_node.addDecorator(MockedConvexHullDecorator())
        assert cura_scene_node.collidesWithAreas([Polygon([[10, 10], [-10, 10], [-10, -10], [10, -10]])])

    def test_convexHullNoIntersection(self, cura_scene_node):
        cura_scene_node.addDecorator(MockedConvexHullDecorator())

        assert not cura_scene_node.collidesWithAreas([Polygon([[60, 60], [40, 60], [40, 40], [60, 40]])])

    def test_invalidConvexHull(self, cura_scene_node):
        cura_scene_node.addDecorator(InvalidConvexHullDecorator())
        assert not cura_scene_node.collidesWithAreas([Polygon([[10, 10], [-10, 10], [-10, -10], [10, -10]])])


def test_outsideBuildArea(cura_scene_node):
    cura_scene_node.setOutsideBuildArea(True)
    assert cura_scene_node.isOutsideBuildArea