Changeset 1641
- Timestamp:
- 07/16/07 09:57:46 (1 year ago)
- Files:
-
- gaphas/branches/hw/gaphas/constraint.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphas/branches/hw/gaphas/constraint.py
r1638 r1641 425 425 426 426 if self.balance is None: 427 b1, b2 = self.band 428 w = b2 - b1 429 if w != 0: 430 self.balance = (v - b1) / w 431 else: 432 self.balance = 0 427 self.update_balance() 428 429 430 def update_balance(self): 431 b1, b2 = self.band 432 w = b2 - b1 433 if w != 0: 434 self.balance = (self.v - b1) / w 435 else: 436 self.balance = 0 433 437 434 438 … … 456 460 self._point = point 457 461 458 self.update_ratio()459 460 462 461 463 def update_ratio(self): … … 465 467 >>> point = (Variable(15), Variable(4)) 466 468 >>> lc = LineConstraint(line=line, point=point) 469 >>> lc.update_ratio() 467 470 >>> lc.ratio_x, lc.ratio_y 468 471 (0.5, 0.20000000000000001) … … 499 502 >>> point = (Variable(15), Variable(4)) 500 503 >>> lc = LineConstraint(line=line, point=point) 504 >>> lc.update_ratio() 501 505 >>> lc.solve_for(point[0]) 502 506 >>> point … … 515 519 y = sy + (ey - sy) * self.ratio_y 516 520 517 px.value, py.value = x, y 521 if px.value != x: 522 px.value = x 523 if py.value != y: 524 py.value = y 518 525 519 526 … … 539 546 >>> bc = BalanceConstraint(band=(zero, r.width), v=v.x, balance=0.25) 540 547 >>> eq = EqualsConstraint(a=r.height, b=v.y) 541 >>> proj(bc, {v.x: v.x0, r.width: r.x0, zero: r.x0})542 >>> proj(eq, {v.y: v.y0, r.height: r.y0})548 >>> proj(bc, data={v.x: v.x0, r.width: r.x0, zero: r.x0}) 549 >>> proj(eq, data={v.y: v.y0, r.height: r.y0}) 543 550 544 551 Let's change rectangle dimensions … … 552 559 >>> v.x, v.y 553 560 (Variable(6, 20), Variable(-20, 20)) 561 562 It is also possible to use projection in case of other constraint's 563 methods than 'solve_for' 564 >>> r = Rectangle(5, 5, 20, 20) 565 >>> v = Vector(10, 50, 5, -25) 566 >>> zero = Variable(0) 567 >>> bc = BalanceConstraint(band=(zero, r.width), v=v.x) 568 >>> proj(bc, data={v.x: v.x0, r.width: r.x0, zero: r.x0}, f=bc.update_balance) 569 >>> bc.update_balance() 570 >>> bc.balance 571 0.5 554 572 """ 555 573 def _cproj(self): … … 569 587 def __call__(self, c, *args, **kw): 570 588 """ 571 Decorator for Constraint.solve_for method to perform 572 projection to common space before variable solving and later 573 project to internal variable space. 574 """ 575 f = c.solve_for 576 def wrapper(var): 589 Decorator for Constraint.solve_for method to perform projection to 590 common space before variable solving and later project to internal 591 variable space. 592 """ 593 if 'f' in kw: 594 f = kw['f'] 595 fn = f.__name__ 596 else: 597 f = c.solve_for 598 fn = 'solve_for' 599 600 def wrapper(*fargs): 577 601 self._cproj(c, *args, **kw) 578 f( var)602 f(*fargs) 579 603 self._iproj(c, *args, **kw) 580 c.solve_for = wrapper 604 605 setattr(c, fn, wrapper) 581 606 582 607
