math.vectors: new word vclamp for clamping vectors
parent
7a4e345f6c
commit
cb39da4b31
|
@ -85,6 +85,7 @@ $nl
|
||||||
vunordered?
|
vunordered?
|
||||||
vmax
|
vmax
|
||||||
vmin
|
vmin
|
||||||
|
vclamp
|
||||||
vsupremum
|
vsupremum
|
||||||
vinfimum
|
vinfimum
|
||||||
}
|
}
|
||||||
|
@ -302,6 +303,17 @@ HELP: vmin
|
||||||
{ $description "Creates a sequence where each element is the minimum of the corresponding elements from " { $snippet "u" } " and " { $snippet "v" } "." }
|
{ $description "Creates a sequence where each element is the minimum of the corresponding elements from " { $snippet "u" } " and " { $snippet "v" } "." }
|
||||||
{ $examples { $example "USING: math.vectors prettyprint ;" "{ 1 2 5 } { -7 6 3 } vmin ." "{ -7 2 3 }" } } ;
|
{ $examples { $example "USING: math.vectors prettyprint ;" "{ 1 2 5 } { -7 6 3 } vmin ." "{ -7 2 3 }" } } ;
|
||||||
|
|
||||||
|
HELP: vclamp
|
||||||
|
{ $values { "v" "a sequence of real numbers" } { "min" "a sequence of real numbers" } { "max" "a sequence of real numbers" } }
|
||||||
|
{ $description "Creates a sequence where each element is clamped to the minimum and maximum elements of the " { $snippet "min" } " and " { $snippet "max" } " sequences." }
|
||||||
|
{ $examples
|
||||||
|
{ $example
|
||||||
|
"USING: math.vectors prettyprint ;"
|
||||||
|
"{ -10 30 120 } { 0 0 0 } { 100 100 100 } vclamp ."
|
||||||
|
"{ 0 30 100 }"
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
HELP: v.
|
HELP: v.
|
||||||
{ $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "x" "a real number" } }
|
{ $values { "u" "a sequence of real numbers" } { "v" "a sequence of real numbers" } { "x" "a real number" } }
|
||||||
{ $description "Computes the dot product of two vectors." } ;
|
{ $description "Computes the dot product of two vectors." } ;
|
||||||
|
|
|
@ -47,3 +47,8 @@ SPECIALIZED-ARRAY: int
|
||||||
{ { 1 5 3 } } [
|
{ { 1 5 3 } } [
|
||||||
{ t f t } [ { 1 2 3 } ] [ { 4 5 6 } ] vif
|
{ t f t } [ { 1 2 3 } ] [ { 4 5 6 } ] vif
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
! vclamp
|
||||||
|
{ { 0 30 100 } } [
|
||||||
|
{ -10 30 120 } { 0 0 0 } { 100 100 100 } vclamp
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -276,3 +276,6 @@ PRIVATE>
|
||||||
|
|
||||||
: v~ ( a b epsilon -- ? )
|
: v~ ( a b epsilon -- ? )
|
||||||
[ ~ ] curry 2all? ; inline
|
[ ~ ] curry 2all? ; inline
|
||||||
|
|
||||||
|
: vclamp ( v min max -- w )
|
||||||
|
rot vmin vmax ; inline
|
||||||
|
|
|
@ -152,7 +152,7 @@ terrain-world H{
|
||||||
GRAVITY v+ ;
|
GRAVITY v+ ;
|
||||||
|
|
||||||
: clamp-coords ( coords dim -- coords' )
|
: clamp-coords ( coords dim -- coords' )
|
||||||
[ { 0 0 } vmax ] dip { 2 2 } v- vmin ;
|
{ 0 0 } swap { 2 2 } v- vclamp ;
|
||||||
|
|
||||||
:: pixel-indices ( coords dim -- indices )
|
:: pixel-indices ( coords dim -- indices )
|
||||||
coords vfloor v>integer dim clamp-coords :> floor-coords
|
coords vfloor v>integer dim clamp-coords :> floor-coords
|
||||||
|
|
|
@ -101,7 +101,7 @@ M: list focusable-child* drop t ;
|
||||||
[ list select-index ] when* ;
|
[ list select-index ] when* ;
|
||||||
|
|
||||||
: clamp-loc ( point max -- point )
|
: clamp-loc ( point max -- point )
|
||||||
vmin { 0 0 } vmax ;
|
{ 0 0 } swap vclamp ;
|
||||||
|
|
||||||
: select-at ( point list -- )
|
: select-at ( point list -- )
|
||||||
[ dim>> clamp-loc ] keep
|
[ dim>> clamp-loc ] keep
|
||||||
|
|
Loading…
Reference in New Issue