File size: 1,553 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# SPDX-License-Identifier: LGPL-2.1-or-later

import FreeCAD as App
import Part

import unittest


class BRepTests(unittest.TestCase):

    def testProject(self):
        """
        This is a unit test for PR #13507
        """
        num = 18
        alt = [0, 1] * num
        pts = [App.Vector(i, alt[i], 0) for i in range(num)]

        bsc = Part.BSplineCurve()
        bsc.buildFromPoles(pts, False, 1)
        edge = bsc.toShape()

        rts = Part.RectangularTrimmedSurface(Part.Plane(), -50, 50, -50, 50)
        plane_shape = rts.toShape()

        proj = plane_shape.project([edge])
        self.assertFalse(proj.isNull())
        self.assertEqual(len(proj.Edges), 1)

    def testEdgeSplitFace(self):
        coords2d = [(0.5, -0.5), (1.0, -0.5), (1.0, 0.5), (0.5, 0.5)]
        pts2d = [App.Base.Vector2d(u, v) for u, v in coords2d]
        pts2d.append(pts2d[0])

        sphere = Part.Sphere()
        edges = []
        for i in range(1, len(pts2d)):
            ls = Part.Geom2d.Line2dSegment(pts2d[i - 1], pts2d[i])
            edges.append(ls.toShape(sphere))

        split = edges[0].split(0.25)
        new_edges = split.Edges + edges[1:]
        wire = Part.Wire(new_edges)
        face = Part.Face(wire, "Part::FaceMakerSimple")
        self.assertTrue(face.isValid())

    def testEdgeSplitReplace(self):
        cyl = Part.makeCylinder(2, 5)
        e1 = cyl.Edge3
        split = e1.split([1.0, 2.0])
        newcyl = cyl.replaceShape([(e1, split), (cyl.Vertex2, split.Vertex1)])
        self.assertTrue(newcyl.isValid())