internal override bool TrySetPair(DxfCodePair pair) { switch (pair.Code) { case 10: this.StartPoint = this.StartPoint.WithUpdatedX(pair.DoubleValue); break; case 20: this.StartPoint = this.StartPoint.WithUpdatedY(pair.DoubleValue); break; case 30: this.StartPoint = this.StartPoint.WithUpdatedZ(pair.DoubleValue); break; case 11: this.UnitDirectionVector = this.UnitDirectionVector.WithUpdatedX(pair.DoubleValue); break; case 21: this.UnitDirectionVector = this.UnitDirectionVector.WithUpdatedY(pair.DoubleValue); break; case 31: this.UnitDirectionVector = this.UnitDirectionVector.WithUpdatedZ(pair.DoubleValue); break; default: return(base.TrySetPair(pair)); } return(true); }
// // Parameterized constructors // public DxfEllipse(DxfPoint center, DxfVector majorAxis, double minorAxisRatio) : this() { this.Center = center; this.MajorAxis = majorAxis; this.MinorAxisRatio = minorAxisRatio; }
public void ClosedPolyLineVertexBulgeIsRespected() { // Data from https://github.com/ixmilia/dxf/issues/102 var vertices = new[] { new DxfVertex(new DxfPoint(0, +0.5, 0)), new DxfVertex(new DxfPoint(-1.5, +0.5, 0)) { Bulge = 1 }, new DxfVertex(new DxfPoint(-1.5, -0.5, 0)), new DxfVertex(new DxfPoint(0, -0.5, 0)) { Bulge = 1 } }; var poly = new DxfPolyline(vertices) { IsClosed = true }; var expectedMin = new DxfPoint(-2.0, -0.5, 0); var expectedMax = new DxfPoint(0.5, +0.5, 0); var expectedSize = new DxfVector(2.5, 1.0, 0); var bb = poly.GetBoundingBox().Value; Assert.Equal(expectedMin, bb.MinimumPoint); Assert.Equal(expectedMax, bb.MaximumPoint); Assert.Equal(expectedSize, bb.Size); }
protected override IEnumerable <DxfPoint> GetExtentsPoints() { var radiusX = new DxfVector(Radius, 0.0, 0.0); var radiusY = new DxfVector(0.0, Radius, 0.0); // base of the helix yield return(StartPoint + radiusX); yield return(StartPoint - radiusX); yield return(StartPoint + radiusY); yield return(StartPoint - radiusY); // other side of the helix var endPoint = StartPoint + AxisVector.Normalize() * NumberOfTurns * TurnHeight; yield return(endPoint + radiusX); yield return(endPoint - radiusX); yield return(endPoint + radiusY); yield return(endPoint - radiusY); }
public void InsertBoundingBox() { var line = new DxfLine(new DxfPoint(1.0, 1.0, 0.0), new DxfPoint(2.0, 3.0, 0.0)); var offset = new DxfVector(2.0, 2.0, 0.0); var block = new DxfBlock(); block.Name = "some-block"; block.Entities.Add(line); var insert = new DxfInsert(); insert.Name = "some-block"; insert.Location = offset; insert.XScaleFactor = 2.0; var file = new DxfFile(); file.Blocks.Add(block); file.Entities.Add(insert); var boundingBox = file.GetBoundingBox(); Assert.Equal(new DxfPoint(4.0, 3.0, 0.0), boundingBox.MinimumPoint); Assert.Equal(new DxfPoint(6.0, 5.0, 0.0), boundingBox.MaximumPoint); }
protected override void Initialize() { base.Initialize(); this.Thickness = 0.0; this.Center = DxfPoint.Origin; this.Radius = 0.0; this.Normal = DxfVector.ZAxis; }
protected override void Initialize() { base.Initialize(); this.Thickness = 0.0; this.P1 = DxfPoint.Origin; this.P2 = DxfPoint.Origin; this.ExtrusionDirection = DxfVector.ZAxis; }
internal override bool TrySetPair(DxfCodePair pair) { switch (pair.Code) { case 2: this.Name = (pair.StringValue); break; case 10: this.Location = this.Location.WithUpdatedX(pair.DoubleValue); break; case 20: this.Location = this.Location.WithUpdatedY(pair.DoubleValue); break; case 30: this.Location = this.Location.WithUpdatedZ(pair.DoubleValue); break; case 39: this.Thickness = (pair.DoubleValue); break; case 40: this.Size = (pair.DoubleValue); break; case 41: this.RelativeXScaleFactor = (pair.DoubleValue); break; case 50: this.RotationAngle = (pair.DoubleValue); break; case 51: this.ObliqueAngle = (pair.DoubleValue); break; case 210: this.ExtrusionDirection = this.ExtrusionDirection.WithUpdatedX(pair.DoubleValue); break; case 220: this.ExtrusionDirection = this.ExtrusionDirection.WithUpdatedY(pair.DoubleValue); break; case 230: this.ExtrusionDirection = this.ExtrusionDirection.WithUpdatedZ(pair.DoubleValue); break; default: return(base.TrySetPair(pair)); } return(true); }
protected override void Initialize() { base.Initialize(); this.DimensionStyleName = null; this.InsertionPoint = DxfPoint.Origin; this.DisplayText = null; this.ExtrusionDirection = DxfVector.ZAxis; this.DirectionVector = DxfVector.XAxis; }
public void RightVectorFromNegativeNormalTest() { // gleaned from https://github.com/ixmilia/dxf/issues/105 // A 90 degree arc from 270-360 degrees with a negative Z normal is displayed by both AutoCAD and Teigha in Q3. var right = DxfVector.RightVectorFromNormal(new DxfVector(0.0, 0.0, -1.0)); var expected = -DxfVector.XAxis; Assert.Equal(expected, right); }
protected override void Initialize() { base.Initialize(); this.FirstCorner = DxfPoint.Origin; this.SecondCorner = DxfPoint.Origin; this.ThirdCorner = DxfPoint.Origin; this.FourthCorner = DxfPoint.Origin; this.Thickness = 0.0; this.ExtrusionDirection = DxfVector.ZAxis; }
public static bool TryCreateFromVertices(DxfVertex v1, DxfVertex v2, out DxfArc arc) { // To the best of my knowledge, 3D Arcs are not defined via z but a normal vector. // Thus, simply ignore non-zero z values. var bulge = v1.Bulge; if (Math.Abs(bulge) < 1e-10) { //throw new ArgumentException("arc bulge too small: " + bulge); arc = null; return(false); } var startPoint = v1.Location; var endPoint = v2.Location; var delta = endPoint - startPoint; var length = delta.Length; if (length <= double.Epsilon) { //throw new ArgumentException("arc startpoint == endpoint"); arc = null; return(false); } var alpha = 4.0 * Math.Atan(bulge); var radius = length / (2.0 * Math.Abs(Math.Sin(alpha * 0.5))); var deltaNorm = delta.Normalize(); int bulgeSign = Math.Sign(bulge); // 2D only solution (z=0) var normal = new DxfVector(-deltaNorm.Y, +deltaNorm.X, 0.0) * bulgeSign; var center = (startPoint + endPoint) * 0.5 + normal * Math.Cos(alpha * 0.5) * radius; // bulge<0 indicates CW arc, but DxfArc is CCW always double startAngleDeg; double endAngleDeg; if (bulge > 0) { startAngleDeg = NormalizedAngleDegree(startPoint, center); endAngleDeg = NormalizedAngleDegree(endPoint, center); } else { endAngleDeg = NormalizedAngleDegree(startPoint, center); startAngleDeg = NormalizedAngleDegree(endPoint, center); } arc = new DxfArc(center, radius, startAngleDeg, endAngleDeg); return(true); }
internal override bool TrySetPair(DxfCodePair pair) { switch (pair.Code) { case 1: this.DisplayText = (pair.StringValue); break; case 3: this.DimensionStyleName = (pair.StringValue); break; case 10: this.InsertionPoint = this.InsertionPoint.WithUpdatedX(pair.DoubleValue); break; case 20: this.InsertionPoint = this.InsertionPoint.WithUpdatedY(pair.DoubleValue); break; case 30: this.InsertionPoint = this.InsertionPoint.WithUpdatedZ(pair.DoubleValue); break; case 11: this.DirectionVector = this.DirectionVector.WithUpdatedX(pair.DoubleValue); break; case 21: this.DirectionVector = this.DirectionVector.WithUpdatedY(pair.DoubleValue); break; case 31: this.DirectionVector = this.DirectionVector.WithUpdatedZ(pair.DoubleValue); break; case 210: this.ExtrusionDirection = this.ExtrusionDirection.WithUpdatedX(pair.DoubleValue); break; case 220: this.ExtrusionDirection = this.ExtrusionDirection.WithUpdatedY(pair.DoubleValue); break; case 230: this.ExtrusionDirection = this.ExtrusionDirection.WithUpdatedZ(pair.DoubleValue); break; default: return(base.TrySetPair(pair)); } return(true); }
protected override void Initialize() { base.Initialize(); this.Thickness = 0.0; this.Location = DxfPoint.Origin; this.Size = 0.0; this.Name = null; this.RotationAngle = 0.0; this.RelativeXScaleFactor = 1.0; this.ObliqueAngle = 0.0; this.ExtrusionDirection = DxfVector.ZAxis; }
internal override bool TrySetPair(DxfCodePair pair) { switch (pair.Code) { case 10: this.P1 = this.P1.WithUpdatedX(pair.DoubleValue); break; case 20: this.P1 = this.P1.WithUpdatedY(pair.DoubleValue); break; case 30: this.P1 = this.P1.WithUpdatedZ(pair.DoubleValue); break; case 11: this.P2 = this.P2.WithUpdatedX(pair.DoubleValue); break; case 21: this.P2 = this.P2.WithUpdatedY(pair.DoubleValue); break; case 31: this.P2 = this.P2.WithUpdatedZ(pair.DoubleValue); break; case 39: this.Thickness = (pair.DoubleValue); break; case 210: this.ExtrusionDirection = this.ExtrusionDirection.WithUpdatedX(pair.DoubleValue); break; case 220: this.ExtrusionDirection = this.ExtrusionDirection.WithUpdatedY(pair.DoubleValue); break; case 230: this.ExtrusionDirection = this.ExtrusionDirection.WithUpdatedZ(pair.DoubleValue); break; default: return(base.TrySetPair(pair)); } return(true); }
/// <param name="imagePath">The path to the image.</param> /// <param name="location">The bottom left corner of the location to display the image in the drawing.</param> /// <param name="imageWidth">The width of the image in pixels.</param> /// <param name="imageHeight">The height of the image in pixels.</param> /// <param name="displaySize">The display size of the image in drawing units.</param> public DxfImage(string imagePath, DxfPoint location, int imageWidth, int imageHeight, DxfVector displaySize) : this() { ImageDefinition = new DxfImageDefinition() { FilePath = imagePath, ImageWidth = imageWidth, ImageHeight = imageHeight }; ImageSize = new DxfVector(imageWidth, imageHeight, 0.0); Location = location; UVector = new DxfVector(displaySize.X / imageWidth, 0.0, 0.0); VVector = new DxfVector(0.0, displaySize.Y / imageHeight, 0.0); }
protected override void Initialize() { base.Initialize(); this.HasAttributes = false; this.Name = null; this.Location = DxfPoint.Origin; this.XScaleFactor = 1.0; this.YScaleFactor = 1.0; this.ZScaleFactor = 1.0; this.Rotation = 0.0; this.ColumnCount = 1; this.RowCount = 1; this.ColumnSpacing = 0.0; this.RowSpacing = 0.0; this.ExtrusionDirection = DxfVector.ZAxis; }
public static DxfImage ToDxfImage(this Image image, Layer layer) { var(pixelWidth, pixelHeight) = ImageHelpers.GetImageDimensions(image.Path, image.ImageData); var dxfImage = new DxfImage(image.Path, image.Location.ToDxfPoint(), pixelWidth, pixelHeight, DxfVector.XAxis); dxfImage.Layer = layer.Name; var radians = image.Rotation * MathHelper.DegreesToRadians; var uVector = new DxfVector(Math.Cos(radians), Math.Sin(radians), 0.0); var vVector = new DxfVector(-Math.Sin(radians), Math.Cos(radians), 0.0); var uVectorLength = dxfImage.ImageSize.X / image.Width; var vVectorLength = dxfImage.ImageSize.Y / image.Height; uVector /= uVectorLength; vVector /= vVectorLength; dxfImage.UVector = uVector; dxfImage.VVector = vVector; return(dxfImage); }
internal override bool TrySetPair(DxfCodePair pair) { switch (pair.Code) { case 10: this.Center = this.Center.WithUpdatedX(pair.DoubleValue); break; case 20: this.Center = this.Center.WithUpdatedY(pair.DoubleValue); break; case 30: this.Center = this.Center.WithUpdatedZ(pair.DoubleValue); break; case 39: this.Thickness = (pair.DoubleValue); break; case 40: this.Radius = (pair.DoubleValue); break; case 210: this.Normal = this.Normal.WithUpdatedX(pair.DoubleValue); break; case 220: this.Normal = this.Normal.WithUpdatedY(pair.DoubleValue); break; case 230: this.Normal = this.Normal.WithUpdatedZ(pair.DoubleValue); break; default: return(base.TrySetPair(pair)); } return(true); }
public static SvgPath FromEllipse(DxfVector normal, double centerX, double centerY, double majorAxisX, double majorAxisY, double minorAxisRatio, double startAngle, double endAngle) { // large arc and counterclockwise computations all rely on the end angle being greater than the start while (endAngle < startAngle) { endAngle += Math.PI * 2.0; } if (IsCloseTo(normal.Z, -1.0)) { // Angles are expressed in OCS // In the case of normal (0,0,-1), startPoint/endPoints are symetric along MajorAxis startAngle = startAngle * -1.0; endAngle = endAngle * -1.0; } var axisAngle = Math.Atan2(majorAxisY, majorAxisX); startAngle += axisAngle; endAngle += axisAngle; var majorAxisLength = Math.Sqrt(majorAxisX * majorAxisX + majorAxisY * majorAxisY); var minorAxisLength = majorAxisLength * minorAxisRatio; var startSin = Math.Sin(startAngle); var startCos = Math.Cos(startAngle); var startX = centerX + startCos * majorAxisLength; var startY = centerY + startSin * minorAxisLength; var endSin = Math.Sin(endAngle); var endCos = Math.Cos(endAngle); var endX = centerX + endCos * majorAxisLength; var endY = centerY + endSin * minorAxisLength; var enclosedAngle = endAngle - startAngle; var isLargeArc = (endAngle - startAngle) > Math.PI; var isCounterClockwise = endAngle > startAngle; var segments = new List <SvgPathSegment>(); segments.Add(new SvgMoveToPath(startX, startY)); var oneDegreeInRadians = Math.PI / 180.0; if (Math.Abs(Math.PI - enclosedAngle) <= oneDegreeInRadians) { // really close to a semicircle; split into to half arcs to avoid rendering artifacts var midAngle = (startAngle + endAngle) / 2.0; var midSin = Math.Sin(midAngle); var midCos = Math.Cos(midAngle); var midX = centerX + midCos * majorAxisLength; var midY = centerY + midSin * minorAxisLength; segments.Add(new SvgArcToPath(majorAxisLength, minorAxisLength, axisAngle, false, isCounterClockwise, midX, midY)); segments.Add(new SvgArcToPath(majorAxisLength, minorAxisLength, axisAngle, false, isCounterClockwise, endX, endY)); } else { // can be contained by just one arc segments.Add(new SvgArcToPath(majorAxisLength, minorAxisLength, axisAngle, isLargeArc, isCounterClockwise, endX, endY)); } return(new SvgPath(segments)); }
public static Vector2 ConvertVector(DxfVector vector) { return(new Vector2((float)vector.X * dxfScale, (float)vector.Y * dxfScale)); }
public DxfXLine(DxfPoint firstPoint, DxfVector unitDirectionVector) : this() { this.FirstPoint = firstPoint; this.UnitDirectionVector = unitDirectionVector; }
internal override bool TrySetPair(DxfCodePair pair) { switch (pair.Code) { case 2: this.Name = (pair.StringValue); break; case 10: this.Location = this.Location.WithUpdatedX(pair.DoubleValue); break; case 20: this.Location = this.Location.WithUpdatedY(pair.DoubleValue); break; case 30: this.Location = this.Location.WithUpdatedZ(pair.DoubleValue); break; case 41: this.XScaleFactor = (pair.DoubleValue); break; case 42: this.YScaleFactor = (pair.DoubleValue); break; case 43: this.ZScaleFactor = (pair.DoubleValue); break; case 44: this.ColumnSpacing = (pair.DoubleValue); break; case 45: this.RowSpacing = (pair.DoubleValue); break; case 50: this.Rotation = (pair.DoubleValue); break; case 66: this.HasAttributes = BoolShort(pair.ShortValue); break; case 70: this.ColumnCount = (pair.ShortValue); break; case 71: this.RowCount = (pair.ShortValue); break; case 210: this.ExtrusionDirection = this.ExtrusionDirection.WithUpdatedX(pair.DoubleValue); break; case 220: this.ExtrusionDirection = this.ExtrusionDirection.WithUpdatedY(pair.DoubleValue); break; case 230: this.ExtrusionDirection = this.ExtrusionDirection.WithUpdatedZ(pair.DoubleValue); break; default: return(base.TrySetPair(pair)); } return(true); }
// // Parameterized constructors // public DxfXLine(DxfPoint firstPoint, DxfVector unitDirectionVector) : this() { this.FirstPoint = firstPoint; this.UnitDirectionVector = unitDirectionVector; }
public DxfViewPort() : base() { LowerLeft = DxfPoint.Origin; UpperRight = new DxfPoint(1.0, 1.0, 0.0); ViewCenter = DxfPoint.Origin; SnapBasePoint = DxfPoint.Origin; SnapSpacing = new DxfVector(1.0, 1.0, 0.0); GridSpacing = new DxfVector(1.0, 1.0, 0.0); ViewDirection = DxfVector.ZAxis; TargetViewPoint = DxfPoint.Origin; ViewHeight = 1.0; ViewPortAspectRatio = 1.0; LensLength = 50.0; FrontClippingPlane = 0.0; BackClippingPlane = 0.0; ViewHeight = 1.0; SnapRotationAngle = 0.0; ViewTwistAngle = 0.0; ViewMode = 0; CircleSides = 1000; FastZoom = true; UCSIcon = 3; SnapOn = false; GridOn = false; SnapStyle = DxfSnapStyle.Standard; SnapIsometricPlane = DxfSnapIsometricPlane.Left; PlotStyleSheet = null; RenderMode = DxfViewRenderMode.Classic2D; HasOwnUCS = false; UCSOrigin = DxfPoint.Origin; UCSXAxis = DxfVector.XAxis; UCSYAxis = DxfVector.YAxis; OrthographicViewType = DxfOrthographicViewType.None; UCSElevation = 0.0; UCSHandle = 0u; BaseUCSHandle = 0u; ShadePlotSetting = DxfShadeEdgeMode.FacesShadedEdgeNotHighlighted; MajorGridLines = false; BackgroundObjectPointer = 0u; ShadePlotObjectPointer = 0u; VisualStyleObjectPointer = 0u; IsDefaultLightingOn = true; DefaultLightingType = DxfDefaultLightingType.OneDistantLight; Brightness = 0.0; Contrast = 0.0; AmbientColor = DxfColor.FromRawValue(7); AmbientColorInt = 0; AmbientColorName = "BLACK"; }
/// <param name="imagePath">The path to the image.</param> /// <param name="location">The bottom left corner of the location to display the image in the drawing.</param> /// <param name="imageWidth">The width of the image in pixels.</param> /// <param name="imageHeight">The height of the image in pixels.</param> /// <param name="displaySize">The display size of the image in drawing units.</param> public DxfWipeout(string imagePath, DxfPoint location, int imageWidth, int imageHeight, DxfVector displaySize) : base(imagePath, location, imageWidth, imageHeight, displaySize) { }
public DxfRay(DxfPoint startPoint, DxfVector unitDirectionVector) : this() { this.StartPoint = startPoint; this.UnitDirectionVector = unitDirectionVector; }
protected override void Initialize() { base.Initialize(); this.StartPoint = DxfPoint.Origin; this.UnitDirectionVector = DxfVector.XAxis; }
internal override bool TrySetPair(DxfCodePair pair) { switch (pair.Code) { case 94: Degree = pair.IntegerValue; break; case 73: IsRational = BoolShort(pair.ShortValue); break; case 74: IsPeriodic = BoolShort(pair.ShortValue); break; case 95: var _knotCount = pair.IntegerValue; break; case 96: var _controlPointCount = pair.IntegerValue; break; case 40: Knots.Add(pair.DoubleValue); break; case 10: ControlPoints.Add(new DxfControlPoint(new DxfPoint(pair.DoubleValue, 0.0, 0.0))); break; case 20: ControlPoints[ControlPoints.Count - 1] = new DxfControlPoint(ControlPoints[ControlPoints.Count - 1].Point.WithUpdatedY(pair.DoubleValue)); break; case 42: ControlPoints[_currentWeight] = new DxfControlPoint(ControlPoints[_currentWeight].Point, pair.DoubleValue); _currentWeight++; break; case 97: var _fitPointCount = pair.IntegerValue; break; case 11: FitPoints.Add(new DxfPoint(pair.DoubleValue, 0.0, 0.0)); break; case 21: FitPoints[FitPoints.Count - 1] = FitPoints[FitPoints.Count - 1].WithUpdatedY(pair.DoubleValue); break; case 12: StartTangent = StartTangent.WithUpdatedX(pair.DoubleValue); break; case 22: StartTangent = StartTangent.WithUpdatedY(pair.DoubleValue); break; case 13: EndTangent = EndTangent.WithUpdatedX(pair.DoubleValue); break; case 23: EndTangent = EndTangent.WithUpdatedY(pair.DoubleValue); break; default: return(false); } return(true); }
internal override bool TrySetPair(DxfCodePair pair) { switch (pair.Code) { case 10: this.FirstCorner = this.FirstCorner.WithUpdatedX(pair.DoubleValue); break; case 20: this.FirstCorner = this.FirstCorner.WithUpdatedY(pair.DoubleValue); break; case 30: this.FirstCorner = this.FirstCorner.WithUpdatedZ(pair.DoubleValue); break; case 11: this.SecondCorner = this.SecondCorner.WithUpdatedX(pair.DoubleValue); break; case 21: this.SecondCorner = this.SecondCorner.WithUpdatedY(pair.DoubleValue); break; case 31: this.SecondCorner = this.SecondCorner.WithUpdatedZ(pair.DoubleValue); break; case 12: this.ThirdCorner = this.ThirdCorner.WithUpdatedX(pair.DoubleValue); break; case 22: this.ThirdCorner = this.ThirdCorner.WithUpdatedY(pair.DoubleValue); break; case 32: this.ThirdCorner = this.ThirdCorner.WithUpdatedZ(pair.DoubleValue); break; case 13: this.FourthCorner = this.FourthCorner.WithUpdatedX(pair.DoubleValue); break; case 23: this.FourthCorner = this.FourthCorner.WithUpdatedY(pair.DoubleValue); break; case 33: this.FourthCorner = this.FourthCorner.WithUpdatedZ(pair.DoubleValue); break; case 39: this.Thickness = (pair.DoubleValue); break; case 210: this.ExtrusionDirection = this.ExtrusionDirection.WithUpdatedX(pair.DoubleValue); break; case 220: this.ExtrusionDirection = this.ExtrusionDirection.WithUpdatedY(pair.DoubleValue); break; case 230: this.ExtrusionDirection = this.ExtrusionDirection.WithUpdatedZ(pair.DoubleValue); break; default: return(base.TrySetPair(pair)); } return(true); }
// // Parameterized constructors // public DxfRay(DxfPoint startPoint, DxfVector unitDirectionVector) : this() { this.StartPoint = startPoint; this.UnitDirectionVector = unitDirectionVector; }
public static Vector ToVector(this DxfVector vector) { return(new Vector(vector.X, vector.Y, vector.Z)); }