## File: Box2DMath.h

package info (click to toggle)
caveexpress 2.4+git20160609-3
• links: PTS, VCS
• area: main
• in suites: stretch
• size: 48,824 kB
• sloc: cpp: 66,239; ansic: 1,135; sh: 471; xml: 186; python: 74; makefile: 20
 file content (40 lines) | stat: -rw-r--r-- 1,101 bytes parent folder | download | duplicates (2)
 `12345678910111213141516171819202122232425262728293031323334353637383940` ``````#pragma once #include #ifndef b2Assert #define b2Assert SDL_assert #endif #include "common/Compiler.h" GCC_DIAG_OFF(shadow) #include GCC_DIAG_ON(shadow) #include "common/Math.h" inline bool b2Vec2Equals (const b2Vec2& one, const b2Vec2& two, float epsilon = EPSILON) { return fequals(one.x, two.x, epsilon) && fequals(one.y, two.y, epsilon); } // Assuming the polygon is simple, checks if it is convex inline bool isConvex (const b2Vec2 *points, const size_t amount) { if (amount < 4) return true; bool isPositive = false; for (size_t k = 0u; k < amount; ++k) { const float dx1 = points[k + 1].x - points[k].x; const float dy1 = points[k + 1].y - points[k].y; const float dx2 = points[k + 2].x - points[k + 1].x; const float dy2 = points[k + 2].y - points[k + 1].y; const float cross = dx1 * dy2 - dy1 * dx2; // Cross product should have same sign // for each vertex if polygon is convex. const bool newIsP = cross > 0; if (k == 0) { isPositive = newIsP; } else if (isPositive != newIsP) { return false; } } return true; } ``````