コード例 #1
0
ファイル: TestBezierCurve.cs プロジェクト: Joxx0r/ATF
        private void TestToStringWithCulture(CultureInfo culture)
        {
            CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = culture;
            try
            {
                string listSeparator = culture.TextInfo.ListSeparator;
                string decimalSeparator = culture.NumberFormat.NumberDecimalSeparator;
                var o = new BezierCurve( new[]
                {
                    new Vec3F(1.1f, 2.2f, 3.3f),
                    new Vec3F(4.4f, 5.5f, 6.6f),
                    new Vec3F(7.7f, 8.8f, 9.9f),
                    new Vec3F(10.10f, 11.11f, 12.12f),
                });

                string s = o.ToString(null, null);
                TestToStringResults(o, s, listSeparator, decimalSeparator);

                string s2 = o.ToString();
                Assert.AreEqual(s, s2);

                s = o.ToString("G", culture);
                TestToStringResults(o, s, listSeparator, decimalSeparator);

                s = o.ToString("R", culture);
                TestToStringResults(o, s, listSeparator, decimalSeparator);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = originalCulture;
            }
        }
コード例 #2
0
ファイル: TestBezierCurve.cs プロジェクト: Joxx0r/ATF
        private void TestToStringResults(BezierCurve o, string s, string listSeparator, string decimalSeparator)
        {
            string[] results = s.Split(new[] { listSeparator }, StringSplitOptions.RemoveEmptyEntries);
            Assert.AreEqual(results.Length, 12);
            foreach(string oneFloatString in results)
                Assert.True(oneFloatString.Contains(decimalSeparator));

            Vec3F[] originals = o.ControlPoints;
            Assert.AreEqual(float.Parse(results[0]), originals[0].X);
            Assert.AreEqual(float.Parse(results[1]), originals[0].Y);
            Assert.AreEqual(float.Parse(results[2]), originals[0].Z);

            Assert.AreEqual(float.Parse(results[3]), originals[1].X);
            Assert.AreEqual(float.Parse(results[4]), originals[1].Y);
            Assert.AreEqual(float.Parse(results[5]), originals[1].Z);

            Assert.AreEqual(float.Parse(results[6]), originals[2].X);
            Assert.AreEqual(float.Parse(results[7]), originals[2].Y);
            Assert.AreEqual(float.Parse(results[8]), originals[2].Z);

            Assert.AreEqual(float.Parse(results[9]), originals[3].X);
            Assert.AreEqual(float.Parse(results[10]), originals[3].Y);
            Assert.AreEqual(float.Parse(results[11]), originals[3].Z);
        }
コード例 #3
0
        private void BuildCurves()
        {
            m_curves.Clear();

            if (Count > 1)
            {
                if (Count == 2)
                {
                    BuildInitialCurveFrom2Points();
                }
                else
                {
                    Vec3F   zeroVec  = new Vec3F(0, 0, 0);
                    Vec3F[] tangents = CalcPointTangents();

                    for (int i = 1; i < Count; i++)
                    {
                        Vec3F chord  = this[i].Position - this[i - 1].Position;
                        float segLen = chord.Length * 0.333f;

                        Vec3F[] points = new Vec3F[4];
                        points[0] = this[i - 1].Position;
                        points[3] = this[i].Position;

                        // calc points[1]
                        if (this[i - 1].Tangent2 != zeroVec)
                        {
                            points[1] = this[i - 1].Position + this[i - 1].Tangent2;
                        }
                        else
                        {
                            Vec3F tangent = tangents[i - 1];
                            if (Vec3F.Dot(chord, tangent) < 0)
                            {
                                tangent = -tangent;
                            }

                            points[1] = this[i - 1].Position + (tangent * segLen);
                        }

                        // calc points[2]
                        if (this[i].Tangent1 != zeroVec)
                        {
                            points[2] = this[i].Position + this[i].Tangent1;
                        }
                        else
                        {
                            Vec3F tangent = tangents[i];
                            if (Vec3F.Dot(-chord, tangent) < 0)
                            {
                                tangent = -tangent;
                            }

                            points[2] = this[i].Position + (tangent * segLen);
                        }

                        BezierCurve curve = new BezierCurve(points);
                        m_curves.Add(curve);
                    }

                    // Calculate last curve if is closed
                    if (m_isClosed)
                    {
                        Vec3F[] points = new Vec3F[4];
                        points[0] = this[Count - 1].Position;
                        points[3] = this[0].Position;
                        float tanLen = (points[3] - points[0]).Length / 3.0f;

                        Vec3F v = m_curves[m_curves.Count - 1].ControlPoints[2] - points[0];
                        v         = v / v.Length;
                        points[1] = points[0] - (v * tanLen);

                        v         = m_curves[0].ControlPoints[1] - points[3];
                        v         = v / v.Length;
                        points[2] = points[3] - (v * tanLen);

                        BezierCurve curve = new BezierCurve(points);
                        m_curves.Add(curve);
                    }
                }
            }
        }