Exemple #1
0
        private static void StretchEdge(Edge edge, double length)
        {
            Vector2 directionNormalized = Vector2.Normalize(edge.GetDirection());
            double  lengthMultiplier    = length - edge.Length;
            Vector2 offset = directionNormalized * (float)lengthMultiplier;

            edge.End.Position = edge.End.Position.Add(new Point((int)Math.Round(offset.X), (int)Math.Round(offset.Y)));
        }
Exemple #2
0
        private static bool AreEdgesPerpendicular(Edge e1, Edge e2)
        {
            Vector2 dir1 = e1.GetDirection();
            Vector2 dir2 = e2.GetDirection();

            //normalizing in order to have length independent epsilon
            return(Math.Abs(Vector2.Dot(Vector2.Normalize(dir1), Vector2.Normalize(dir2))) < RelationConstants.PerpendicularDotEpsilon);
        }
Exemple #3
0
        private static void RotateNeighboursToPerpendicular(Edge first, Edge second)
        {
            var temp   = new Edge(first.Begin, second.End);
            var middle = temp.GetSplitVertex();
            var oldPos = first.End.Position;

            first.End.Position = middle.Position;
            var direction      = first.GetDirection();
            var positionFirst  = first.End.Position.Add(new Point(-(int)Math.Round(direction.Y), (int)Math.Round(direction.X)));
            var positionSecond = first.End.Position.Add(new Point((int)Math.Round(direction.Y), -(int)Math.Round(direction.X)));

            first.End.Position = positionFirst.DistanceSquaredTo(oldPos) > positionSecond.DistanceSquaredTo(oldPos) ? positionSecond : positionFirst;
        }
Exemple #4
0
        private static void RotateToPerpendicular(Edge edge, Edge relationEdge)
        {
            var direction = relationEdge.GetDirection();

            if (edge.Length < 3)
            {
                StretchEdge(edge, 4);
            }

            var perpFirst  = new Vector2(-direction.Y, direction.X);
            var perpSecond = new Vector2(direction.Y, -direction.X);

            perpFirst  = Vector2.Normalize(perpFirst) * (float)edge.Length;
            perpSecond = Vector2.Normalize(perpSecond) * (float)edge.Length;

            var posFirst  = edge.Begin.Position.Add(new Point((int)Math.Round(perpFirst.X), (int)Math.Round(perpFirst.Y)));
            var posSecond = edge.Begin.Position.Add(new Point((int)Math.Round(perpSecond.X), (int)Math.Round(perpSecond.Y)));

            edge.End.Position = posFirst.DistanceSquaredTo(edge.End.Position) > posSecond.DistanceSquaredTo(edge.End.Position) ? posSecond : posFirst;
        }