Changeset 7799f79 for libcfa/src/vec
 Timestamp:
 Dec 13, 2019, 7:41:58 PM (2 years ago)
 Branches:
 armeh, jacob/cs343translation, master, newastuniqueexpr
 Children:
 ae09808
 Parents:
 ae3db00
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

libcfa/src/vec/vec2.hfa
rae3db00 r7799f79 42 42 // Primitive mathematical operations 43 43 44 // Subtraction45 46 44 forall( subtract(T)) { 47 45 vec2(T) ??(vec2(T) u, vec2(T) v) { // TODO( can't make this const ref ) … … 53 51 } 54 52 } 55 56 forall( negate(T)) { 53 forall( negate(T)) 57 54 vec2(T) ?(vec2(T) v) with (v) { 58 55 return [x, y]; 59 56 } 60 } 61 62 // Addition 57 58 forall( { T ?(T&); }) { 59 vec2(T)& ?(vec2(T)& v) { 60 v.x; 61 v.y; 62 return v; 63 } 64 vec2(T)& ?(vec2(T)& v) { 65 vec2(T) copy = v; 66 v; 67 return copy; 68 } 69 } 70 63 71 forall( add(T)) { 64 72 vec2(T) ?+?(vec2(T) u, vec2(T) v) { // TODO( can't make this const ref ) … … 71 79 } 72 80 73 // Scalar Multiplication 81 forall( { T ++?(T&); }) { 82 vec2(T)& ++?(vec2(T)& v) { 83 ++v.x; 84 ++v.y; 85 return v; 86 } 87 vec2(T)& ?++(vec2(T)& v) { 88 vec2(T) copy = v; 89 ++v; 90 return copy; 91 } 92 } 93 74 94 forall( multiply(T)) { 75 95 vec2(T) ?*?(vec2(T) v, T scalar) with (v) { // TODO (can't make this const ref) … … 79 99 return v * scalar; 80 100 } 101 vec2(T) ?*?(vec2(T) u, vec2(T) v) { 102 return [u.x * v.x, u.y * v.y]; 103 } 81 104 vec2(T)& ?*=?(vec2(T)& v, T scalar) { 82 105 v = v * scalar; 83 106 return v; 84 107 } 85 } 86 87 // Scalar Division 108 vec2(T) ?*=?(vec2(T)& u, vec2(T) v) { 109 u = u * v; 110 return u; 111 } 112 } 113 88 114 forall( divide(T)) { 89 115 vec2(T) ?/?(vec2(T) v, T scalar) with (v) { 90 116 return [x / scalar, y / scalar]; 91 117 } 118 vec2(T) ?/?(vec2(T) u, vec2(T) v) { 119 return [u.x / v.x, u.y / v.y]; 120 } 92 121 vec2(T)& ?/=?(vec2(T)& v, T scalar) with (v) { 93 122 v = v / scalar; 94 123 return v; 95 124 } 125 vec2(T) ?/=?(vec2(T)& u, vec2(T) v) { 126 u = u / v; 127 return u; 128 } 129 } 130 131 forall( { T ?%?(T,T); }) { 132 vec2(T) ?%?(vec2(T) v, T scalar) with (v) { 133 return [x % scalar, y % scalar]; 134 } 135 vec2(T)& ?%=?(vec2(T)& u, T scalar) { 136 u = u % scalar; 137 return u; 138 } 139 vec2(T) ?%?(vec2(T) u, vec2(T) v) { 140 return [u.x % v.x, u.y % v.y]; 141 } 142 vec2(T)& ?%=?(vec2(T)& u, vec2(T) v) { 143 u = u % v; 144 return u; 145 } 146 } 147 148 forall( { T ?&?(T,T); }) { 149 vec2(T) ?&?(vec2(T) v, T scalar) with (v) { 150 return [x & scalar, y & scalar]; 151 } 152 vec2(T)& ?&=?(vec2(T)& u, T scalar) { 153 u = u & scalar; 154 return u; 155 } 156 vec2(T) ?&?(vec2(T) u, vec2(T) v) { 157 return [u.x & v.x, u.y & v.y]; 158 } 159 vec2(T)& ?&=?(vec2(T)& u, vec2(T) v) { 160 u = u & v; 161 return u; 162 } 163 } 164 165 forall( { T ??(T,T); }) { 166 vec2(T) ??(vec2(T) v, T scalar) with (v) { 167 return [x  scalar, y  scalar]; 168 } 169 vec2(T)& ?=?(vec2(T)& u, T scalar) { 170 u = u  scalar; 171 return u; 172 } 173 vec2(T) ??(vec2(T) u, vec2(T) v) { 174 return [u.x  v.x, u.y  v.y]; 175 } 176 vec2(T)& ?=?(vec2(T)& u, vec2(T) v) { 177 u = u  v; 178 return u; 179 } 180 } 181 182 forall( { T ?^?(T,T); }) { 183 vec2(T) ?^?(vec2(T) v, T scalar) with (v) { 184 return [x ^ scalar, y ^ scalar]; 185 } 186 vec2(T)& ?^=?(vec2(T)& u, T scalar) { 187 u = u ^ scalar; 188 return u; 189 } 190 vec2(T) ?^?(vec2(T) u, vec2(T) v) { 191 return [u.x ^ v.x, u.y ^ v.y]; 192 } 193 vec2(T)& ?^=?(vec2(T)& u, vec2(T) v) { 194 u = u ^ v; 195 return u; 196 } 197 } 198 199 forall( { T ?<<?(T,T); }) { 200 vec2(T) ?<<?(vec2(T) v, T scalar) with (v) { 201 return [x << scalar, y << scalar]; 202 } 203 vec2(T)& ?<<=?(vec2(T)& u, T scalar) { 204 u = u << scalar; 205 return u; 206 } 207 vec2(T) ?<<?(vec2(T) u, vec2(T) v) { 208 return [u.x << v.x, u.y << v.y]; 209 } 210 vec2(T)& ?<<=?(vec2(T)& u, vec2(T) v) { 211 u = u << v; 212 return u; 213 } 214 } 215 216 forall( { T ?>>?(T,T); }) { 217 vec2(T) ?>>?(vec2(T) v, T scalar) with (v) { 218 return [x >> scalar, y >> scalar]; 219 } 220 vec2(T)& ?>>=?(vec2(T)& u, T scalar) { 221 u = u >> scalar; 222 return u; 223 } 224 vec2(T) ?>>?(vec2(T) u, vec2(T) v) { 225 return [u.x >> v.x, u.y >> v.y]; 226 } 227 vec2(T)& ?>>=?(vec2(T)& u, vec2(T) v) { 228 u = u >> v; 229 return u; 230 } 231 } 232 233 forall( { T ~?(T); }) 234 vec2(T) ~?(vec2(T) v) with (v) { 235 return [~v.x, ~v.y]; 96 236 } 97 237 … … 123 263 } 124 264 } 125
Note: See TracChangeset
for help on using the changeset viewer.