From 8162be94bd906a671678a412e48207cfe5e9ca95 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sat, 21 Feb 2015 15:45:07 -0800 Subject: [PATCH] vector-break-at --- quad/wrap-typed.rkt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/quad/wrap-typed.rkt b/quad/wrap-typed.rkt index eeae06dd..00158071 100644 --- a/quad/wrap-typed.rkt +++ b/quad/wrap-typed.rkt @@ -2,7 +2,7 @@ (require (for-syntax racket/base racket/syntax)) (require/typed sugar/list [slicef-after ((Listof Quad) (Quad . -> . Boolean) . -> . (Listof (Listof Quad)))] [shift ((Listof Any) (Listof Integer) . -> . (Listof Any))]) -(require math/flonum (except-in racket/list flatten)) +(require math/flonum (except-in racket/list flatten) racket/vector) (require/typed racket/list [flatten (All (A) (Rec as (U Any (Listof as))) -> (Listof Any))]) (require "ocm-typed.rkt" "quads-typed.rkt" "utils-typed.rkt" "measure-typed.rkt" "world-typed.rkt" "logger-typed.rkt") @@ -320,4 +320,14 @@ (cast (for*/sum : (U Flonum Zero) ([rendered-piece (in-list (render-pieces ps))] [piece-quad (in-list (quad-list rendered-piece))]) - (quad-width (cast piece-quad Quad))) Flonum)) \ No newline at end of file + (quad-width (cast piece-quad Quad))) Flonum)) + + +(define/typed (vector-break-at vec bps) + ((Vectorof Any) (Listof Nonnegative-Integer) . -> . (Listof (Vectorof Any))) + (define-values (vecs _) ;; loop backward + (for/fold ([vecs : (Listof (Vectorof Any)) empty][end : Nonnegative-Integer (vector-length vec)])([start (in-list (reverse (cons 0 bps)))]) + (if (= start end) + (values vecs start) + (values (cons ((inst vector-copy Any) vec start end) vecs) start)))) + vecs)