public virtual double GetAutoOrientAngle(MarkerSvgNodeRenderer marker, bool reverse) { Object[] pathShapes = GetShapes().ToArray(); if (pathShapes.Length > 1) { Vector v = new Vector(0, 0, 0); if (SvgConstants.Attributes.MARKER_END.Equals(marker.attributesAndStyles.Get(SvgConstants.Tags.MARKER))) { // Create vector from the last two shapes IPathShape lastShape = (IPathShape)pathShapes[pathShapes.Length - 1]; IPathShape secondToLastShape = (IPathShape)pathShapes[pathShapes.Length - 2]; v = new Vector((float)(lastShape.GetEndingPoint().GetX() - secondToLastShape.GetEndingPoint().GetX()), (float )(lastShape.GetEndingPoint().GetY() - secondToLastShape.GetEndingPoint().GetY()), 0f); } else { if (SvgConstants.Attributes.MARKER_START.Equals(marker.attributesAndStyles.Get(SvgConstants.Tags.MARKER))) { // Create vector from the first two shapes IPathShape firstShape = (IPathShape)pathShapes[0]; IPathShape secondShape = (IPathShape)pathShapes[1]; v = new Vector((float)(secondShape.GetEndingPoint().GetX() - firstShape.GetEndingPoint().GetX()), (float)( secondShape.GetEndingPoint().GetY() - firstShape.GetEndingPoint().GetY()), 0f); } } // Get angle from this vector and the horizontal axis Vector xAxis = new Vector(1, 0, 0); double rotAngle = SvgCoordinateUtils.CalculateAngleBetweenTwoVectors(xAxis, v); return(v.Get(1) >= 0 && !reverse ? rotAngle : rotAngle * -1f); } return(0); }
public virtual double GetAutoOrientAngle(MarkerSvgNodeRenderer marker, bool reverse) { if (points.Count > 1) { Vector v = new Vector(0, 0, 0); if (SvgConstants.Attributes.MARKER_END.Equals(marker.attributesAndStyles.Get(SvgConstants.Tags.MARKER))) { Point lastPoint = points[points.Count - 1]; Point secondToLastPoint = points[points.Count - 2]; v = new Vector((float)(lastPoint.GetX() - secondToLastPoint.GetX()), (float)(lastPoint.GetY() - secondToLastPoint .GetY()), 0f); } else { if (SvgConstants.Attributes.MARKER_START.Equals(marker.attributesAndStyles.Get(SvgConstants.Tags.MARKER))) { Point firstPoint = points[0]; Point secondPoint = points[1]; v = new Vector((float)(secondPoint.GetX() - firstPoint.GetX()), (float)(secondPoint.GetY() - firstPoint.GetY ()), 0f); } } Vector xAxis = new Vector(1, 0, 0); double rotAngle = SvgCoordinateUtils.CalculateAngleBetweenTwoVectors(xAxis, v); return(v.Get(1) >= 0 && !reverse ? rotAngle : rotAngle * -1f); } return(0); }
public virtual double GetAutoOrientAngle(MarkerSvgNodeRenderer marker, bool reverse) { Vector v = new Vector(GetAttribute(this.attributesAndStyles, SvgConstants.Attributes.X2) - GetAttribute(this .attributesAndStyles, SvgConstants.Attributes.X1), GetAttribute(this.attributesAndStyles, SvgConstants.Attributes .Y2) - GetAttribute(this.attributesAndStyles, SvgConstants.Attributes.Y1), 0f); Vector xAxis = new Vector(1, 0, 0); double rotAngle = SvgCoordinateUtils.CalculateAngleBetweenTwoVectors(xAxis, v); return(v.Get(1) >= 0 && !reverse ? rotAngle : rotAngle * -1f); }
public virtual String[] MakeCoordinatesAbsolute(String[] relativeCoordinates, double[] initialPoint) { String[] result = new String[relativeCoordinates.Length]; Array.Copy(relativeCoordinates, 0, result, 0, 2); // convert all relative operators to absolute operators ... relativeCoordinates = SvgCoordinateUtils.MakeRelativeOperatorCoordinatesAbsolute(relativeCoordinates, initialPoint ); // ... but don't store the first coordinate pair Array.Copy(relativeCoordinates, 2, result, 2, relativeCoordinates.Length - 2); return(result); }
public override void SetCoordinates(String[] coordinates, Point startPoint) { if (coordinates.Length == 0 || coordinates.Length % 2 != 0) { throw new ArgumentException(MessageFormatUtil.Format(SvgExceptionMessageConstant.MOVE_TO_EXPECTS_FOLLOWING_PARAMETERS_GOT_0 , JavaUtil.ArraysToString(coordinates))); } if (coordinates.Length > 2) { // (x y)+ parameters will be implemented in the future throw new NotSupportedException(); } this.coordinates = new String[] { coordinates[0], coordinates[1] }; if (IsRelative()) { this.coordinates = SvgCoordinateUtils.MakeRelativeOperatorCoordinatesAbsolute(coordinates, new double[] { startPoint.x, startPoint.y }); } }
public override void SetCoordinates(String[] coordinates, Point startPoint) { if (coordinates.Length == 0 || coordinates.Length % 2 != 0) { throw new ArgumentException(MessageFormatUtil.Format(SvgExceptionMessageConstant.LINE_TO_EXPECTS_FOLLOWING_PARAMETERS_GOT_0 , JavaUtil.ArraysToString(coordinates))); } this.coordinates = new String[coordinates.Length / 2][]; double[] initialPoint = new double[] { startPoint.GetX(), startPoint.GetY() }; for (int i = 0; i < coordinates.Length; i += 2) { String[] curCoordinates = new String[] { coordinates[i], coordinates[i + 1] }; if (IsRelative()) { curCoordinates = SvgCoordinateUtils.MakeRelativeOperatorCoordinatesAbsolute(curCoordinates, initialPoint); initialPoint[0] = (float)CssUtils.ParseFloat(curCoordinates[0]); initialPoint[1] = (float)CssUtils.ParseFloat(curCoordinates[1]); } this.coordinates[i / 2] = curCoordinates; } }
public virtual String[] MakeCoordinatesAbsolute(String[] relativeCoordinates, double[] initialPoint) { return(SvgCoordinateUtils.MakeRelativeOperatorCoordinatesAbsolute(relativeCoordinates, initialPoint)); }