From ee6443053bbdac17785f6c074a5de446365cd3bf Mon Sep 17 00:00:00 2001
From: Joe Groff <arcata@gmail.com>
Date: Sun, 6 Jul 2008 19:39:53 -0700
Subject: [PATCH 01/17] Remove useless bitand from integer>bit-array;
 set-alien-unsigned-1 does that for us!

---
 extra/bit-arrays/bit-arrays.factor | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/extra/bit-arrays/bit-arrays.factor b/extra/bit-arrays/bit-arrays.factor
index 3d699a2623..4e6f7428b0 100755
--- a/extra/bit-arrays/bit-arrays.factor
+++ b/extra/bit-arrays/bit-arrays.factor
@@ -76,7 +76,7 @@ M: bit-array byte-length length 7 + -3 shift ;
     n zero? [ 0 <bit-array> ] [
         [let | out [ n log2 1+ <bit-array> ] i! [ 0 ] n'! [ n ] |
             [ n' zero? not ] [
-                n' out underlying>> i 255 bitand set-alien-unsigned-1
+                n' out underlying>> i set-alien-unsigned-1
                 n' -8 shift n'!
                 i 1+ i!
             ] [ ] while

From 1026587d631263942a4a5e6491fb944ffa2f46c6 Mon Sep 17 00:00:00 2001
From: Eduardo Cavazos <dharmatech@finkelstein.stackeffects.info>
Date: Fri, 11 Jul 2008 18:07:04 -0500
Subject: [PATCH 02/17] add math.geometry.rect

---
 extra/math/geometry/rect/rect.factor | 42 ++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 extra/math/geometry/rect/rect.factor

diff --git a/extra/math/geometry/rect/rect.factor b/extra/math/geometry/rect/rect.factor
new file mode 100644
index 0000000000..51f42c22ca
--- /dev/null
+++ b/extra/math/geometry/rect/rect.factor
@@ -0,0 +1,42 @@
+
+USING: kernel arrays math.vectors ;
+
+IN: math.geometry.rect
+
+TUPLE: rect { loc initial: { 0 0 } } { dim initial: { 0 0 } } ;
+
+: <zero-rect> ( -- rect ) rect new ;
+
+C: <rect> rect
+
+M: array rect-loc ;
+
+M: array rect-dim drop { 0 0 } ;
+
+: rect-bounds ( rect -- loc dim ) dup rect-loc swap rect-dim ;
+
+: rect-extent ( rect -- loc ext ) rect-bounds over v+ ;
+
+: 2rect-extent ( rect rect -- loc1 loc2 ext1 ext2 )
+    [ rect-extent ] bi@ swapd ;
+
+: <extent-rect> ( loc ext -- rect ) over [v-] <rect> ;
+
+: offset-rect ( rect loc -- newrect )
+    over rect-loc v+ swap rect-dim <rect> ;
+
+: (rect-intersect) ( rect rect -- array array )
+    2rect-extent vmin >r vmax r> ;
+
+: rect-intersect ( rect1 rect2 -- newrect )
+    (rect-intersect) <extent-rect> ;
+
+: intersects? ( rect/point rect -- ? )
+    (rect-intersect) [v-] { 0 0 } = ;
+
+: (rect-union) ( rect rect -- array array )
+    2rect-extent vmax >r vmin r> ;
+
+: rect-union ( rect1 rect2 -- newrect )
+    (rect-union) <extent-rect> ;
+

From 6235d0b16f7e1c0394461225cd235e557764dd48 Mon Sep 17 00:00:00 2001
From: Eduardo Cavazos <dharmatech@finkelstein.stackeffects.info>
Date: Fri, 11 Jul 2008 18:13:41 -0500
Subject: [PATCH 03/17] gadgets: remove rect (moved to math.geometry.rect)

---
 extra/ui/gadgets/gadgets.factor | 43 +++------------------------------
 1 file changed, 4 insertions(+), 39 deletions(-)

diff --git a/extra/ui/gadgets/gadgets.factor b/extra/ui/gadgets/gadgets.factor
index 5bfb5a1b05..a274dc2392 100755
--- a/extra/ui/gadgets/gadgets.factor
+++ b/extra/ui/gadgets/gadgets.factor
@@ -1,51 +1,16 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays hashtables kernel models math namespaces
-sequences quotations math.vectors combinators sorting vectors
-dlists dequeues models threads concurrency.flags math.order ;
+       sequences quotations math.vectors combinators sorting vectors
+       dlists dequeues models threads concurrency.flags
+       math.order math.geometry.rect ;
+
 IN: ui.gadgets
 
 SYMBOL: ui-notify-flag
 
 : notify-ui-thread ( -- ) ui-notify-flag get-global raise-flag ;
 
-TUPLE: rect { loc initial: { 0 0 } } { dim initial: { 0 0 } } ;
-
-: <zero-rect> ( -- rect ) rect new ;
-
-C: <rect> rect
-
-M: array rect-loc ;
-
-M: array rect-dim drop { 0 0 } ;
-
-: rect-bounds ( rect -- loc dim ) dup rect-loc swap rect-dim ;
-
-: rect-extent ( rect -- loc ext ) rect-bounds over v+ ;
-
-: 2rect-extent ( rect rect -- loc1 loc2 ext1 ext2 )
-    [ rect-extent ] bi@ swapd ;
-
-: <extent-rect> ( loc ext -- rect ) over [v-] <rect> ;
-
-: offset-rect ( rect loc -- newrect )
-    over rect-loc v+ swap rect-dim <rect> ;
-
-: (rect-intersect) ( rect rect -- array array )
-    2rect-extent vmin >r vmax r> ;
-
-: rect-intersect ( rect1 rect2 -- newrect )
-    (rect-intersect) <extent-rect> ;
-
-: intersects? ( rect/point rect -- ? )
-    (rect-intersect) [v-] { 0 0 } = ;
-
-: (rect-union) ( rect rect -- array array )
-    2rect-extent vmax >r vmin r> ;
-
-: rect-union ( rect1 rect2 -- newrect )
-    (rect-union) <extent-rect> ;
-
 TUPLE: gadget < rect
 pref-dim parent children orientation focus
 visible? root? clipped? layout-state graft-state graft-node

From e0602a621d9e2f72d1d8e3847eaf54d263f3b2d1 Mon Sep 17 00:00:00 2001
From: Eduardo Cavazos <dharmatech@finkelstein.stackeffects.info>
Date: Fri, 11 Jul 2008 18:14:05 -0500
Subject: [PATCH 04/17] add math.geometry.rect-docs

---
 extra/math/geometry/rect/rect-docs.factor | 54 +++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 extra/math/geometry/rect/rect-docs.factor

diff --git a/extra/math/geometry/rect/rect-docs.factor b/extra/math/geometry/rect/rect-docs.factor
new file mode 100644
index 0000000000..3e21dfe307
--- /dev/null
+++ b/extra/math/geometry/rect/rect-docs.factor
@@ -0,0 +1,54 @@
+USING: help.markup help.syntax ;
+
+IN: math.geometry.rect
+
+HELP: rect
+{ $class-description "A rectangle with the following slots:"
+    { $list
+        { { $link rect-loc } " - the top-left corner of the rectangle as an x/y pair" }
+        { { $link rect-dim } " - the dimensions of the rectangle as a width/height pair" }
+    }
+    "Rectangles are constructed by calling " { $link <rect> } " and " { $link <extent-rect> } "."
+} ;
+
+HELP: <rect> ( loc dim -- rect )
+{ $values { "loc" "a pair of integers" } { "dim" "a pair of integers" } { "rect" "a new " { $link rect } } }
+{ $description "Creates a new rectangle with the specified top-left location and dimensions." } ;
+
+{ <zero-rect> <rect> <extent-rect> } related-words
+
+HELP: set-rect-dim ( dim rect -- )
+{ $values { "dim" "a pair of integers" } { "rect" rect } }
+{ $description "Modifies the dimensions of a rectangle." }
+{ $side-effects "rect" } ;
+
+HELP: rect-bounds
+{ $values { "rect" rect } { "loc" "a pair of integers" } { "dim" "a pair of integers" } }
+{ $description "Outputs the location and dimensions of a rectangle." } ;
+
+{ rect-bounds rect-extent } related-words
+
+HELP: <extent-rect> ( loc ext -- rect )
+{ $values { "loc" "a pair of integers" } { "ext" "a pair of integers" } { "rect" "a new " { $link rect } } }
+{ $description "Creates a new rectangle with the specified top-left and bottom-right corner locations." } ;
+
+HELP: rect-extent
+{ $values { "rect" rect } { "loc" "a pair of integers" } { "ext" "a pair of integers" } }
+{ $description "Outputs the location of the top-left and bottom-right corners of a rectangle." } ;
+
+HELP: offset-rect
+{ $values { "rect" rect } { "loc" "a pair of integers" } { "newrect" "a new " { $link rect } } }
+{ $description "Creates a new rectangle with the same dimensions, and top-left corner translated by " { $snippet "loc" } "." } ;
+
+HELP: rect-intersect
+{ $values { "rect1" rect } { "rect2" rect } { "newrect" "a new " { $link rect } } }
+{ $description "Computes the intersection of two rectangles." } ;
+
+HELP: intersects?
+{ $values { "rect/point" "a " { $link rect } " or a pair of integers" } { "rect" rect } { "?" "a boolean" } }
+{ $description "Tests if two rectangles (or a point and a rectangle, respectively) have a non-empty intersection." } ;
+
+HELP: <zero-rect>
+{ $values { "rect" "a new " { $link rect } } }
+{ $description "Creates a rectangle located at the origin with zero dimensions." } ;
+

From 6a358bd391231601e6854761afbd7530e6777d84 Mon Sep 17 00:00:00 2001
From: Eduardo Cavazos <dharmatech@finkelstein.stackeffects.info>
Date: Fri, 11 Jul 2008 18:14:30 -0500
Subject: [PATCH 05/17] gadgets-docs: remove rect help

---
 extra/ui/gadgets/gadgets-docs.factor | 52 +---------------------------
 1 file changed, 1 insertion(+), 51 deletions(-)

diff --git a/extra/ui/gadgets/gadgets-docs.factor b/extra/ui/gadgets/gadgets-docs.factor
index 8093aa5dc5..b9d12847be 100755
--- a/extra/ui/gadgets/gadgets-docs.factor
+++ b/extra/ui/gadgets/gadgets-docs.factor
@@ -1,53 +1,7 @@
 USING: help.markup help.syntax opengl kernel strings
-classes.tuple classes quotations models ;
+       classes.tuple classes quotations models math.geometry.rect ;
 IN: ui.gadgets
 
-HELP: rect
-{ $class-description "A rectangle with the following slots:"
-    { $list
-        { { $link rect-loc } " - the top-left corner of the rectangle as an x/y pair" }
-        { { $link rect-dim } " - the dimensions of the rectangle as a width/height pair" }
-    }
-    "Rectangles are constructed by calling " { $link <rect> } " and " { $link <extent-rect> } "."
-} ;
-
-HELP: <rect> ( loc dim -- rect )
-{ $values { "loc" "a pair of integers" } { "dim" "a pair of integers" } { "rect" "a new " { $link rect } } }
-{ $description "Creates a new rectangle with the specified top-left location and dimensions." } ;
-
-{ <zero-rect> <rect> <extent-rect> } related-words
-
-HELP: set-rect-dim ( dim rect -- )
-{ $values { "dim" "a pair of integers" } { "rect" rect } }
-{ $description "Modifies the dimensions of a rectangle. To resize a gadget, use " { $link set-gadget-dim } " or " { $link set-layout-dim } " instead." }
-{ $side-effects "rect" } ;
-
-HELP: rect-bounds
-{ $values { "rect" rect } { "loc" "a pair of integers" } { "dim" "a pair of integers" } }
-{ $description "Outputs the location and dimensions of a rectangle." } ;
-
-{ rect-bounds rect-extent } related-words
-
-HELP: <extent-rect> ( loc ext -- rect )
-{ $values { "loc" "a pair of integers" } { "ext" "a pair of integers" } { "rect" "a new " { $link rect } } }
-{ $description "Creates a new rectangle with the specified top-left and bottom-right corner locations." } ;
-
-HELP: rect-extent
-{ $values { "rect" rect } { "loc" "a pair of integers" } { "ext" "a pair of integers" } }
-{ $description "Outputs the location of the top-left and bottom-right corners of a rectangle." } ;
-
-HELP: offset-rect
-{ $values { "rect" rect } { "loc" "a pair of integers" } { "newrect" "a new " { $link rect } } }
-{ $description "Creates a new rectangle with the same dimensions, and top-left corner translated by " { $snippet "loc" } "." } ;
-
-HELP: rect-intersect
-{ $values { "rect1" rect } { "rect2" rect } { "newrect" "a new " { $link rect } } }
-{ $description "Computes the intersection of two rectangles." } ;
-
-HELP: intersects?
-{ $values { "rect/point" "a " { $link rect } " or a pair of integers" } { "rect" rect } { "?" "a boolean" } }
-{ $description "Tests if two rectangles (or a point and a rectangle, respectively) have a non-empty intersection." } ;
-
 HELP: gadget-child
 { $values { "gadget" gadget } { "child" gadget } }
 { $description "Outputs the first child of the gadget. Typically this word is used with gadgets which are known to have an only child." } ;
@@ -57,10 +11,6 @@ HELP: nth-gadget
 { $description "Outputs the " { $snippet "n" } "th child of the gadget." }
 { $errors "Throws an error if " { $snippet "n" } " is negative or greater than or equal to the number of children." } ;
 
-HELP: <zero-rect>
-{ $values { "rect" "a new " { $link rect } } }
-{ $description "Creates a rectangle located at the origin with zero dimensions." } ;
-
 HELP: <gadget>
 { $values { "gadget" "a new " { $link gadget } } }
 { $description "Creates a new gadget." } ;

From 75991cf7ce74bc391a8feff753dc4785e2703f80 Mon Sep 17 00:00:00 2001
From: Eduardo Cavazos <dharmatech@finkelstein.stackeffects.info>
Date: Fri, 11 Jul 2008 18:34:43 -0500
Subject: [PATCH 06/17] Edit USING: for 'math.geometry.rect'

---
 extra/ui/gadgets/books/books.factor              | 2 +-
 extra/ui/gadgets/borders/borders.factor          | 2 +-
 extra/ui/gadgets/buttons/buttons.factor          | 2 +-
 extra/ui/gadgets/editors/editors.factor          | 3 ++-
 extra/ui/gadgets/frames/frames.factor            | 3 ++-
 extra/ui/gadgets/grid-lines/grid-lines.factor    | 2 +-
 extra/ui/gadgets/grids/grids.factor              | 3 ++-
 extra/ui/gadgets/incremental/incremental.factor  | 2 +-
 extra/ui/gadgets/lists/lists.factor              | 2 +-
 extra/ui/gadgets/menus/menus.factor              | 3 ++-
 extra/ui/gadgets/packs/packs.factor              | 2 +-
 extra/ui/gadgets/panes/panes.factor              | 2 +-
 extra/ui/gadgets/paragraphs/paragraphs.factor    | 2 +-
 extra/ui/gadgets/scrollers/scrollers-docs.factor | 2 +-
 extra/ui/gadgets/scrollers/scrollers.factor      | 2 +-
 extra/ui/gadgets/sliders/sliders.factor          | 2 +-
 extra/ui/gadgets/tracks/tracks.factor            | 2 +-
 extra/ui/gadgets/viewports/viewports.factor      | 2 +-
 extra/ui/gadgets/worlds/worlds.factor            | 2 +-
 extra/ui/render/render-docs.factor               | 2 +-
 extra/ui/render/render.factor                    | 3 ++-
 extra/ui/ui-docs.factor                          | 2 +-
 extra/ui/x11/x11.factor                          | 2 +-
 23 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/extra/ui/gadgets/books/books.factor b/extra/ui/gadgets/books/books.factor
index 219a970943..93a8d271af 100755
--- a/extra/ui/gadgets/books/books.factor
+++ b/extra/ui/gadgets/books/books.factor
@@ -1,6 +1,6 @@
 ! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel sequences models ui.gadgets ;
+USING: accessors kernel sequences models ui.gadgets math.geometry.rect ;
 IN: ui.gadgets.books
 
 TUPLE: book < gadget ;
diff --git a/extra/ui/gadgets/borders/borders.factor b/extra/ui/gadgets/borders/borders.factor
index 55d1993b1d..2c232392ce 100644
--- a/extra/ui/gadgets/borders/borders.factor
+++ b/extra/ui/gadgets/borders/borders.factor
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays ui.gadgets kernel math
-namespaces vectors sequences math.vectors ;
+namespaces vectors sequences math.vectors math.geometry.rect ;
 IN: ui.gadgets.borders
 
 TUPLE: border < gadget
diff --git a/extra/ui/gadgets/buttons/buttons.factor b/extra/ui/gadgets/buttons/buttons.factor
index 96a89e8aa6..a855a6d93e 100755
--- a/extra/ui/gadgets/buttons/buttons.factor
+++ b/extra/ui/gadgets/buttons/buttons.factor
@@ -6,7 +6,7 @@ classes.tuple opengl math.vectors
 ui.commands ui.gadgets ui.gadgets.borders
 ui.gadgets.labels ui.gadgets.theme
 ui.gadgets.tracks ui.gadgets.packs ui.gadgets.worlds ui.gestures
-ui.render ;
+ui.render math.geometry.rect ;
 IN: ui.gadgets.buttons
 
 TUPLE: button < border pressed? selected? quot ;
diff --git a/extra/ui/gadgets/editors/editors.factor b/extra/ui/gadgets/editors/editors.factor
index 1732d404ca..8b0244900a 100755
--- a/extra/ui/gadgets/editors/editors.factor
+++ b/extra/ui/gadgets/editors/editors.factor
@@ -5,7 +5,8 @@ namespaces opengl opengl.gl sequences strings io.styles
 math.vectors sorting colors combinators assocs math.order
 ui.clipboards ui.commands ui.gadgets ui.gadgets.borders
 ui.gadgets.buttons ui.gadgets.labels ui.gadgets.scrollers
-ui.gadgets.theme ui.gadgets.wrappers ui.render ui.gestures ;
+ui.gadgets.theme ui.gadgets.wrappers ui.render ui.gestures
+math.geometry.rect ;
 IN: ui.gadgets.editors
 
 TUPLE: editor < gadget
diff --git a/extra/ui/gadgets/frames/frames.factor b/extra/ui/gadgets/frames/frames.factor
index 096d916a9b..717323c69a 100644
--- a/extra/ui/gadgets/frames/frames.factor
+++ b/extra/ui/gadgets/frames/frames.factor
@@ -1,7 +1,8 @@
 ! Copyright (C) 2005, 2007 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays generic kernel math namespaces sequences words
-splitting grouping math.vectors ui.gadgets.grids ui.gadgets ;
+splitting grouping math.vectors ui.gadgets.grids ui.gadgets
+math.geometry.rect ;
 IN: ui.gadgets.frames
 
 ! A frame arranges gadgets in a 3x3 grid, where the center
diff --git a/extra/ui/gadgets/grid-lines/grid-lines.factor b/extra/ui/gadgets/grid-lines/grid-lines.factor
index 533116824b..d0cedc985b 100755
--- a/extra/ui/gadgets/grid-lines/grid-lines.factor
+++ b/extra/ui/gadgets/grid-lines/grid-lines.factor
@@ -1,7 +1,7 @@
 ! Copyright (C) 2006, 2007 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel math namespaces opengl opengl.gl sequences
-math.vectors ui.gadgets ui.gadgets.grids ui.render ;
+math.vectors ui.gadgets ui.gadgets.grids ui.render math.geometry.rect ;
 IN: ui.gadgets.grid-lines
 
 TUPLE: grid-lines color ;
diff --git a/extra/ui/gadgets/grids/grids.factor b/extra/ui/gadgets/grids/grids.factor
index 70aee4d1e3..b539934771 100644
--- a/extra/ui/gadgets/grids/grids.factor
+++ b/extra/ui/gadgets/grids/grids.factor
@@ -1,7 +1,8 @@
 ! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays kernel math namespaces sequences words io
-io.streams.string math.vectors ui.gadgets columns accessors ;
+io.streams.string math.vectors ui.gadgets columns accessors
+math.geometry.rect ;
 IN: ui.gadgets.grids
 
 TUPLE: grid < gadget
diff --git a/extra/ui/gadgets/incremental/incremental.factor b/extra/ui/gadgets/incremental/incremental.factor
index 418dd3b7c6..c74f6676ad 100755
--- a/extra/ui/gadgets/incremental/incremental.factor
+++ b/extra/ui/gadgets/incremental/incremental.factor
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: io kernel math namespaces math.vectors ui.gadgets
-ui.gadgets.packs accessors ;
+ui.gadgets.packs accessors math.geometry.rect ;
 IN: ui.gadgets.incremental
 
 ! Incremental layout allows adding lines to panes to be O(1).
diff --git a/extra/ui/gadgets/lists/lists.factor b/extra/ui/gadgets/lists/lists.factor
index 2b50453cf4..776814853f 100755
--- a/extra/ui/gadgets/lists/lists.factor
+++ b/extra/ui/gadgets/lists/lists.factor
@@ -4,7 +4,7 @@ USING: accessors ui.commands ui.gestures ui.render ui.gadgets
 ui.gadgets.labels ui.gadgets.scrollers
 kernel sequences models opengl math math.order namespaces
 ui.gadgets.presentations ui.gadgets.viewports ui.gadgets.packs
-math.vectors classes.tuple ;
+math.vectors classes.tuple math.geometry.rect ;
 IN: ui.gadgets.lists
 
 TUPLE: list < pack index presenter color hook ;
diff --git a/extra/ui/gadgets/menus/menus.factor b/extra/ui/gadgets/menus/menus.factor
index 66dbb05d66..3e1145a8b6 100644
--- a/extra/ui/gadgets/menus/menus.factor
+++ b/extra/ui/gadgets/menus/menus.factor
@@ -3,7 +3,8 @@
 USING: arrays ui.commands ui.gadgets ui.gadgets.buttons
 ui.gadgets.worlds ui.gestures generic hashtables kernel math
 models namespaces opengl sequences math.vectors
-ui.gadgets.theme ui.gadgets.packs ui.gadgets.borders colors ;
+ui.gadgets.theme ui.gadgets.packs ui.gadgets.borders colors
+math.geometry.rect ;
 IN: ui.gadgets.menus
 
 : menu-loc ( world menu -- loc )
diff --git a/extra/ui/gadgets/packs/packs.factor b/extra/ui/gadgets/packs/packs.factor
index 00f27af270..7ae222c279 100755
--- a/extra/ui/gadgets/packs/packs.factor
+++ b/extra/ui/gadgets/packs/packs.factor
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: sequences ui.gadgets kernel math math.functions
-math.vectors namespaces math.order accessors ;
+math.vectors namespaces math.order accessors math.geometry.rect ;
 IN: ui.gadgets.packs
 
 TUPLE: pack < gadget
diff --git a/extra/ui/gadgets/panes/panes.factor b/extra/ui/gadgets/panes/panes.factor
index 87eec35871..973c8c5725 100755
--- a/extra/ui/gadgets/panes/panes.factor
+++ b/extra/ui/gadgets/panes/panes.factor
@@ -9,7 +9,7 @@ quotations math opengl combinators math.vectors
 sorting splitting io.streams.nested assocs
 ui.gadgets.presentations ui.gadgets.slots ui.gadgets.grids
 ui.gadgets.grid-lines classes.tuple models continuations
-destructors accessors ;
+destructors accessors math.geometry.rect ;
 IN: ui.gadgets.panes
 
 TUPLE: pane < pack
diff --git a/extra/ui/gadgets/paragraphs/paragraphs.factor b/extra/ui/gadgets/paragraphs/paragraphs.factor
index 12382be9cd..1946ff6db6 100644
--- a/extra/ui/gadgets/paragraphs/paragraphs.factor
+++ b/extra/ui/gadgets/paragraphs/paragraphs.factor
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2007 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays ui.gadgets ui.gadgets.labels ui.render kernel math
-namespaces sequences math.order ;
+namespaces sequences math.order math.geometry.rect ;
 IN: ui.gadgets.paragraphs
 
 ! A word break gadget
diff --git a/extra/ui/gadgets/scrollers/scrollers-docs.factor b/extra/ui/gadgets/scrollers/scrollers-docs.factor
index ee82339f33..3554c735a7 100755
--- a/extra/ui/gadgets/scrollers/scrollers-docs.factor
+++ b/extra/ui/gadgets/scrollers/scrollers-docs.factor
@@ -1,5 +1,5 @@
 USING: ui.gadgets help.markup help.syntax ui.gadgets.viewports
-ui.gadgets.sliders ;
+ui.gadgets.sliders math.geometry.rect ;
 IN: ui.gadgets.scrollers
 
 HELP: scroller
diff --git a/extra/ui/gadgets/scrollers/scrollers.factor b/extra/ui/gadgets/scrollers/scrollers.factor
index 8cac3f4400..1fe3c606bb 100755
--- a/extra/ui/gadgets/scrollers/scrollers.factor
+++ b/extra/ui/gadgets/scrollers/scrollers.factor
@@ -4,7 +4,7 @@ USING: accessors arrays ui.gadgets ui.gadgets.viewports
 ui.gadgets.frames ui.gadgets.grids ui.gadgets.theme
 ui.gadgets.sliders ui.gestures kernel math namespaces sequences
 models models.range models.compose
-combinators math.vectors classes.tuple ;
+combinators math.vectors classes.tuple math.geometry.rect ;
 IN: ui.gadgets.scrollers
 
 TUPLE: scroller < frame viewport x y follows ;
diff --git a/extra/ui/gadgets/sliders/sliders.factor b/extra/ui/gadgets/sliders/sliders.factor
index da18dea142..b5d8862359 100755
--- a/extra/ui/gadgets/sliders/sliders.factor
+++ b/extra/ui/gadgets/sliders/sliders.factor
@@ -4,7 +4,7 @@ USING: accessors arrays ui.gestures ui.gadgets ui.gadgets.buttons
 ui.gadgets.frames ui.gadgets.grids math.order
 ui.gadgets.theme ui.render kernel math namespaces sequences
 vectors models models.range math.vectors math.functions
-quotations colors ;
+quotations colors math.geometry.rect ;
 IN: ui.gadgets.sliders
 
 TUPLE: elevator < gadget direction ;
diff --git a/extra/ui/gadgets/tracks/tracks.factor b/extra/ui/gadgets/tracks/tracks.factor
index f9276fd1a1..5de9b9d366 100644
--- a/extra/ui/gadgets/tracks/tracks.factor
+++ b/extra/ui/gadgets/tracks/tracks.factor
@@ -1,7 +1,7 @@
 ! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors io kernel math namespaces
-sequences words math.vectors ui.gadgets ui.gadgets.packs ;
+sequences words math.vectors ui.gadgets ui.gadgets.packs math.geometry.rect ;
 IN: ui.gadgets.tracks
 
 TUPLE: track < pack sizes ;
diff --git a/extra/ui/gadgets/viewports/viewports.factor b/extra/ui/gadgets/viewports/viewports.factor
index 2e7e130404..100d6c8a39 100755
--- a/extra/ui/gadgets/viewports/viewports.factor
+++ b/extra/ui/gadgets/viewports/viewports.factor
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 IN: ui.gadgets.viewports
 USING: accessors arrays ui.gadgets ui.gadgets.borders
-kernel math namespaces sequences models math.vectors ;
+kernel math namespaces sequences models math.vectors math.geometry.rect ;
 
 : viewport-gap { 3 3 } ; inline
 
diff --git a/extra/ui/gadgets/worlds/worlds.factor b/extra/ui/gadgets/worlds/worlds.factor
index 7064045cc4..dc4debd900 100755
--- a/extra/ui/gadgets/worlds/worlds.factor
+++ b/extra/ui/gadgets/worlds/worlds.factor
@@ -3,7 +3,7 @@
 USING: accessors arrays assocs continuations kernel math models
 namespaces opengl sequences io combinators math.vectors
 ui.gadgets ui.gestures ui.render ui.backend ui.gadgets.tracks
-debugger ;
+debugger math.geometry.rect ;
 IN: ui.gadgets.worlds
 
 TUPLE: world < track
diff --git a/extra/ui/render/render-docs.factor b/extra/ui/render/render-docs.factor
index d48d7c99d9..0133b7bb1c 100755
--- a/extra/ui/render/render-docs.factor
+++ b/extra/ui/render/render-docs.factor
@@ -1,5 +1,5 @@
 USING: ui.gadgets ui.gestures help.markup help.syntax
-kernel classes strings opengl.gl models ;
+kernel classes strings opengl.gl models math.geometry.rect ;
 IN: ui.render
 
 HELP: gadget
diff --git a/extra/ui/render/render.factor b/extra/ui/render/render.factor
index 8f40bec1c3..6e9a4778a7 100644
--- a/extra/ui/render/render.factor
+++ b/extra/ui/render/render.factor
@@ -2,7 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien arrays hashtables io kernel math namespaces opengl
 opengl.gl opengl.glu sequences strings io.styles vectors
-combinators math.vectors ui.gadgets colors math.order ;
+combinators math.vectors ui.gadgets colors
+math.order math.geometry.rect ;
 IN: ui.render
 
 SYMBOL: clip
diff --git a/extra/ui/ui-docs.factor b/extra/ui/ui-docs.factor
index 1a541090c5..72cb2c557e 100755
--- a/extra/ui/ui-docs.factor
+++ b/extra/ui/ui-docs.factor
@@ -1,6 +1,6 @@
 USING: help.markup help.syntax strings quotations debugger
 io.styles namespaces ui.backend ui.gadgets ui.gadgets.worlds
-ui.gadgets.tracks ui.gadgets.packs ui.gadgets.grids ;
+ui.gadgets.tracks ui.gadgets.packs ui.gadgets.grids math.geometry.rect ;
 IN: ui
 
 HELP: windows
diff --git a/extra/ui/x11/x11.factor b/extra/ui/x11/x11.factor
index 35f22ec64f..b75daf89fa 100755
--- a/extra/ui/x11/x11.factor
+++ b/extra/ui/x11/x11.factor
@@ -6,7 +6,7 @@ assocs kernel math namespaces opengl sequences strings x11.xlib
 x11.events x11.xim x11.glx x11.clipboard x11.constants
 x11.windows io.encodings.string io.encodings.ascii
 io.encodings.utf8 combinators debugger command-line qualified
-math.vectors classes.tuple opengl.gl threads ;
+math.vectors classes.tuple opengl.gl threads math.geometry.rect ;
 QUALIFIED: system
 IN: ui.x11
 

From 24a063ea76ba94acb3da4cbaad61aaf4c0a606c9 Mon Sep 17 00:00:00 2001
From: Eduardo Cavazos <dharmatech@finkelstein.stackeffects.info>
Date: Fri, 11 Jul 2008 19:02:43 -0500
Subject: [PATCH 07/17] math.physics.pos and math.physics.vel

---
 extra/math/physics/pos/pos.factor | 5 +++++
 extra/math/physics/vel/vel.factor | 7 +++++++
 2 files changed, 12 insertions(+)
 create mode 100644 extra/math/physics/pos/pos.factor
 create mode 100644 extra/math/physics/vel/vel.factor

diff --git a/extra/math/physics/pos/pos.factor b/extra/math/physics/pos/pos.factor
new file mode 100644
index 0000000000..1582c42108
--- /dev/null
+++ b/extra/math/physics/pos/pos.factor
@@ -0,0 +1,5 @@
+
+IN: math.physics.pos
+
+TUPLE: pos pos ;
+
diff --git a/extra/math/physics/vel/vel.factor b/extra/math/physics/vel/vel.factor
new file mode 100644
index 0000000000..5fc815e9b8
--- /dev/null
+++ b/extra/math/physics/vel/vel.factor
@@ -0,0 +1,7 @@
+
+USING: math.physics.pos ;
+
+IN: math.physics.vel
+
+TUPLE: vel < pos vel ;
+

From b7b17ed879f63f57efb983f47ca613be24c837f5 Mon Sep 17 00:00:00 2001
From: Eduardo Cavazos <dharmatech@finkelstein.stackeffects.info>
Date: Fri, 11 Jul 2008 19:03:15 -0500
Subject: [PATCH 08/17] boids: Use math.physics

---
 extra/boids/boids.factor | 25 ++++++++++++++-----------
 extra/boids/ui/ui.factor |  7 ++++---
 2 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/extra/boids/boids.factor b/extra/boids/boids.factor
index e6c97b90dd..cff33c9d19 100644
--- a/extra/boids/boids.factor
+++ b/extra/boids/boids.factor
@@ -6,14 +6,17 @@ USING: combinators.short-circuit kernel namespaces
        math.order
        math.vectors
        math.trig
+       math.physics.pos
+       math.physics.vel
        combinators arrays sequences random vars
-       combinators.lib ;
+       combinators.lib
+       accessors ;
 
 IN: boids
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-TUPLE: boid pos vel ;
+TUPLE: boid < vel ;
 
 C: <boid> boid
 
@@ -70,7 +73,7 @@ VAR: separation-radius
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-: distance ( boid boid -- n ) [ boid-pos ] [ boid-pos ] bi* v- norm ;
+: distance ( boid boid -- n ) [ pos>> ] [ pos>> ] bi* v- norm ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
@@ -81,10 +84,10 @@ VAR: separation-radius
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-: relative-position ( self other -- v ) swap [ boid-pos ] bi@ v- ;
+: relative-position ( self other -- v ) swap [ pos>> ] bi@ v- ;
 
 : relative-angle ( self other -- angle )
-over boid-vel -rot relative-position angle-between ;
+over vel>> -rot relative-position angle-between ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
@@ -92,9 +95,9 @@ over boid-vel -rot relative-position angle-between ;
 
 : vaverage ( seq-of-vectors -- seq ) [ vsum ] [ length ] bi v/n ;
 
-: average-position ( boids -- pos ) [ boid-pos ] map vaverage ;
+: average-position ( boids -- pos ) [ pos>> ] map vaverage ;
 
-: average-velocity ( boids -- vel ) [ boid-vel ] map vaverage ;
+: average-velocity ( boids -- vel ) [ vel>> ] map vaverage ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
@@ -123,7 +126,7 @@ over boid-vel -rot relative-position angle-between ;
   dup cohesion-neighborhood
   dup empty?
   [ 2drop { 0 0 } ]
-  [ average-position swap boid-pos v- normalize* cohesion-weight> v*n ]
+  [ average-position swap pos>> v- normalize* cohesion-weight> v*n ]
   if ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -143,7 +146,7 @@ over boid-vel -rot relative-position angle-between ;
   dup separation-neighborhood
   dup empty?
   [ 2drop { 0 0 } ]
-  [ average-position swap boid-pos swap v- normalize* separation-weight> v*n ]
+  [ average-position swap pos>> swap v- normalize* separation-weight> v*n ]
   if ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -206,10 +209,10 @@ cond ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-: new-pos ( boid -- pos ) [ boid-pos ] [ boid-vel time-slice> v*n ] bi v+ ;
+: new-pos ( boid -- pos ) [ pos>> ] [ vel>> time-slice> v*n ] bi v+ ;
 
 : new-vel ( boid -- vel )
-  [ boid-vel ] [ acceleration time-slice> v*n ] bi v+ normalize* ;
+  [ vel>> ] [ acceleration time-slice> v*n ] bi v+ normalize* ;
 
 : wrap-pos ( pos -- pos ) { [ wrap-x ] [ wrap-y ] } parallel-call ;
 
diff --git a/extra/boids/ui/ui.factor b/extra/boids/ui/ui.factor
index e3c54e0744..ab1f8e5f80 100755
--- a/extra/boids/ui/ui.factor
+++ b/extra/boids/ui/ui.factor
@@ -19,7 +19,8 @@ USING: combinators.short-circuit kernel namespaces
        ui.gadgets.packs
        ui.gadgets.grids
        ui.gestures
-       assocs.lib vars rewrite-closures boids ;
+       assocs.lib vars rewrite-closures boids accessors
+       math.geometry.rect ;
 
 IN: boids.ui
 
@@ -27,9 +28,9 @@ IN: boids.ui
 ! draw-boid
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-: point-a ( boid -- a ) boid-pos ;
+: point-a ( boid -- a ) pos>> ;
 
-: point-b ( boid -- b ) [ boid-pos ] [ boid-vel normalize* 20 v*n ] bi v+ ;
+: point-b ( boid -- b ) [ pos>> ] [ vel>> normalize* 20 v*n ] bi v+ ;
 
 : boid-points ( boid -- point-a point-b ) [ point-a ] [ point-b ] bi ;
 

From ba6d70b7f728adbf2c55cc6cd9b3853ef45e1753 Mon Sep 17 00:00:00 2001
From: Eduardo Cavazos <dharmatech@finkelstein.stackeffects.info>
Date: Fri, 11 Jul 2008 19:28:48 -0500
Subject: [PATCH 09/17] springies: use math.physics

---
 extra/springies/springies.factor | 69 ++++++++++++++++++--------------
 extra/springies/ui/ui.factor     |  6 +--
 2 files changed, 42 insertions(+), 33 deletions(-)

diff --git a/extra/springies/springies.factor b/extra/springies/springies.factor
index 1856115863..2640423eb4 100755
--- a/extra/springies/springies.factor
+++ b/extra/springies/springies.factor
@@ -1,6 +1,6 @@
 
 USING: kernel combinators sequences arrays math math.vectors
-       generalizations vars ;
+       generalizations vars accessors math.physics.vel ;
 
 IN: springies
 
@@ -28,23 +28,27 @@ VAR: gravity
 ! node
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-TUPLE: node mass elas pos vel force ;
+! TUPLE: node mass elas pos vel force ;
+
+TUPLE: node < vel mass elas force ;
 
 C: <node> node
 
-: >>pos ( node pos -- node ) over set-node-pos ;
+! : >>pos ( node pos -- node ) over set-node-pos ;
 
-: >>vel ( node vel -- node ) over set-node-vel ;
+! : >>vel ( node vel -- node ) over set-node-vel ;
 
-: pos-x ( node -- x ) node-pos first ;
-: pos-y ( node -- y ) node-pos second ;
-: vel-x ( node -- y ) node-vel first ;
-: vel-y ( node -- y ) node-vel second ;
+: set-node-vel ( vel node -- ) swap >>vel drop ;
 
-: >>pos-x ( node x -- node ) over node-pos set-first ;
-: >>pos-y ( node y -- node ) over node-pos set-second ;
-: >>vel-x ( node x -- node ) over node-vel set-first ;
-: >>vel-y ( node y -- node ) over node-vel set-second ;
+: pos-x ( node -- x ) pos>> first ;
+: pos-y ( node -- y ) pos>> second ;
+: vel-x ( node -- y ) vel>> first ;
+: vel-y ( node -- y ) vel>> second ;
+
+: >>pos-x ( node x -- node ) over pos>> set-first ;
+: >>pos-y ( node y -- node ) over pos>> set-second ;
+: >>vel-x ( node x -- node ) over vel>> set-first ;
+: >>vel-y ( node y -- node ) over vel>> set-second ;
 
 : apply-force ( node vec -- ) over node-force v+ swap set-node-force ;
 
@@ -61,7 +65,7 @@ TUPLE: spring rest-length k damp node-a node-b ;
 C: <spring> spring
 
 : end-points ( spring -- b-pos a-pos )
-  [ spring-node-b node-pos ] [ spring-node-a node-pos ] bi ;
+  [ spring-node-b pos>> ] [ spring-node-a pos>> ] bi ;
 
 : spring-length ( spring -- length ) end-points v- norm ;
 
@@ -112,10 +116,10 @@ C: <spring> spring
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 : relative-velocity-a ( spring -- vel )
-  [ spring-node-a node-vel ] [ spring-node-b node-vel ] bi v- ;
+  [ spring-node-a vel>> ] [ spring-node-b vel>> ] bi v- ;
 
 : unit-vec-b->a ( spring -- vec )
-  [ spring-node-a node-pos ] [ spring-node-b node-pos ] bi v- ;
+  [ spring-node-a pos>> ] [ spring-node-b pos>> ] bi v- ;
 
 : relative-velocity-along-spring-a ( spring -- vel )
   [ relative-velocity-a ] [ unit-vec-b->a ] bi vector-projection ;
@@ -126,10 +130,10 @@ C: <spring> spring
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 : relative-velocity-b ( spring -- vel )
-  [ spring-node-b node-vel ] [ spring-node-a node-vel ] bi v- ;
+  [ spring-node-b vel>> ] [ spring-node-a vel>> ] bi v- ;
 
 : unit-vec-a->b ( spring -- vec )
-  [ spring-node-b node-pos ] [ spring-node-a node-pos ] bi v- ;
+  [ spring-node-b pos>> ] [ spring-node-a pos>> ] bi v- ;
 
 : relative-velocity-along-spring-b ( spring -- vel )
   [ relative-velocity-b ] [ unit-vec-a->b ] bi vector-projection ;
@@ -210,9 +214,9 @@ C: <spring> spring
 : calc-acceleration ( node -- vec ) [ node-force ] [ node-mass ] bi v/n ;
 
 : new-vel ( node -- vel )
-  [ node-vel ] [ calc-acceleration time-slice> v*n ] bi v+ ;
+  [ vel>> ] [ calc-acceleration time-slice> v*n ] bi v+ ;
 
-: new-pos ( node -- pos ) [ node-pos ] [ node-vel time-slice> v*n ] bi v+ ;
+: new-pos ( node -- pos ) [ pos>> ] [ vel>> time-slice> v*n ] bi v+ ;
 
 : iterate-node ( node -- )
   dup new-pos >>pos
@@ -231,16 +235,21 @@ C: <spring> spring
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 : mass ( id x y x-vel y-vel mass elas -- )
-  7 nrot drop
-  6 nrot 6 nrot 2array
-  5 nrot 5 nrot 2array
-  0 0 2array <node>
-  nodes> swap suffix >nodes ;
+  node new
+    swap >>elas
+    swap >>mass
+    -rot 2array >>vel
+    -rot 2array >>pos
+    0 0  2array >>force
+  nodes> swap suffix >nodes
+  drop ;
 
 : spng ( id id-a id-b k damp rest-length -- )
-  6 nrot drop
-  -rot
-  5 nrot node-id
-  5 nrot node-id
-  <spring>
-  springs> swap suffix >springs ;
+   spring new
+     swap >>rest-length
+     swap >>damp
+     swap >>k
+     swap node-id >>node-b
+     swap node-id >>node-a
+   springs> swap suffix >springs
+   drop ;
\ No newline at end of file
diff --git a/extra/springies/ui/ui.factor b/extra/springies/ui/ui.factor
index 8aabe6b70b..365632e974 100644
--- a/extra/springies/ui/ui.factor
+++ b/extra/springies/ui/ui.factor
@@ -1,16 +1,16 @@
 
 USING: kernel namespaces threads sequences math math.vectors
        opengl.gl opengl colors ui ui.gadgets ui.gadgets.slate
-       fry rewrite-closures vars springies ;
+       fry rewrite-closures vars springies accessors math.geometry.rect ;
 
 IN: springies.ui
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-: draw-node ( node -- ) node-pos { -5 -5 } v+ dup { 10 10 } v+ gl-rect ;
+: draw-node ( node -- ) pos>> { -5 -5 } v+ dup { 10 10 } v+ gl-rect ;
 
 : draw-spring ( spring -- )
-  [ spring-node-a node-pos ] [ spring-node-b node-pos ] bi gl-line ;
+  [ spring-node-a pos>> ] [ spring-node-b pos>> ] bi gl-line ;
 
 : draw-nodes ( -- ) nodes> [ draw-node ] each ;
 

From e890b7a4bc53cb417d8782de8f39a821f735e9eb Mon Sep 17 00:00:00 2001
From: Eduardo Cavazos <dharmatech@finkelstein.stackeffects.info>
Date: Fri, 11 Jul 2008 20:31:15 -0500
Subject: [PATCH 10/17] More math.geometry.rect updates

---
 extra/ui/cocoa/cocoa.factor     | 2 +-
 extra/ui/windows/windows.factor | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/extra/ui/cocoa/cocoa.factor b/extra/ui/cocoa/cocoa.factor
index bf28740ecc..0085376eaa 100755
--- a/extra/ui/cocoa/cocoa.factor
+++ b/extra/ui/cocoa/cocoa.factor
@@ -5,7 +5,7 @@ command-line kernel memory namespaces cocoa.messages
 cocoa.runtime cocoa.subclassing cocoa.pasteboard cocoa.types
 cocoa.windows cocoa.classes cocoa.application sequences system
 ui ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds
-ui.cocoa.views core-foundation threads ;
+ui.cocoa.views core-foundation threads math.geometry.rect ;
 IN: ui.cocoa
 
 TUPLE: handle view window ;
diff --git a/extra/ui/windows/windows.factor b/extra/ui/windows/windows.factor
index 231dd7f8a5..a210287439 100755
--- a/extra/ui/windows/windows.factor
+++ b/extra/ui/windows/windows.factor
@@ -8,7 +8,7 @@ sequences strings vectors words windows.kernel32 windows.gdi32
 windows.user32 windows.opengl32 windows.messages windows.types
 windows.nt windows threads libc combinators continuations
 command-line shuffle opengl ui.render unicode.case ascii
-math.bitfields locals symbols accessors ;
+math.bitfields locals symbols accessors math.geometry.rect ;
 IN: ui.windows
 
 SINGLETON: windows-ui-backend

From 466a3fecd16166834e5a2bd254a14772c3a592fe Mon Sep 17 00:00:00 2001
From: Eduardo Cavazos <dharmatech@finkelstein.stackeffects.info>
Date: Fri, 11 Jul 2008 20:47:07 -0500
Subject: [PATCH 11/17] ui.cocoa.views: math.geometry.rect

---
 extra/ui/cocoa/views/views.factor | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/extra/ui/cocoa/views/views.factor b/extra/ui/cocoa/views/views.factor
index 68db5954d5..3bacad20b4 100755
--- a/extra/ui/cocoa/views/views.factor
+++ b/extra/ui/cocoa/views/views.factor
@@ -4,7 +4,7 @@ USING: accessors alien alien.c-types arrays assocs cocoa kernel
 math cocoa.messages cocoa.subclassing cocoa.classes cocoa.views
 cocoa.application cocoa.pasteboard cocoa.types cocoa.windows
 sequences ui ui.gadgets ui.gadgets.worlds ui.gestures
-core-foundation threads combinators ;
+core-foundation threads combinators math.geometry.rect ;
 IN: ui.cocoa.views
 
 : send-mouse-moved ( view event -- )

From 7e24f26b4d5baf5db0084ea2716adac3e288ca5d Mon Sep 17 00:00:00 2001
From: "U-VICTORIA\\Administrator" <Administrator@victoria.(none)>
Date: Fri, 11 Jul 2008 18:49:11 -0700
Subject: [PATCH 12/17] Add missing import to ui.windows

---
 extra/ui/windows/windows.factor | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/extra/ui/windows/windows.factor b/extra/ui/windows/windows.factor
index 231dd7f8a5..a210287439 100755
--- a/extra/ui/windows/windows.factor
+++ b/extra/ui/windows/windows.factor
@@ -8,7 +8,7 @@ sequences strings vectors words windows.kernel32 windows.gdi32
 windows.user32 windows.opengl32 windows.messages windows.types
 windows.nt windows threads libc combinators continuations
 command-line shuffle opengl ui.render unicode.case ascii
-math.bitfields locals symbols accessors ;
+math.bitfields locals symbols accessors math.geometry.rect ;
 IN: ui.windows
 
 SINGLETON: windows-ui-backend

From f3d63e34acb79bb5558735cbc16f56f104352d92 Mon Sep 17 00:00:00 2001
From: "U-VICTORIA\\Administrator" <Administrator@victoria.(none)>
Date: Fri, 11 Jul 2008 18:50:26 -0700
Subject: [PATCH 13/17] Add LPGUID typedef to windows.ole32

---
 extra/windows/ole32/ole32.factor | 1 +
 1 file changed, 1 insertion(+)

diff --git a/extra/windows/ole32/ole32.factor b/extra/windows/ole32/ole32.factor
index 7daba37063..0e74dcfca3 100755
--- a/extra/windows/ole32/ole32.factor
+++ b/extra/windows/ole32/ole32.factor
@@ -10,6 +10,7 @@ TYPEDEF: void* LPUNKNOWN
 TYPEDEF: wchar_t* LPOLESTR
 TYPEDEF: wchar_t* LPCOLESTR
 
+TYPEDEF: REFGUID LPGUID
 TYPEDEF: REFGUID REFIID
 TYPEDEF: REFGUID REFCLSID
 

From 8d311fbf76e991c96542ff94da988b3f49cc382e Mon Sep 17 00:00:00 2001
From: "U-VICTORIA\\Administrator" <Administrator@victoria.(none)>
Date: Fri, 11 Jul 2008 18:51:25 -0700
Subject: [PATCH 14/17] Update bunny, spheres, demo-support to use delegation

---
 extra/bunny/bunny.factor                      | 20 +++++++------------
 extra/opengl/demo-support/demo-support.factor | 14 ++++++-------
 extra/spheres/spheres.factor                  |  5 ++---
 3 files changed, 16 insertions(+), 23 deletions(-)

diff --git a/extra/bunny/bunny.factor b/extra/bunny/bunny.factor
index b4cefbc5bd..06959c91c2 100755
--- a/extra/bunny/bunny.factor
+++ b/extra/bunny/bunny.factor
@@ -7,28 +7,23 @@ opengl.demo-support multiline ui.gestures bunny.fixed-pipeline
 bunny.cel-shaded bunny.outlined bunny.model accessors destructors ;
 IN: bunny
 
-TUPLE: bunny-gadget model geom draw-seq draw-n ;
+TUPLE: bunny-gadget < demo-gadget model-triangles geom draw-seq draw-n ;
 
 : <bunny-gadget> ( -- bunny-gadget )
-    0.0 0.0 0.375 <demo-gadget>
-    maybe-download read-model {
-        set-delegate
-        (>>model)
-    } bunny-gadget construct ;
+    0.0 0.0 0.375 bunny-gadget new-demo-gadget
+    maybe-download read-model >>model-triangles ;
 
 : bunny-gadget-draw ( gadget -- draw )
-    { draw-n>> draw-seq>> }
-    get-slots nth ;
+    [ draw-n>> ] [ draw-seq>> ] bi nth ;
 
 : bunny-gadget-next-draw ( gadget -- )
-    dup { draw-seq>> draw-n>> }
-    get-slots
+    dup [ draw-seq>> ] [ draw-n>> ] bi
     1+ swap length mod
     >>draw-n relayout-1 ;
 
 M: bunny-gadget graft* ( gadget -- )
     GL_DEPTH_TEST glEnable
-    dup model>> <bunny-geom> >>geom
+    dup model-triangles>> <bunny-geom> >>geom
     dup
     [ <bunny-fixed-pipeline> ]
     [ <bunny-cel-shaded> ]
@@ -48,8 +43,7 @@ M: bunny-gadget draw-gadget* ( gadget -- )
         dup demo-gadget-set-matrices
         GL_MODELVIEW glMatrixMode
         0.02 -0.105 0.0 glTranslatef
-        { geom>> bunny-gadget-draw } get-slots
-        draw-bunny
+        [ geom>> ] [ bunny-gadget-draw ] bi draw-bunny
     ] if ;
 
 M: bunny-gadget pref-dim* ( gadget -- dim )
diff --git a/extra/opengl/demo-support/demo-support.factor b/extra/opengl/demo-support/demo-support.factor
index 5dcbd526f2..2bf2abae95 100755
--- a/extra/opengl/demo-support/demo-support.factor
+++ b/extra/opengl/demo-support/demo-support.factor
@@ -9,10 +9,10 @@ IN: opengl.demo-support
 
 SYMBOL: last-drag-loc
 
-TUPLE: demo-gadget yaw pitch distance ;
+TUPLE: demo-gadget < gadget yaw pitch distance ;
 
-: <demo-gadget> ( yaw pitch distance -- gadget )
-    demo-gadget construct-gadget
+: new-demo-gadget ( yaw pitch distance class -- gadget )
+    new-gadget
         swap >>distance
         swap >>pitch
         swap >>yaw ;
@@ -31,19 +31,19 @@ M: demo-gadget distance-step ( gadget -- dz )
 : fov-ratio ( gadget -- fov ) dim>> dup first2 min v/n ;
 
 : yaw-demo-gadget ( yaw gadget -- )
-    [ [ demo-gadget-yaw + ] keep set-demo-gadget-yaw ] keep relayout-1 ;
+    [ + ] with change-yaw relayout-1 ;
 
 : pitch-demo-gadget ( pitch gadget -- )
-    [ [ demo-gadget-pitch + ] keep set-demo-gadget-pitch ] keep relayout-1 ;
+    [ + ] with change-pitch relayout-1 ;
 
 : zoom-demo-gadget ( distance gadget -- )
-    [ [ demo-gadget-distance + ] keep set-demo-gadget-distance ] keep relayout-1 ;
+    [ + ] with change-distance relayout-1 ;
 
 M: demo-gadget pref-dim* ( gadget -- dim )
     drop { 640 480 } ;
 
 : -+ ( x -- -x x )
-    dup neg swap ;
+    [ neg ] keep ;
 
 : demo-gadget-frustum ( gadget -- -x x -y y near far )
     [ near-plane ] [ far-plane ] [ fov-ratio ] tri [
diff --git a/extra/spheres/spheres.factor b/extra/spheres/spheres.factor
index dff7313eec..9607f6d201 100755
--- a/extra/spheres/spheres.factor
+++ b/extra/spheres/spheres.factor
@@ -99,14 +99,13 @@ main()
 }
 ;
 
-TUPLE: spheres-gadget
+TUPLE: spheres-gadget < demo-gadget
     plane-program solid-sphere-program texture-sphere-program
     reflection-framebuffer reflection-depthbuffer
     reflection-texture ;
 
 : <spheres-gadget> ( -- gadget )
-    20.0 10.0 20.0 <demo-gadget>
-    { set-delegate } spheres-gadget construct ;
+    20.0 10.0 20.0 spheres-gadget new-demo-gadget ;
 
 M: spheres-gadget near-plane ( gadget -- z )
     drop 1.0 ;

From b19c3ee65e7655fbb9ce71692751bfe31a4e8ada Mon Sep 17 00:00:00 2001
From: Joe Groff <arcata@gmail.com>
Date: Fri, 11 Jul 2008 19:34:42 -0700
Subject: [PATCH 15/17] use single-precision floats in bunny vertex buffers for
 much better performance

---
 extra/bunny/model/model.factor | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/extra/bunny/model/model.factor b/extra/bunny/model/model.factor
index fce73785b5..6723f94353 100755
--- a/extra/bunny/model/model.factor
+++ b/extra/bunny/model/model.factor
@@ -2,7 +2,7 @@ USING: alien alien.c-types arrays sequences math math.vectors
 math.matrices math.parser io io.files kernel opengl opengl.gl
 opengl.glu io.encodings.ascii opengl.capabilities shuffle
 http.client vectors splitting system combinators
-float-arrays continuations destructors namespaces sequences.lib
+continuations destructors namespaces sequences.lib
 accessors ;
 IN: bunny.model
 
@@ -66,7 +66,7 @@ TUPLE: bunny-buffers array element-array nv ni ;
     {
         [
             [ first concat ] [ second concat ] bi
-            append >c-double-array
+            append >c-float-array
             GL_ARRAY_BUFFER swap GL_STATIC_DRAW <gl-buffer>
         ]
         [
@@ -86,10 +86,10 @@ M: bunny-dlist bunny-geom
 M: bunny-buffers bunny-geom
     dup { array>> element-array>> } get-slots [
         { GL_VERTEX_ARRAY GL_NORMAL_ARRAY } [
-            GL_DOUBLE 0 0 buffer-offset glNormalPointer
+            GL_FLOAT 0 0 buffer-offset glNormalPointer
             [
-                nv>> "double" heap-size * buffer-offset
-                3 GL_DOUBLE 0 roll glVertexPointer
+                nv>> "float" heap-size * buffer-offset
+                3 GL_FLOAT 0 roll glVertexPointer
             ] [
                 ni>>
                 GL_TRIANGLES swap GL_UNSIGNED_INT 0 buffer-offset glDrawElements

From 5b0fbf9abf092fac48da24353ba1632c6e703adc Mon Sep 17 00:00:00 2001
From: Joe Groff <arcata@gmail.com>
Date: Fri, 11 Jul 2008 19:48:41 -0700
Subject: [PATCH 16/17] Whip the out-of-control USING: lines in bunny into
 shape

---
 extra/bunny/bunny.factor       | 10 +++-------
 extra/bunny/model/model.factor | 10 ++++------
 2 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/extra/bunny/bunny.factor b/extra/bunny/bunny.factor
index 06959c91c2..ed89f2a809 100755
--- a/extra/bunny/bunny.factor
+++ b/extra/bunny/bunny.factor
@@ -1,10 +1,6 @@
-USING: alien alien.c-types arrays sequences math math.vectors
-math.matrices math.parser io io.files kernel opengl opengl.gl
-opengl.glu shuffle http.client vectors namespaces ui.gadgets
-ui.gadgets.canvas ui.render ui splitting combinators
-system combinators.lib float-arrays continuations
-opengl.demo-support multiline ui.gestures bunny.fixed-pipeline
-bunny.cel-shaded bunny.outlined bunny.model accessors destructors ;
+USING: accessors arrays bunny.cel-shaded bunny.fixed-pipeline
+bunny.model bunny.outlined destructors kernel math opengl.demo-support
+opengl.gl sequences ui ui.gadgets ui.gestures ui.render words ;
 IN: bunny
 
 TUPLE: bunny-gadget < demo-gadget model-triangles geom draw-seq draw-n ;
diff --git a/extra/bunny/model/model.factor b/extra/bunny/model/model.factor
index 6723f94353..f64030ff70 100755
--- a/extra/bunny/model/model.factor
+++ b/extra/bunny/model/model.factor
@@ -1,9 +1,7 @@
-USING: alien alien.c-types arrays sequences math math.vectors
-math.matrices math.parser io io.files kernel opengl opengl.gl
-opengl.glu io.encodings.ascii opengl.capabilities shuffle
-http.client vectors splitting system combinators
-continuations destructors namespaces sequences.lib
-accessors ;
+USING: accessors alien.c-types arrays combinators destructors http.client
+io io.encodings.ascii io.files kernel math math.matrices math.parser
+math.vectors opengl opengl.capabilities opengl.gl sequences sequences.lib
+splitting vectors words ;
 IN: bunny.model
 
 : numbers ( str -- seq )

From 7608afbf4c445f1a6da613019fa9a67e86473c1a Mon Sep 17 00:00:00 2001
From: Joe Groff <arcata@gmail.com>
Date: Fri, 11 Jul 2008 20:16:22 -0700
Subject: [PATCH 17/17] duh... bunny.outlined needs to update the framebuffer
 size after it builds it!

---
 extra/bunny/outlined/outlined.factor | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/extra/bunny/outlined/outlined.factor b/extra/bunny/outlined/outlined.factor
index f3ee4594c7..fcba98a0e9 100755
--- a/extra/bunny/outlined/outlined.factor
+++ b/extra/bunny/outlined/outlined.factor
@@ -181,10 +181,9 @@ TUPLE: bunny-outlined
     ] [ drop ] if ;
 
 : remake-framebuffer-if-needed ( draw -- )
-    dup [ gadget>> dim>> ] [ framebuffer-dim>> ] bi
-    over =
-    [ 2drop ] [
-        [ dup dispose-framebuffer dup ] dip {
+    dup [ gadget>> dim>> ] [ framebuffer-dim>> ] bi =
+    [ drop ] [
+        [ dispose-framebuffer ] [ dup ] [ gadget>> dim>> ] tri {
             [
                 GL_RGBA16F_ARB GL_RGBA (framebuffer-texture)
                 [ >>color-texture drop ] keep
@@ -196,7 +195,8 @@ TUPLE: bunny-outlined
                 [ >>depth-texture drop ] keep
             ]
         } 2cleave
-        (make-framebuffer) >>framebuffer drop
+        [ (make-framebuffer) >>framebuffer ] [ >>framebuffer-dim ] bi
+        drop
     ] if ;
 
 : clear-framebuffer ( -- )