From f75a52474b4505a031b091a40907ada4e76d2648 Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Mon, 1 Dec 2008 13:15:47 -0600 Subject: [PATCH] flatland: minor changes --- extra/flatland/flatland.factor | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/extra/flatland/flatland.factor b/extra/flatland/flatland.factor index a33da32908..c98c5a6c57 100644 --- a/extra/flatland/flatland.factor +++ b/extra/flatland/flatland.factor @@ -176,3 +176,45 @@ METHOD: height ( -- height ) \\ top>> bottom>> bi - ; ! METHOD: to-extent ( -- ) ! { [ left>> ] [ right>> ] [ bottom>> ] [ top>> ] } cleave boa ; +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +METHOD: to-the-left-of? ( sequence -- ? ) \\ x left bi* < ; +METHOD: to-the-right-of? ( sequence -- ? ) \\ x right bi* > ; + +METHOD: below? ( sequence -- ? ) \\ y bottom bi* < ; +METHOD: above? ( sequence -- ? ) \\ y top bi* > ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +! Some support for the' 'rect' class from math.geometry.rect' + +! METHOD: width ( rect -- width ) dim>> first ; +! METHOD: height ( rect -- height ) dim>> second ; + +! METHOD: left ( rect -- left ) loc>> x +! METHOD: right ( rect -- right ) [ loc>> x ] [ width ] bi + ; + +! METHOD: to-the-left-of? ( sequence rect -- ? ) [ x ] [ loc>> x ] bi* < ; +! METHOD: to-the-right-of? ( sequence rect -- ? ) [ x ] [ loc>> x ] bi* > ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +USING: locals combinators ; + +:: wrap ( POINT RECT -- POINT ) + + { + { [ POINT RECT to-the-left-of? ] [ RECT right ] } + { [ POINT RECT to-the-right-of? ] [ RECT left ] } + { [ t ] [ POINT x ] } + } + cond + + { + { [ POINT RECT below? ] [ RECT top ] } + { [ POINT RECT above? ] [ RECT bottom ] } + { [ t ] [ POINT y ] } + } + cond + + 2array ;