| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** Various utility functions. | ||
| 2 | * | ||
| 3 | * Copyright 2008 Marco Cecchetti <mrcekets at gmail.com> | ||
| 4 | * Copyright 2007 Johan Engelen <goejendaagh@zonnet.nl> | ||
| 5 | * Copyright 2006 Michael G. Sloan <mgsloan@gmail.com> | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it either under the terms of the GNU Lesser General Public | ||
| 9 | * License version 2.1 as published by the Free Software Foundation | ||
| 10 | * (the "LGPL") or, at your option, under the terms of the Mozilla | ||
| 11 | * Public License Version 1.1 (the "MPL"). If you do not alter this | ||
| 12 | * notice, a recipient may use your version of this file under either | ||
| 13 | * the MPL or the LGPL. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the LGPL along with this library | ||
| 16 | * in the file COPYING-LGPL-2.1; if not, write to the Free Software | ||
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 18 | * You should have received a copy of the MPL along with this library | ||
| 19 | * in the file COPYING-MPL-1.1 | ||
| 20 | * | ||
| 21 | * The contents of this file are subject to the Mozilla Public License | ||
| 22 | * Version 1.1 (the "License"); you may not use this file except in | ||
| 23 | * compliance with the License. You may obtain a copy of the License at | ||
| 24 | * http://www.mozilla.org/MPL/ | ||
| 25 | * | ||
| 26 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY | ||
| 27 | * OF ANY KIND, either express or implied. See the LGPL or the MPL for | ||
| 28 | * the specific language governing rights and limitations. | ||
| 29 | * | ||
| 30 | */ | ||
| 31 | |||
| 32 | |||
| 33 | #include <2geom/utils.h> | ||
| 34 | |||
| 35 | |||
| 36 | namespace Geom | ||
| 37 | { | ||
| 38 | |||
| 39 | // return a vector that contains all the binomial coefficients of degree n | ||
| 40 | ✗ | void binomial_coefficients(std::vector<size_t>& bc, std::size_t n) | |
| 41 | { | ||
| 42 | ✗ | size_t s = n+1; | |
| 43 | ✗ | bc.clear(); | |
| 44 | ✗ | bc.resize(s); | |
| 45 | ✗ | bc[0] = 1; | |
| 46 | ✗ | for (size_t i = 1; i < n; ++i) | |
| 47 | { | ||
| 48 | ✗ | size_t k = i >> 1; | |
| 49 | ✗ | if (i & 1u) | |
| 50 | { | ||
| 51 | ✗ | bc[k+1] = bc[k] << 1; | |
| 52 | } | ||
| 53 | ✗ | for (size_t j = k; j > 0; --j) | |
| 54 | { | ||
| 55 | ✗ | bc[j] += bc[j-1]; | |
| 56 | } | ||
| 57 | } | ||
| 58 | ✗ | s >>= 1; | |
| 59 | ✗ | for (size_t i = 0; i < s; ++i) | |
| 60 | { | ||
| 61 | ✗ | bc[n-i] = bc[i]; | |
| 62 | } | ||
| 63 | ✗ | } | |
| 64 | |||
| 65 | } // end namespace Geom | ||
| 66 | |||
| 67 | |||
| 68 | |||
| 69 | |||
| 70 | |||
| 71 | |||
| 72 | |||
| 73 | |||
| 74 | |||
| 75 | |||
| 76 | |||
| 77 | /* | ||
| 78 | Local Variables: | ||
| 79 | mode:c++ | ||
| 80 | c-file-style:"stroustrup" | ||
| 81 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) | ||
| 82 | indent-tabs-mode:nil | ||
| 83 | fill-column:99 | ||
| 84 | End: | ||
| 85 | */ | ||
| 86 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : | ||
| 87 |