Geometric.st
changeset 2381 10af98758a49
parent 2377 83a8f10a1234
child 2382 78182edd332e
--- a/Geometric.st	Wed Feb 12 11:36:26 1997 +0100
+++ b/Geometric.st	Wed Feb 12 13:23:49 1997 +0100
@@ -12,7 +12,7 @@
 
 Object subclass:#Geometric
 	instanceVariableNames:''
-	classVariableNames:''
+	classVariableNames:'Scale InverseScale'
 	poolDictionaries:''
 	category:'Graphics-Geometry'
 !
@@ -266,15 +266,78 @@
 "
 ! !
 
+!Geometric class methodsFor:'initialization'!
+
+initialize
+    "setup class constants"
+
+    "/ these are note used in ST/X;
+    "/ (acc. to a testers note, ST-80 internally uses
+    "/  integer valued coordinates, scaling coordinates by
+    "/  the Scale constant. ST/X does not do this. However,
+    "/  user suppied subclasses may depend on those values being
+    "/  present ...)
+
+    Scale := 4096.
+    InverseScale := 1.0 / Scale
+
+    "
+     Geometric initialize
+    "
+
+    "Modified: 12.2.1997 / 13:11:31 / cg"
+! !
+
+!Geometric class methodsFor:'helper functions'!
+
+boundingRectangleForPoints:aSequencableCollectionOfPoints
+    "given a bunch of point, compute the boundingRectangle
+     (i.e. the smallest rectangle which encloses all of those points)"
+
+    |p minX minY maxX maxY n "{ Class: SmallInteger }"
+     x y |
+
+    p := aSequencableCollectionOfPoints first.
+    minX := maxX := p x.
+    minY := maxY := p y.
+
+    n := aSequencableCollectionOfPoints size.
+    1 to:n do:[:idx | 
+        p := aSequencableCollectionOfPoints at:idx.
+        x := p x.
+        y := p y.
+        x < minX ifTrue:[
+            minX := x
+        ] ifFalse:[
+            x > maxX ifTrue:[
+                maxX := x
+            ]
+        ].
+        y < minY ifTrue:[
+            minY := y
+        ] ifFalse:[
+            y > maxY ifTrue:[
+                maxY := y
+            ]
+        ].
+    ].
+
+    ^ Rectangle left:minX top:minY right:maxX bottom:maxY
+
+    "Modified: 12.2.1997 / 12:10:12 / cg"
+! !
+
 !Geometric methodsFor:'converting'!
 
 asFiller
     "return a wrapper which displays the receiver in its filled form"
 
-    ^ FillingWrapper on:self
+    self canBeFilled ifTrue:[
+        ^ FillingWrapper on:self
+    ].
+    ^ self shouldNotImplement
 
-    "Created: 8.5.1996 / 14:38:59 / cg"
-    "Modified: 8.5.1996 / 18:22:56 / cg"
+    "Modified: 12.2.1997 / 11:47:22 / cg"
 !
 
 asRectangle
@@ -334,12 +397,14 @@
 !Geometric methodsFor:'queries'!
 
 bounds
-    "return the smallest enclosing rectangle"
+    "return the smallest enclosing rectangle.
+     This resends computeBounds, to allow caching of bounds in
+     case this computation is expensive."
 
-    ^ self subclassResponsibility
+    ^ self computeBounds
 
     "Created: 8.5.1996 / 13:56:08 / cg"
-    "Modified: 8.5.1996 / 14:06:31 / cg"
+    "Modified: 12.2.1997 / 11:41:38 / cg"
 !
 
 canBeFilled
@@ -351,6 +416,14 @@
     "Created: 1.6.1996 / 11:28:58 / cg"
 !
 
+computeBounds
+    "return the smallest enclosing rectangle."
+
+    ^ self subclassResponsibility
+
+    "Created: 12.2.1997 / 11:41:58 / cg"
+!
+
 outlineIntersects:aRectangle
     "return true, if the receivers image intersects
      aRectangle, when drawn as an outline.
@@ -396,5 +469,6 @@
 !Geometric class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Geometric.st,v 1.22 1997-02-10 18:07:00 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Geometric.st,v 1.23 1997-02-12 12:23:49 cg Exp $'
 ! !
+Geometric initialize!