Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A bounding box is usually a rectangle. I don't think a circle located at (-r,-r) is the bounding box of a circle of radius r....</p> <p>Anyway, suppose you have a bounding box b1 and another b2 and a function <code>combineBoxes</code> that computes the bounding box of b1 and b2.</p> <p>Then if you have a <em>non-empty</em> set of shapes in your group, you can use <code>reduceLeft</code> to compute the whole bounding box of a list of bounding boxes by combining them two at a time until only one giant box remains. (The same idea can be used to reduce a list of numbers to a sum of numbers by adding them in pairs. And it's called <code>reduceLeft</code> because it works left to right across the list.)</p> <p>Suppose that <code>blist</code> is a list of bounding boxes of each shape. (Hint: this is where <code>map</code> comes in.) Then</p> <pre><code>val bigBox = blist reduceLeft( (box1,box2) =&gt; combineBoxes(box1,box2) ) </code></pre> <p>You'll need to catch the empty group case separately, however. (Since it has a no well-defined bounding box, you don't want to use folds; folds are good for when there is a default empty case that makes sense. Or you have to fold with <code>Option</code>, but then your combining function has to understand how to combine <code>None</code> with <code>Some(box)</code>, which is probably not worth it in this case--but very well might be if you were writing production code that needs to elegantly handle various sorts of empty list situations.)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload