Changeset 1882
- Timestamp:
- 08/09/07 01:34:16 (1 year ago)
- Files:
-
- gaphas/trunk/gaphas/item.py (modified) (7 diffs)
- gaphas/trunk/gaphas/solver.py (modified) (1 diff)
- gaphas/trunk/undo.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphas/trunk/gaphas/item.py
r1840 r1882 530 530 The min number of parts is 2. 531 531 532 A list of new handles is returned. 533 534 Note that ``split_segment`` is not able to reconnect constraints that 535 are connected to the segment. 536 532 537 >>> a = Line() 533 538 >>> a.handles()[1].pos = (20, 0) … … 535 540 2 536 541 >>> a.split_segment(0) 537 >>> len(a.handles()) 538 3 539 >>> a.handles()[1] 540 <Handle object on (10, 0)> 542 [<Handle object on (10, 0)>] 543 >>> a.handles() 544 [<Handle object on (0, 0)>, <Handle object on (10, 0)>, <Handle object on (20, 0)>] 545 546 A line segment can be split into multiple (equal) parts: 547 541 548 >>> b = Line() 542 549 >>> b.handles()[1].pos = (20, 16) … … 544 551 [<Handle object on (0, 0)>, <Handle object on (20, 16)>] 545 552 >>> b.split_segment(0, parts=4) 553 [<Handle object on (5, 4)>, <Handle object on (10, 8)>, <Handle object on (15, 12)>] 546 554 >>> len(b.handles()) 547 555 5 … … 561 569 do_split(segment + 1, parts - 1) 562 570 do_split(segment, parts) 571 # TODO: or reconnect them from here. 572 # Force orthogonal constraints to be recreated 563 573 self.orthogonal = self.orthogonal 574 return self._handles[segment+1:segment+parts] 564 575 565 576 @observed … … 569 580 The parts parameter indicates how many segments should be merged 570 581 582 The deleted handles are returned as a list. 583 571 584 >>> a = Line() 572 585 >>> a.handles()[1].pos = (20, 0) 573 >>> a.split_segment(0)586 >>> _ = a.split_segment(0) 574 587 >>> a.handles() 575 588 [<Handle object on (0, 0)>, <Handle object on (10, 0)>, <Handle object on (20, 0)>] 576 589 >>> a.merge_segment(0) 577 >>> len(a.handles()) 578 2 590 [<Handle object on (10, 0)>] 591 >>> a.handles() 592 [<Handle object on (0, 0)>, <Handle object on (20, 0)>] 579 593 >>> try: a.merge_segment(0) 580 594 ... except AssertionError: print 'okay' 581 595 okay 596 597 More than two segments can be merged at once: 598 >>> _ = a.split_segment(0) 599 >>> _ = a.split_segment(0) 600 >>> _ = a.split_segment(0) 601 >>> a.handles() 602 [<Handle object on (0, 0)>, <Handle object on (2.5, 0)>, <Handle object on (5, 0)>, <Handle object on (10, 0)>, <Handle object on (20, 0)>] 603 >>> a.merge_segment(0, parts=4) 604 [<Handle object on (2.5, 0)>, <Handle object on (5, 0)>, <Handle object on (10, 0)>] 605 >>> a.handles() 606 [<Handle object on (0, 0)>, <Handle object on (20, 0)>] 582 607 """ 583 608 assert len(self._handles) > 2, 'Not enough segments' … … 585 610 raise IndexError("index out of range (0 > %d > %d)" % (segment, len(self._handles) - 1)) 586 611 if segment == 0: segment = 1 612 deleted_handles = [self._handles[segment]] 587 613 del self._handles[segment] 588 614 if parts > 2: 589 merge_segment(segment, parts - 1)615 deleted_handles.extend(self.merge_segment(segment, parts - 1)) 590 616 else: 591 617 # Force orthogonal constraints to be recreated 592 618 self.orthogonal = self.orthogonal 619 return deleted_handles 593 620 594 621 reversible_pair(split_segment, merge_segment) … … 639 666 >>> a.handles()[1].pos = 30, 30 640 667 >>> a.split_segment(0) 668 [<Handle object on (15, 15)>] 641 669 >>> a.handles()[1].pos = 25, 5 642 670 >>> a.point(-1, 0) gaphas/trunk/gaphas/solver.py
r1881 r1882 532 532 False 533 533 """ 534 # use a copy of the original set, so constraints may be deleted in the535 # meantime.534 # Use a copy of the original set, so constraints may be 535 # deleted in the meantime. 536 536 variables = set(variables) 537 537 for c in set(self._constraints): gaphas/trunk/undo.txt
r1803 r1882 377 377 378 378 >>> l.split_segment(0) 379 [<Handle object on (5, 5)>] 379 380 >>> l.handles() 380 381 [<Handle object on (0, 0)>, <Handle object on (5, 5)>, <Handle object on (10, 10)>]
