示例#1
0
        public void InsertEdgeByAngle(HBEdge edge)
        {
            edge.Vertex = this;

            if (Edge == null)
            {
                Edge = edge;
            }
            else if (EdgeCount == 1)
            {
                Edge.Next = edge.Opposite;
                edge.Opposite.Previous = Edge;
                edge.Next = Edge.Opposite;
                Edge.Opposite.Previous = edge;
            }
            else
            {
                var   p0       = Edge.Opposite.GetVertex <HBVertex2f>().Position - Position;
                var   p1       = edge.Opposite.GetVertex <HBVertex2f>().Position - Position;
                float a01      = Vector2f.Angle360(p0, p1);
                var   previous = Edge;

                foreach (var e in EnumerateEdges())
                {
                    var   p2  = e.Opposite.GetVertex <HBVertex2f>().Position - Position;
                    float a02 = Vector2f.Angle360(p0, p2);

                    if (a01 <= a02)
                    {
                        edge.Next           = e.Opposite;
                        e.Opposite.Previous = edge;

                        edge.Opposite.Previous = previous;
                        previous.Next          = edge.Opposite;
                        return;
                    }

                    previous = e;
                }

                edge.Next = Edge.Opposite;
                Edge.Opposite.Previous = edge;

                edge.Opposite.Previous = previous;
                previous.Next          = edge.Opposite;
            }
        }
示例#2
0
        public void Angle360()
        {
            float    error = 1e-4f;
            Vector2f v     = new Vector2f(1, 0);

            for (int i = 0; i <= 360; i++)
            {
                double di = i / 360.0f;

                double theta = 2.0 * Math.PI * di;
                float  x     = (float)Math.Cos(theta);
                float  y     = (float)Math.Sin(theta);

                Assert.IsTrue(NearlyEqual(i, Vector2f.Angle360(v, new Vector2f(x, y)), error));
            }

            Assert.IsTrue(NearlyEqual(0, Vector2f.Angle360(v, new Vector2f(1, 0)), error));
            Assert.IsTrue(NearlyEqual(45, Vector2f.Angle360(v, new Vector2f(1, 1)), error));
            Assert.IsTrue(NearlyEqual(90, Vector2f.Angle360(v, new Vector2f(0, 1)), error));
            Assert.IsTrue(NearlyEqual(135, Vector2f.Angle360(v, new Vector2f(-1, 1)), error));
            Assert.IsTrue(NearlyEqual(180, Vector2f.Angle360(v, new Vector2f(-1, 0)), error));
            Assert.IsTrue(NearlyEqual(225, Vector2f.Angle360(v, new Vector2f(-1, -1)), error));
            Assert.IsTrue(NearlyEqual(270, Vector2f.Angle360(v, new Vector2f(0, -1)), error));

            v = new Vector2f(-1, 0);

            Assert.IsTrue(NearlyEqual(0, Vector2f.Angle360(v, new Vector2f(-1, 0)), error));
            Assert.IsTrue(NearlyEqual(90, Vector2f.Angle360(v, new Vector2f(0, -1)), error));
            Assert.IsTrue(NearlyEqual(180, Vector2f.Angle360(v, new Vector2f(1, 0)), error));
            Assert.IsTrue(NearlyEqual(270, Vector2f.Angle360(v, new Vector2f(0, 1)), error));

            v = new Vector2f(0, 1);

            Assert.IsTrue(NearlyEqual(0, Vector2f.Angle360(v, new Vector2f(0, 1)), error));
            Assert.IsTrue(NearlyEqual(90, Vector2f.Angle360(v, new Vector2f(-1, 0)), error));
            Assert.IsTrue(NearlyEqual(180, Vector2f.Angle360(v, new Vector2f(0, -1)), error));
            Assert.IsTrue(NearlyEqual(270, Vector2f.Angle360(v, new Vector2f(1, 0)), error));
        }