From fc21d597a9b2d40f9ec0f4ea27dd0d1a2e9dd226 Mon Sep 17 00:00:00 2001 From: Roy-043 <70520633+Roy-043@users.noreply.github.com> Date: Wed, 9 Nov 2022 13:31:23 +0100 Subject: [PATCH] Draft: test_modification.py: modified test and added test (#7741) The old test_offset_closed function was renamed to test_offset_rectangle_with_face. It is now also a regression test for: #7670 The added test_offset_closed_with_reversed_edge function is a regression test for: #5496 --- src/Mod/Draft/drafttests/test_modification.py | 48 +++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/src/Mod/Draft/drafttests/test_modification.py b/src/Mod/Draft/drafttests/test_modification.py index a1e4138ef5..f32454a231 100644 --- a/src/Mod/Draft/drafttests/test_modification.py +++ b/src/Mod/Draft/drafttests/test_modification.py @@ -112,13 +112,13 @@ class DraftModification(unittest.TestCase): "'{}' failed".format(operation)) def test_offset_open(self): - """Create a wire, then produce an offset copy.""" + """Create an open wire, then produce an offset copy.""" operation = "Draft Offset" _msg(" Test '{}'".format(operation)) a = Vector(0, 2, 0) b = Vector(2, 4, 0) c = Vector(5, 2, 0) - _msg(" Wire") + _msg(" Open wire") _msg(" a={0}, b={1}".format(a, b)) _msg(" c={0}".format(c)) wire = Draft.make_wire([a, b, c]) @@ -130,22 +130,52 @@ class DraftModification(unittest.TestCase): obj = Draft.offset(wire, offset, copy=True) self.assertTrue(obj, "'{}' failed".format(operation)) - def test_offset_closed(self): - """Create a rectangle, then produce an offset copy.""" + def test_offset_closed_with_reversed_edge(self): + """Create a closed wire with a reversed edge, then produce an offset copy.""" + # Regression test for: + # https://github.com/FreeCAD/FreeCAD/pull/5496 operation = "Draft Offset" _msg(" Test '{}'".format(operation)) - length = 4 - width = 2 - _msg(" Rectangle") + _msg(" Closed wire with reversed edge") + a = Vector(0, 0, 0) + b = Vector(10, 0, 0) + c = Vector(10, 4, 0) + d = Vector(0, 4, 0) + edges = [Part.makeLine(a, b), + Part.makeLine(b, c), + Part.makeLine(c, d), + Part.makeLine(a, d)] + wire = Part.Wire(edges) + obj = App.ActiveDocument.addObject("Part::Feature") + obj.Shape = wire + + offset = Vector(0, -1, 0) + new = Draft.offset(obj, offset, copy=True) + self.assertTrue(len(new.Points) == 4, "'{}' failed".format(operation)) + + def test_offset_rectangle_with_face(self): + """Create a rectangle with a face, then produce an offset copy.""" + # Regression test for: + # https://github.com/FreeCAD/FreeCAD/pull/7670 + operation = "Draft Offset" + _msg(" Test '{}'".format(operation)) + length = 10 + width = 4 + _msg(" Rectangle with face") _msg(" length={0}, width={1}".format(length, width)) rect = Draft.make_rectangle(length, width) + rect.MakeFace = True App.ActiveDocument.recompute() - offset = Vector(-1, -1, 0) + offset = Vector(0, -1, 0) _msg(" Offset") _msg(" vector={}".format(offset)) obj = Draft.offset(rect, offset, copy=True) - self.assertTrue(obj, "'{}' failed".format(operation)) + App.ActiveDocument.recompute() + obj_is_ok = (obj.Shape.CenterOfGravity == Vector(5, 2, 0) + and obj.Length == 12 + and obj.Height == 6) + self.assertTrue(obj_is_ok, "'{}' failed".format(operation)) def test_trim(self): """Trim a line. NOT IMPLEMENTED."""