math_test.cpp
Go to the documentation of this file.
1 // MIT License
2 
3 // Copyright (c) 2020 Erin Catto
4 
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #include "box2d/box2d.h"
24 #include "doctest.h"
25 #include <stdio.h>
26 
27 DOCTEST_TEST_CASE("math test")
28 {
29  SUBCASE("sweep")
30  {
31  // From issue #447
32  b2Sweep sweep;
33  sweep.localCenter.SetZero();
34  sweep.c0.Set(-2.0f, 4.0f);
35  sweep.c.Set(3.0f, 8.0f);
36  sweep.a0 = 0.5f;
37  sweep.a = 5.0f;
38  sweep.alpha0 = 0.0f;
39 
40  b2Transform transform;
41 
42  sweep.GetTransform(&transform, 0.0f);
43  DOCTEST_REQUIRE_EQ(transform.p.x, sweep.c0.x);
44  DOCTEST_REQUIRE_EQ(transform.p.y, sweep.c0.y);
45  DOCTEST_REQUIRE_EQ(transform.q.c, cosf(sweep.a0));
46  DOCTEST_REQUIRE_EQ(transform.q.s, sinf(sweep.a0));
47 
48  sweep.GetTransform(&transform, 1.0f);
49  DOCTEST_REQUIRE_EQ(transform.p.x, sweep.c.x);
50  DOCTEST_REQUIRE_EQ(transform.p.y, sweep.c.y);
51  DOCTEST_REQUIRE_EQ(transform.q.c, cosf(sweep.a));
52  DOCTEST_REQUIRE_EQ(transform.q.s, sinf(sweep.a));
53  }
54 }
#define DOCTEST_REQUIRE_EQ(...)
Definition: doctest.h:2127
b2Vec2 p
Definition: b2_math.h:360
b2Vec2 c0
Definition: b2_math.h:383
b2Rot q
Definition: b2_math.h:361
f
float x
Definition: b2_math.h:128
float y
Definition: b2_math.h:128
#define SUBCASE
Definition: doctest.h:2447
void SetZero()
Set this vector to all zeros.
Definition: b2_math.h:50
float s
Sine and cosine.
Definition: b2_math.h:333
DOCTEST_TEST_CASE("math test")
Definition: math_test.cpp:27
float a0
Definition: b2_math.h:384
b2Vec2 c
center world positions
Definition: b2_math.h:383
float c
Definition: b2_math.h:333
b2Vec2 localCenter
local center of mass position
Definition: b2_math.h:382
void Set(float x_, float y_)
Set this vector to some specified coordinates.
Definition: b2_math.h:53
float a
world angles
Definition: b2_math.h:384
void GetTransform(b2Transform *transform, float beta) const
Definition: b2_math.h:687
float alpha0
Definition: b2_math.h:388


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:21