예제 #1
0
        protected virtual SLExpression VisitSideLengthAndPositionSquare(SideLengthAndPositionSquareExpression perimeterAndSidePositionSquareExpression)
        {
            var lines        = perimeterAndSidePositionSquareExpression.Lines.Select(Visit).ToArray();
            var sidePosition = (TwoPointsLineExpression)Visit(perimeterAndSidePositionSquareExpression.SidePosition);

            if (HasChanged(lines, perimeterAndSidePositionSquareExpression.Lines) ||
                sidePosition != perimeterAndSidePositionSquareExpression.SidePosition)
            {
                return(new SideLengthAndPositionSquareExpression
                {
                    LinesLengthToSideLengthFactor = perimeterAndSidePositionSquareExpression.LinesLengthToSideLengthFactor,
                    Lines = lines.Cast <LineExpression>().ToArray(),
                    SideDirection = perimeterAndSidePositionSquareExpression.SideDirection,
                    SidePosition = sidePosition,
                });
            }
            return(perimeterAndSidePositionSquareExpression);
        }
예제 #2
0
        protected override SLExpression VisitSideLengthAndPositionSquare(SideLengthAndPositionSquareExpression expression)
        {
            var sidePositionAxis = (TwoPointsLineExpression)Visit(expression.SidePosition);
            var axisLength       = GetDistance(
                (CoordinatesPointExpression)sidePositionAxis.Point1,
                (CoordinatesPointExpression)sidePositionAxis.Point2);

            var lines            = expression.Lines.Select(Visit).Cast <TwoPointsLineExpression>().ToArray();
            var totalLinesLength = lines.Select(l => GetDistance((CoordinatesPointExpression)l.Point1, (CoordinatesPointExpression)l.Point2)).Sum();
            var factor           = GetFactor(expression.LinesLengthToSideLengthFactor);
            var sideLength       = factor * totalLinesLength;

            var sideAxisPoint1 = (CoordinatesPointExpression)sidePositionAxis.Point1;
            var sideAxisPoint2 = (CoordinatesPointExpression)sidePositionAxis.Point2;
            var sideCenter     = GetEquidistantPoint(sideAxisPoint1, sideAxisPoint2);

            var axisPoint1RelativePositionToCenterOfSide = sideAxisPoint1 - sideCenter;
            var axisPoint2RelativePositionToCenterOfSide = sideAxisPoint2 - sideCenter;

            var squareSideToAxisLengthFactor = sideLength / axisLength;

            var squareCorner1 = axisPoint1RelativePositionToCenterOfSide * squareSideToAxisLengthFactor + sideCenter;
            var squareCorner2 = axisPoint2RelativePositionToCenterOfSide * squareSideToAxisLengthFactor + sideCenter;

            var otherSideDirection = axisPoint1RelativePositionToCenterOfSide * squareSideToAxisLengthFactor * 2;

            otherSideDirection = new CoordinatesPointExpression
            {
                X = otherSideDirection.Y,
                Y = -otherSideDirection.X,
            };

            if (expression.SideDirection == "right" || expression.SideDirection == "bottom")
            {
                otherSideDirection = otherSideDirection * -1;
            }

            var squareCorner3 = squareCorner1 + otherSideDirection;
            var squareCorner4 = squareCorner2 + otherSideDirection;

            return(new PolygonFromPointsExpression
            {
                Points = new[]
                {
                    squareCorner1,
                    squareCorner2,
                    squareCorner4,
                    squareCorner3,
                }
            });

            //return new PolygonFromLinesExpression
            //{
            //    Lines = lines//.Take(1)
            //        .Concat(new[]
            //        {
            //            sidePositionAxis,

            //        }).ToArray(),
            //};
        }
예제 #3
0
 protected override SLExpression VisitSideLengthAndPositionSquare(SideLengthAndPositionSquareExpression perimeterAndSidePositionSquareExpression)
 {
     this.PolygonLines = perimeterAndSidePositionSquareExpression.Lines;
     return(base.VisitSideLengthAndPositionSquare(perimeterAndSidePositionSquareExpression));
 }