Ticket #3541: 3451.4.diff
File 3451.4.diff, 3.0 KB (added by , 9 years ago) |
---|
-
source/maths/FixedVector2D.h
95 95 } 96 96 97 97 /** 98 * Multiply separately coordinates by a CFixed. Likely to overflow if both numbers are large, 99 * so we use an ugly name instead of operator* to make it obvious. 100 */ 101 CFixedVector2D MultiplyCoordinates(fixed n,fixed m) const 102 { 103 return CFixedVector2D(X.Multiply(n), Y.Multiply(m)); 104 } 105 106 /** 98 107 * Returns the length of the vector. 99 108 * Will not overflow if the result can be represented as type 'fixed'. 100 109 */ -
source/simulation2/helpers/Geometry.cpp
236 236 return false; 237 237 } 238 238 239 /** 240 * This function does the same as Geometry::TestRaySquare except it ignores rotations. This saves some computation time 241 * for units which have a round obstruction. 242 * @return true if the vector cross the square, false otherwise. 243 */ 239 244 bool Geometry::TestRayAASquare(CFixedVector2D a, CFixedVector2D b, CFixedVector2D halfSize) 240 245 { 241 // Exactly like TestRaySquare with u=(1,0), v=(0,1)242 243 // Assume the compiler is clever enough to inline and simplify all this244 // (TODO: stop assuming that)245 CFixedVector2D u (fixed::FromInt(1), fixed::Zero());246 CFixedVector2D v (fixed::Zero(), fixed::FromInt(1));247 248 246 fixed hw = halfSize.X; 249 247 fixed hh = halfSize.Y; 250 248 251 fixed au = a.Dot(u); 252 fixed av = a.Dot(v); 253 254 if (-hw <= au && au <= hw && -hh <= av && av <= hh) 249 if (-hw <= a.X && a.X <= hw && -hh <= a.Y && a.Y <= hh) 255 250 return false; // a is inside 256 251 257 fixed bu = b.Dot(u); 258 fixed bv = b.Dot(v); 259 260 if (-hw <= bu && bu <= hw && -hh <= bv && bv <= hh) // TODO: isn't this subsumed by the next checks? 252 if (-hw <= b.X && b.X <= hw && -hh <= b.Y && b.Y <= hh) // TODO: isn't this subsumed by the next checks? 261 253 return true; // a is outside, b is inside 262 254 263 if ((a u < -hw && bu < -hw) || (au > hw && bu > hw) || (av < -hh && bv < -hh) || (av > hh && bv> hh))255 if ((a.X < -hw && b.X < -hw) || (a.X > hw && b.X > hw) || (a.Y < -hh && b.Y < -hh) || (a.Y > hh && b.Y > hh)) 264 256 return false; // ab is entirely above/below/side the square 265 257 266 258 CFixedVector2D abp = (b - a).Perpendicular(); 267 fixed s0 = abp.Dot( (u.Multiply(hw) + v.Multiply(hh))- a);268 fixed s1 = abp.Dot( (u.Multiply(hw) - v.Multiply(hh)) - a);269 fixed s2 = abp.Dot( (-u.Multiply(hw) - v.Multiply(hh))- a);270 fixed s3 = abp.Dot( (-u.Multiply(hw) + v.Multiply(hh)) - a);259 fixed s0 = abp.Dot(halfSize - a); 260 fixed s1 = abp.Dot(halfSize.MultiplyCoordinates(fixed::FromInt(1), fixed::FromInt(-1)) - a); 261 fixed s2 = abp.Dot(- halfSize - a); 262 fixed s3 = abp.Dot(halfSize.MultiplyCoordinates(fixed::FromInt(-1), fixed::FromInt(1)) - a); 271 263 if (s0.IsZero() || s1.IsZero() || s2.IsZero() || s3.IsZero()) 272 264 return true; // ray intersects the corner 273 265