]> gitweb.factorcode.org Git - factor.git/commitdiff
Fix conflict
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 6 Feb 2009 04:29:15 +0000 (22:29 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 6 Feb 2009 04:29:15 +0000 (22:29 -0600)
1  2 
basis/math/rectangles/rectangles-tests.factor
basis/math/rectangles/rectangles.factor
basis/math/vectors/vectors.factor
basis/xml/writer/writer-tests.factor
extra/quadtrees/quadtrees-docs.factor
extra/quadtrees/quadtrees-tests.factor
extra/quadtrees/quadtrees.factor

index 332a3ef52dd3b5bda26e4130f16b9d4b0a305478,0000000000000000000000000000000000000000..ca722859d261f6616faabe77ea2f32bcc9558690
mode 100644,000000..100644
--- /dev/null
@@@ -1,35 -1,0 +1,42 @@@
 +USING: tools.test math.rectangles ;
 +IN: math.rectangles.tests
 +
 +[ T{ rect f { 10 10 } { 20 20 } } ]
 +[
 +    T{ rect f { 10 10 } { 50 50 } }
 +    T{ rect f { -10 -10 } { 40 40 } }
 +    rect-intersect
 +] unit-test
 +
 +[ T{ rect f { 200 200 } { 0 0 } } ]
 +[
 +    T{ rect f { 100 100 } { 50 50 } }
 +    T{ rect f { 200 200 } { 40 40 } }
 +    rect-intersect
 +] unit-test
 +
 +[ f ] [
 +    T{ rect f { 100 100 } { 50 50 } }
 +    T{ rect f { 200 200 } { 40 40 } }
 +    contains-rect?
 +] unit-test
 +
 +[ t ] [
 +    T{ rect f { 100 100 } { 50 50 } }
 +    T{ rect f { 120 120 } { 40 40 } }
 +    contains-rect?
 +] unit-test
 +
 +[ f ] [
 +    T{ rect f { 1000 100 } { 50 50 } }
 +    T{ rect f { 120 120 } { 40 40 } }
 +    contains-rect?
 +] unit-test
 +
++[ T{ rect f { 10 20 } { 20 20 } } ] [
++    {
++        { 20 20 }
++        { 10 40 }
++        { 30 30 }
++    } rect-containing
++] unit-test
index 1c30253d303c5b13f0906d9405f7a766b15c92de,0000000000000000000000000000000000000000..d3ada2951c3ba4e4858e64e2e74a9eb64e3c6b18
mode 100644,000000..100644
--- /dev/null
@@@ -1,46 -1,0 +1,50 @@@
 +! Copyright (C) 2008, 2009 Slava Pestov.
 +! See http://factorcode.org/license.txt for BSD license.
 +USING: kernel arrays sequences math math.vectors accessors ;
 +IN: math.rectangles
 +
 +TUPLE: rect { loc initial: { 0 0 } } { dim initial: { 0 0 } } ;
 +
 +: <rect> ( loc dim -- rect ) rect boa ; inline
 +
 +: <zero-rect> ( -- rect ) rect new ; inline
 +
 +: point>rect ( loc -- rect ) { 0 0 } <rect> ; inline
 +
 +: rect-bounds ( rect -- loc dim ) [ loc>> ] [ dim>> ] bi ;
 +
 +: rect-extent ( rect -- loc ext ) rect-bounds over v+ ;
 +
 +: with-rect-extents ( rect1 rect2 loc-quot: ( loc1 loc2 -- ) ext-quot: ( ext1 ext2 -- ) -- )
 +    [ [ rect-extent ] bi@ ] 2dip bi-curry* bi* ; inline
 +
 +: <extent-rect> ( loc ext -- rect ) over [v-] <rect> ;
 +
 +: offset-rect ( rect loc -- newrect )
 +    over loc>> v+ swap dim>> <rect> ;
 +
 +: (rect-intersect) ( rect rect -- array array )
 +    [ vmax ] [ vmin ] with-rect-extents ;
 +
 +: rect-intersect ( rect1 rect2 -- newrect )
 +    (rect-intersect) <extent-rect> ;
 +
 +GENERIC: contains-rect? ( rect1 rect2 -- ? )
 +
 +M: rect contains-rect?
 +    (rect-intersect) [v-] { 0 0 } = ;
 +
 +GENERIC: contains-point? ( point rect -- ? )
 +
 +M: rect contains-point?
 +    [ point>rect ] dip contains-rect? ;
 +
 +: (rect-union) ( rect rect -- array array )
 +    [ vmin ] [ vmax ] with-rect-extents ;
 +
 +: rect-union ( rect1 rect2 -- newrect )
 +    (rect-union) <extent-rect> ;
++
++: rect-containing ( points -- rect )
++    [ vsupremum ] [ vinfimum ] bi
++    [ nip ] [ v- ] 2bi <rect> ;
index a6967a7218bb86be4343ff188d380e4d0bfe891b,4d9a0916b5c37c6718e0b6a01154eddd65e2250f..eb5fa7b9705135ae33a099ea5b0ddf4aef1bb8bc
@@@ -19,6 -19,9 +19,9 @@@ IN: math.vector
  : vmax ( u v -- w ) [ max ] 2map ;
  : vmin ( u v -- w ) [ min ] 2map ;
  
 -: vgreatest ( array -- vmax ) { -1.0/0.0 -1.0/0.0 } [ vmax ] reduce ; 
 -: vleast    ( array -- vmax ) {  1.0/0.0  1.0/0.0 } [ vmin ] reduce ; 
++: vsupremum ( seq -- vmax ) [ ] [ vmax ] map-reduce ; 
++: vinfimum ( seq -- vmin ) [ ] [ vmin ] map-reduce ; 
  : v. ( u v -- x ) [ * ] [ + ] 2map-reduce ;
  : norm-sq ( v -- x ) [ absq ] [ + ] map-reduce ;
  : norm ( v -- x ) norm-sq sqrt ;
Simple merge
Simple merge
index 697fd53f3a07a772b1dcba2e9915a661dec4154a,7a17c1fb442e809aff62a3e20d276359471c57d4..993389a4b4acbdea3a0a0f4e2664c2f2717999fb
@@@ -1,5 -1,5 +1,5 @@@
  ! (c) 2009 Joe Groff, see BSD license
- USING: assocs kernel tools.test quadtrees math.rectangles sorting ;
 -USING: accessors assocs kernel tools.test quadtrees math.geometry.rect sorting ;
++USING: accessors assocs kernel tools.test quadtrees math.rectangles sorting ;
  IN: quadtrees.tests
  
  : unit-bounds ( -- rect ) { -1.0 -1.0 } { 2.0 2.0 } <rect> ;
index 383a0907e7ff708ed826fa5c66e11e1780a0cb0d,d9bdbe4aebc9e27e40490fdf623654fcf7904c02..1a916c74f4aa79ef01c03a29b26982add1842006
@@@ -1,17 -1,20 +1,19 @@@
  ! (c) 2009 Joe Groff, see BSD license
 -USING: assocs kernel math.geometry.rect combinators accessors
 -math.vectors vectors sequences math math.points math.geometry
 -combinators.short-circuit arrays fry ;
 +USING: assocs kernel math.rectangles combinators accessors
- math.vectors vectors sequences math math.points math.geometry
- combinators.short-circuit arrays fry locals ;
++math.vectors vectors sequences math combinators.short-circuit arrays fry ;
  IN: quadtrees
  
  TUPLE: quadtree { bounds rect } point value ll lr ul ur leaf? ;
  
- : <quadtree> ( bounds -- quadtree ) f f f f f f t quadtree boa ;
+ : <quadtree> ( bounds -- quadtree )
+     quadtree new
+         swap >>bounds
+         t >>leaf? ;
  
  : rect-ll ( rect -- point ) loc>> ;
--: rect-lr ( rect -- point ) [ loc>> ] [ width  ] bi v+x ;
--: rect-ul ( rect -- point ) [ loc>> ] [ height ] bi v+y ;
--: rect-ur ( rect -- point ) [ loc>> ] [ dim>>  ] bi v+  ;
++: rect-lr ( rect -- point ) [ loc>> ] [ dim>> { 1 0 } v* ] bi v+ ;
++: rect-ul ( rect -- point ) [ loc>> ] [ dim>> { 0 1 } v* ] bi v+ ;
++: rect-ur ( rect -- point ) [ loc>> ] [ dim>>  ] bi v+ ;
  
  : rect-center ( rect -- point ) [ loc>> ] [ dim>> 0.5 v*n ] bi v+ ; inline
  
@@@ -94,12 -100,12 +99,12 @@@ DEFER: in-rect
      dup leaf?>> [ leaf-at-point ] [ node-at-point ] if ;
  
  : (node-in-rect*) ( values rect node -- values )
--    2dup bounds>> intersects? [ in-rect* ] [ 2drop ] if ;
++    2dup bounds>> contains-rect? [ in-rect* ] [ 2drop ] if ;
  : node-in-rect* ( values rect node -- values )
      [ (node-in-rect*) ] with each-quadrant ;
  
  : leaf-in-rect* ( values rect leaf -- values ) 
--    tuck { [ nip point>> ] [ point>> swap intersects? ] } 2&&
++    tuck { [ nip point>> ] [ point>> swap contains-point? ] } 2&&
      [ value>> over push ] [ drop ] if ;
  
  : in-rect* ( values rect tree -- values )