1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
use na::{DefaultAllocator}; use aliases::TVec; use traits::{Number, Alloc, Dimension}; /// Checks that all the vector components are `true`. /// /// # Examples: /// /// ``` /// # use nalgebra_glm as glm; /// let vec = glm::vec2(true, false); /// assert_eq!(false, glm::all(&vec)); /// /// let vec = glm::vec2(true, true); /// assert_eq!(true, glm::all(&vec)); /// ``` /// /// # See also: /// /// * [`any`](fn.any.html) /// * [`not`](fn.not.html) pub fn all<D: Dimension>(v: &TVec<bool, D>) -> bool where DefaultAllocator: Alloc<bool, D> { v.iter().all(|x| *x) } /// Checks that at least one of the vector components is `true`. /// /// # Examples: /// /// ``` /// # use nalgebra_glm as glm; /// let vec = glm::vec2(true, false); /// assert_eq!(true, glm::any(&vec)); /// /// let vec = glm::vec2(true, true); /// assert_eq!(true, glm::any(&vec)); /// /// let vec = glm::vec2(false, false); /// assert_eq!(false, glm::any(&vec)); /// ``` /// /// # See also: /// /// * [`all`](fn.all.html) /// * [`not`](fn.not.html) pub fn any<D: Dimension>(v: &TVec<bool, D>) -> bool where DefaultAllocator: Alloc<bool, D> { v.iter().any(|x| *x) } /// Component-wise equality comparison. /// /// See also: /// /// * [`equal`](fn.equal.html) /// * [`greater_than`](fn.greater_than.html) /// * [`greater_than_equal`](fn.greater_than_equal.html) /// * [`less_than`](fn.less_than.html) /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) pub fn equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D> where DefaultAllocator: Alloc<N, D> { x.zip_map(y, |x, y| x == y) } /// Component-wise `>` comparison. /// /// See also: /// /// * [`equal`](fn.equal.html) /// * [`greater_than`](fn.greater_than.html) /// * [`greater_than_equal`](fn.greater_than_equal.html) /// * [`less_than`](fn.less_than.html) /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) pub fn greater_than<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D> where DefaultAllocator: Alloc<N, D> { x.zip_map(y, |x, y| x > y) } /// Component-wise `>=` comparison. /// /// See also: /// /// * [`equal`](fn.equal.html) /// * [`greater_than`](fn.greater_than.html) /// * [`greater_than_equal`](fn.greater_than_equal.html) /// * [`less_than`](fn.less_than.html) /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) pub fn greater_than_equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D> where DefaultAllocator: Alloc<N, D> { x.zip_map(y, |x, y| x >= y) } /// Component-wise `<` comparison. /// /// See also: /// /// * [`equal`](fn.equal.html) /// * [`greater_than`](fn.greater_than.html) /// * [`greater_than_equal`](fn.greater_than_equal.html) /// * [`less_than`](fn.less_than.html) /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) pub fn less_than<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D> where DefaultAllocator: Alloc<N, D> { x.zip_map(y, |x, y| x < y) } /// Component-wise `>=` comparison. /// /// See also: /// /// * [`equal`](fn.equal.html) /// * [`greater_than`](fn.greater_than.html) /// * [`greater_than_equal`](fn.greater_than_equal.html) /// * [`less_than`](fn.less_than.html) /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) pub fn less_than_equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D> where DefaultAllocator: Alloc<N, D> { x.zip_map(y, |x, y| x <= y) } /// Component-wise not `!`. /// /// # Examples: /// /// ``` /// # use nalgebra_glm as glm; /// let vec = glm::vec2(true, false); /// assert_eq!(glm::vec2(false, true), glm::not(&vec)); /// ``` /// /// See also: /// /// * [`all`](fn.all.html) /// * [`any`](fn.any.html) /// * [`equal`](fn.equal.html) /// * [`greater_than`](fn.greater_than.html) /// * [`greater_than_equal`](fn.greater_than_equal.html) /// * [`less_than`](fn.less_than.html) /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) pub fn not<D: Dimension>(v: &TVec<bool, D>) -> TVec<bool, D> where DefaultAllocator: Alloc<bool, D> { v.map(|x| !x) } /// Component-wise not-equality `!=`. /// /// See also: /// /// * [`equal`](fn.equal.html) /// * [`greater_than`](fn.greater_than.html) /// * [`greater_than_equal`](fn.greater_than_equal.html) /// * [`less_than`](fn.less_than.html) /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not_equal`](fn.not_equal.html) pub fn not_equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D> where DefaultAllocator: Alloc<N, D> { x.zip_map(y, |x, y| x != y) }