class: Geometric
authorClaus Gittinger <cg@exept.de>
Sat, 31 Aug 2013 13:46:29 +0200
changeset 15729 72bb494f9a13
parent 15728 68b68fafbd79
child 15730 4013efc6649a
class: Geometric added:8 methods for aligning geometric objects
Geometric.st
--- a/Geometric.st	Sat Aug 31 09:29:11 2013 +0200
+++ b/Geometric.st	Sat Aug 31 13:46:29 2013 +0200
@@ -504,6 +504,133 @@
 
 !Geometric methodsFor:'transformations'!
 
+align:offset with:someCoordinate
+    self subclassResponsibility
+!
+
+alignBottomLeftWith:someCoordinate
+    "return a copy of myself where its bottomLeft is aligned with someCoordinate"
+
+    ^ self align:(self bounds bottomLeft) with:someCoordinate
+
+    "
+     |r1 r2 r3 v|
+
+     r1 := 0@0 corner:10@10.
+     r2 := 100@100 corner:200@200.
+     r3 := r1 copy alignBottomLeftWith:r2 corner.
+     v := (View extent:300@300) openAndWait.
+     r2 displayOn:v.   
+     r3 displayOn:v.   
+    "
+!
+
+alignBottomRightWith:someCoordinate
+    "return a copy of myself where its bottomRight is aligned with someCoordinate.
+     Same as alignCorner"
+
+    ^ self align:(self bounds corner) with:someCoordinate
+
+    "
+     |r1 r2 r3 v|
+
+     r1 := 0@0 corner:10@10.
+     r2 := 100@100 corner:200@200.
+     r3 := r1 copy alignBottomRightWith:r2 corner.
+     v := (View extent:300@300) openAndWait.
+     r2 displayOn:v.   
+     r3 displayOn:v.   
+    "
+!
+
+alignCenterWith:someCoordinate
+    "return a copy of myself where its center is aligned with someCoordinate.
+     Same as alignOrigin"
+
+    ^ self align:(self bounds center) with:someCoordinate
+
+    "
+     |r1 r2 r3 v|
+
+     r1 := 0@0 corner:10@10.
+     r2 := 100@100 corner:200@200.
+     r3 := r1 copy alignCenterWith:r2 corner.
+     v := (View extent:300@300) openAndWait.
+     r2 displayOn:v.   
+     r3 displayOn:v.   
+    "
+!
+
+alignCornerWith:someCoordinate
+    "return a copy of myself where its corner is aligned with someCoordinate"
+
+    ^ self align:(self bounds corner) with:someCoordinate
+
+    "
+     |r1 r2 r3 v|
+
+     r1 := 0@0 corner:10@10.
+     r2 := 100@100 corner:200@200.
+     r3 := r1 copy alignCornerWith:r2 corner.
+     v := (View extent:300@300) openAndWait.
+     r2 displayOn:v.   
+     r3 displayOn:v.   
+    "
+!
+
+alignOriginWith:someCoordinate
+    "return a copy of myself where its origin is aligned with someCoordinate"
+
+    ^ self align:(self bounds origin) with:someCoordinate
+
+    "
+     |r1 r2 r3 v|
+
+     r1 := 0@0 corner:10@10.
+     r2 := 100@100 corner:200@200.
+     r3 := r1 copy alignOriginWith:r2 corner.
+     v := (View extent:300@300) openAndWait.
+     r2 displayOn:v.   
+     r3 displayOn:v.   
+    "
+!
+
+alignTopLeftWith:someCoordinate
+    "return a copy of myself where its topLeft is aligned with someCoordinate.
+     Same as alignOrigin"
+
+    ^ self align:(self bounds origin) with:someCoordinate
+
+    "
+     |r1 r2 r3 v|
+
+     r1 := 0@0 corner:10@10.
+     r2 := 100@100 corner:200@200.
+     r3 := r1 copy alignTopLeftWith:r2 corner.
+     v := (View extent:300@300) openAndWait.
+     r2 displayOn:v.   
+     r3 displayOn:v.   
+    "
+!
+
+alignTopRightWith:someCoordinate
+    "return a copy of myself where its topRight is aligned with someCoordinate.
+     Same as alignOrigin"
+
+    ^ self align:(self bounds topRight) with:someCoordinate
+
+    "
+     |r1 r2 r3 v|
+
+     r1 := 0@0 corner:10@10.
+     r2 := 100@100 corner:200@200.
+     r3 := r1 copy alignTopRightWith:r2 corner.
+     v := (View extent:300@300) openAndWait.
+     r2 displayOn:v.   
+     r3 displayOn:v.   
+    "
+!
+
 scaledBy:scaleAmount 
     "return a copy of the receiver, which is scaled by the argument,
      a point or number"
@@ -525,7 +652,8 @@
 !Geometric class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Geometric.st,v 1.31 2009-06-06 10:12:25 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Geometric.st,v 1.32 2013-08-31 11:46:29 cg Exp $'
 ! !
 
+
 Geometric initialize!