MCPcopy Create free account
hub / github.com/BIMCoderLiang/LNLib / TEST

Function TEST

tests/T_Additional.cpp:11–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9using namespace LNLib;
10
11TEST(Test_Additional, ApproximateLength)
12{
13 LN_NurbsCurve result;
14 NurbsCurve::CreateLine(XYZ(0, 0, 0), XYZ(100, 0, 0), result);
15 EXPECT_TRUE(NurbsCurve::IsLinear(result));
16 std::vector<double> lineKnotVector = result.KnotVector;
17 double startLineKnot = lineKnotVector[0];
18 double endLineKnot = lineKnotVector[lineKnotVector.size() - 1];
19 double nonCurvature = NurbsCurve::Curvature(result, (startLineKnot + endLineKnot) / 2.0);
20 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(nonCurvature, 0.0));
21 LN_ArcInfo arcInfo;
22 EXPECT_FALSE(NurbsCurve::IsArc(result, arcInfo));
23 double simpson = NurbsCurve::ApproximateLength(result, IntegratorType::Simpson);
24 double gaussLegendre = NurbsCurve::ApproximateLength(result, IntegratorType::GaussLegendre);
25 double chebyshev = NurbsCurve::ApproximateLength(result, IntegratorType::Chebyshev);
26 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(simpson, 100.0));
27 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(gaussLegendre, 100.0));
28 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(chebyshev, 100.0));
29
30 XYZ center = XYZ(0, 0, 0);
31 XYZ xAxis = XYZ(1, 0, 0);
32 XYZ yAxis = XYZ(0, 1, 0);
33 double radius = 100;
34 LN_NurbsCurve curve;
35 bool createArc = NurbsCurve::CreateArc(center, xAxis, yAxis, 0, 2 * Constants::Pi, radius, radius, curve);
36 EXPECT_TRUE(createArc);
37 double curvature = NurbsCurve::Curvature(curve, curve.KnotVector[0]);
38 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(curvature, 1.0/radius));
39 EXPECT_TRUE(NurbsCurve::IsArc(curve, arcInfo));
40 EXPECT_FALSE(NurbsCurve::IsLinear(curve));
41 simpson = NurbsCurve::ApproximateLength(curve, IntegratorType::Simpson);
42 gaussLegendre = NurbsCurve::ApproximateLength(curve, IntegratorType::GaussLegendre);
43 chebyshev = NurbsCurve::ApproximateLength(curve, IntegratorType::Chebyshev);
44 EXPECT_FALSE(MathUtils::IsAlmostEqualTo(simpson, 2 * Constants::Pi * radius)); // not accuracy when use Simpson
45 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(gaussLegendre, 2 * Constants::Pi * radius));
46 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(chebyshev, 2 * Constants::Pi * radius));
47
48 simpson = NurbsCurve::GetParamOnCurve(curve, 0.5 * Constants::Pi * radius, IntegratorType::Simpson);
49 gaussLegendre = NurbsCurve::GetParamOnCurve(curve, 0.5 * Constants::Pi * radius, IntegratorType::GaussLegendre);
50 chebyshev = NurbsCurve::GetParamOnCurve(curve, 0.5 * Constants::Pi * radius, IntegratorType::Chebyshev);
51 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(simpson, 0.25));
52 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(gaussLegendre, 0.25));
53 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(chebyshev, 0.25));
54
55 std::vector<double> arcParameters = NurbsCurve::GetParamsOnCurve(curve, 0.25 * 2 * Constants::Pi * radius, IntegratorType::Simpson);
56 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(arcParameters[0], 0.25));
57 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(arcParameters[1], 0.5));
58 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(arcParameters[2], 0.75));
59 arcParameters = NurbsCurve::GetParamsOnCurve(curve, 0.25 * 2 * Constants::Pi * radius, IntegratorType::GaussLegendre);
60 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(arcParameters[0], 0.25));
61 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(arcParameters[1], 0.5));
62 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(arcParameters[2], 0.75));
63 arcParameters = NurbsCurve::GetParamsOnCurve(curve, 0.25 * 2 * Constants::Pi * radius, IntegratorType::Chebyshev);
64 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(arcParameters[0], 0.25));
65 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(arcParameters[1], 0.5));
66 EXPECT_TRUE(MathUtils::IsAlmostEqualTo(arcParameters[2], 0.75));
67}
68

Callers

nothing calls this directly

Calls 8

NURBSSurfaceForAreaTestFunction · 0.85
GetPointOnCurveFunction · 0.85
XYZClass · 0.50
XYZWClass · 0.50
NormalizeMethod · 0.45
IsAlmostEqualToMethod · 0.45
AngleToMethod · 0.45
DistanceMethod · 0.45

Tested by

no test coverage detected