예제 #1
0
    def test_identity(self):
        assert Cc.from_pt(1, 1).pt == (1, 1)
        assert Cc.from_in(1, 1).inches == (1, 1)
        assert Cc.from_cm(1, 1).cm == (1, 1)
        assert Cc.from_mm(1, 1).mm == (1, 1)
        assert Cc.from_px(1, 1).px == (1, 1)

        assert Cc.from_pt(2, 2).pt == (2, 2)
        assert Cc.from_in(2, 2).inches == (2, 2)
        assert Cc.from_cm(2, 2).cm == (2, 2)
        assert Cc.from_mm(2, 2).mm == (2, 2)
        assert Cc.from_px(2, 2).px == (2, 2)
    def test_multi_polygons(self):
        path = Path(__file__).parent.joinpath(
            'output/stripe_filled_polygon_drawer_multi_polygons.svg')
        path.unlink(missing_ok=True)
        canvas_builder = CanvasBuilder()
        canvas_builder.set_path(path)
        canvas_builder.set_size(Cu.from_pt(100), Cu.from_pt(100))

        canvas = canvas_builder.build()

        drawer = StripeFilledPolygonDrawer()
        drawer.stripe_colors = [(1, 1, 0), None, (0.7, 0, 0.7), (0, 0, 0)]
        drawer.stripe_widths = [
            Cu.from_pt(5),
            Cu.from_pt(5),
            Cu.from_pt(5),
            Cu.from_pt(5),
        ]
        drawer.stripe_origin = CanvasCoordinate.from_pt(30, 30)
        drawer.stripe_angle = math.pi / 8  # Vertical stripes
        drawer.geoms = [
            MultiPolygon([
                Polygon([
                    (30, 30),
                    (70, 30),
                    (70, 70),
                    (30, 70),
                    (30, 30),
                ], [[
                    (35, 35),
                    (65, 35),
                    (65, 65),
                    (35, 65),
                    (35, 35),
                ]]),
                Polygon([
                    (40, 40),
                    (60, 40),
                    (60, 60),
                    (40, 60),
                    (40, 40),
                ])
            ])
        ]
        drawer.draw(canvas)

        canvas.close()

        assert path.exists()

        with open(path, 'r') as file:
            data = file.read()
            assert data.find('fill:rgb(100%,100%,0%)') != -1
            assert data.find('fill:rgb(0%,0%,0%)') != -1
            assert data.find('fill:rgb(70%,0%,70%)') != -1
            assert data.find('stroke:none') != -1
            assert data.find('stroke-width:') == -1
    def test_two_vertical_stripes(self):
        path = Path(__file__).parent.joinpath(
            'output/stripe_filled_polygon_drawer_two_vertical_stripes.svg')
        path.unlink(missing_ok=True)
        canvas_builder = CanvasBuilder()
        canvas_builder.set_path(path)
        canvas_builder.set_size(Cu.from_pt(100), Cu.from_pt(100))

        canvas = canvas_builder.build()

        drawer = StripeFilledPolygonDrawer()
        drawer.stripe_colors = [(0, 1, 0), (0, 0, 1)]
        drawer.stripe_widths = [Cu.from_pt(20), Cu.from_pt(20)]
        drawer.stripe_origin = CanvasCoordinate.from_pt(30, 30)
        drawer.stripe_angle = math.pi / 2  # Vertical stripes
        drawer.geoms = [
            Polygon([
                (30, 30),
                (70, 30),
                (70, 70),
                (30, 70),
                (30, 30),
            ])
        ]
        drawer.draw(canvas)

        canvas.close()

        assert path.exists()

        with open(path, 'r') as file:
            data = file.read()
            assert data.find('M 30 30 L 30 70 L 50 70 L 50 30 Z M 30 30') != -1
            assert data.find('M 50 30 L 50 70 L 70 70 L 70 30 Z M 50 30') != -1
            assert data.find('fill:rgb(0%,100%,0%)') != -1
            assert data.find('fill:rgb(0%,0%,100%)') != -1
            assert data.find('stroke:none') != -1
            assert data.find('stroke-width:') == -1
예제 #4
0
 def test_comparisons(self):
     assert Cc.from_in(1, 1).pt[0] > Cc.from_cm(1, 1).pt[0]
     assert Cc.from_cm(1, 1).pt[0] > Cc.from_mm(1, 1).pt[0]
     assert Cc.from_mm(1, 1).pt[0] > Cc.from_pt(1, 1).pt[0]
예제 #5
0
 def test_eq(self):
     assert Cc.from_pt(1, 2) == Cc.from_pt(1, 2)
     assert Cc.from_pt(1, 2) != (1, 2)