Rectangle.st
changeset 18892 89fe764ff616
parent 18820 8f1b263c8435
child 18895 223497b63b36
equal deleted inserted replaced
18891:2f7a57a236c8 18892:89fe764ff616
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "
     3 "
     2  COPYRIGHT (c) 1989 by Claus Gittinger
     4  COPYRIGHT (c) 1989 by Claus Gittinger
     3 	      All Rights Reserved
     5 	      All Rights Reserved
     4 
     6 
     5  This software is furnished under a license and may be used
     7  This software is furnished under a license and may be used
  1806      r2 := r1 scaledBy:2.    
  1808      r2 := r1 scaledBy:2.    
  1807      r1  
  1809      r1  
  1808     "
  1810     "
  1809 !
  1811 !
  1810 
  1812 
       
  1813 scaledBy:scale translatedBy:translation 
       
  1814     "return a new rectangle which is translated (i.e. moved)
       
  1815      by translation, aPoint or Number and scaled by scale, aPoint or number."
       
  1816 
       
  1817     |x y w h translationPoint scalePoint sx sy|
       
  1818 
       
  1819     (translation isNil and:[scale isNil]) ifTrue:[
       
  1820         ^ self.
       
  1821     ].
       
  1822 
       
  1823     x := left.
       
  1824     y := top.
       
  1825     w := width.
       
  1826     h := height.
       
  1827 
       
  1828     scale notNil ifTrue:[
       
  1829         (scale isMemberOf:SmallInteger) ifTrue:[
       
  1830             "/ this is an stc optimization
       
  1831             x := x * scale.
       
  1832             y := y * scale.
       
  1833             w := w * scale.
       
  1834             h := h * scale.
       
  1835         ] ifFalse:[
       
  1836             scalePoint := scale asPoint.
       
  1837             sx := scalePoint x.
       
  1838             sy := scalePoint y.
       
  1839             x := x * sx.
       
  1840             y := y * sy.
       
  1841             w := w * sx.
       
  1842             h := h * sy.
       
  1843         ].
       
  1844     ].
       
  1845     translation notNil ifTrue:[
       
  1846         (translation isMemberOf:SmallInteger) ifTrue:[
       
  1847             "/ this is an stc optimization
       
  1848             x := x + translation.
       
  1849             y := y + translation.
       
  1850         ] ifFalse:[
       
  1851             translationPoint := translation asPoint.
       
  1852             x := x + translationPoint x.
       
  1853             y := y + translationPoint y.
       
  1854         ].
       
  1855     ].
       
  1856 
       
  1857     ^ Rectangle left:x top:y width:w height:h.
       
  1858 
       
  1859     "
       
  1860      (Rectangle origin:10@10 corner:50@50) translatedBy:10 scaledBy:2
       
  1861     "
       
  1862 !
       
  1863 
  1811 translatedBy:amount
  1864 translatedBy:amount
  1812     "return a new rectangle which is translated (i.e. moved)
  1865     "return a new rectangle which is translated (i.e. moved)
  1813      by amount, aPoint or Number"
  1866      by amount, aPoint or Number"
  1814 
  1867 
  1815     |amountPoint|
  1868     |amountPoint|
  1816 
  1869 
       
  1870     (amount isMemberOf:SmallInteger) ifTrue:[
       
  1871         "/ this is an stc optimization
       
  1872         ^ Rectangle 
       
  1873             left:(left + amount)
       
  1874             top:(top + amount)
       
  1875             width:width
       
  1876             height:height
       
  1877     ].
       
  1878 
  1817     amountPoint := amount asPoint.
  1879     amountPoint := amount asPoint.
  1818     ^ Rectangle left:(left + amountPoint x) 
  1880     ^ Rectangle left:(left + amountPoint x) 
  1819 		 top:(top + amountPoint y)
  1881                  top:(top + amountPoint y)
  1820 	       width:width
  1882                width:width
  1821 	      height:height
  1883               height:height
  1822     "
  1884     "
  1823      (Rectangle origin:10@10 corner:50@50) translatedBy:10
  1885      (Rectangle origin:10@10 corner:50@50) translatedBy:10
  1824     "
  1886     "
  1825 
  1887 
  1826     "its NOT destructive:"
  1888     "its NOT destructive:"