Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/thaiguer/ACadSharp
Browse files Browse the repository at this point in the history
  • Loading branch information
thaiguer committed Oct 3, 2024
2 parents 8330999 + d2e0092 commit 09a7c51
Show file tree
Hide file tree
Showing 27 changed files with 476 additions and 58 deletions.
13 changes: 13 additions & 0 deletions src/ACadSharp.Tests/Entities/ArcTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ public void CreateFromBulgeTest()
Assert.Equal(Math.PI / 2, arc.EndAngle);
}

[Fact]
public void GetBoundingBoxTest()
{
Arc arc = new Arc();
arc.Radius = 5;
arc.EndAngle = Math.PI / 2;

BoundingBox boundingBox = arc.GetBoundingBox();

Assert.Equal(new XYZ(0, 0, 0), boundingBox.Min);
Assert.Equal(new XYZ(5, 5, 0), boundingBox.Max);
}

[Fact]
public void GetCenter()
{
Expand Down
21 changes: 21 additions & 0 deletions src/ACadSharp.Tests/Entities/CircleTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using ACadSharp.Entities;
using CSMath;
using Xunit;

namespace ACadSharp.Tests.Entities
{
public class CircleTests
{
[Fact]
public void GetBoundingBoxTest()
{
Circle circle = new Circle();
circle.Radius = 5;

BoundingBox boundingBox = circle.GetBoundingBox();

Assert.Equal(new XYZ(-5, -5, 0), boundingBox.Min);
Assert.Equal(new XYZ(5, 5, 0), boundingBox.Max);
}
}
}
23 changes: 23 additions & 0 deletions src/ACadSharp.Tests/Entities/EllipseTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using ACadSharp.Entities;
using CSMath;
using System;
using Xunit;

namespace ACadSharp.Tests.Entities
{
public class EllipseTests
{
[Fact]
public void GetBoundingBoxTest()
{
//Ellipse size: x = 1, y = 0.5
Ellipse ellipse = new();
ellipse.RadiusRatio = 0.5d;

BoundingBox boundingBox = ellipse.GetBoundingBox();

Assert.Equal(new XYZ(-1, -0.5, 0), boundingBox.Min);
Assert.Equal(new XYZ(1, 0.5, 0), boundingBox.Max);
}
}
}
25 changes: 25 additions & 0 deletions src/ACadSharp.Tests/Entities/HatchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,30 @@ public void PolylineHatchNotAllowMoreEdges()
}
);
}

[Fact]
public void GetBoundingBoxTest()
{
Hatch hatch = new Hatch();
hatch.IsSolid = true;

Hatch.BoundaryPath path = new Hatch.BoundaryPath();

Hatch.BoundaryPath.Polyline pline = new Hatch.BoundaryPath.Polyline();
pline.Vertices.Add(new XYZ(0, 0, 0));
pline.Vertices.Add(new XYZ(1, 0, 0));
pline.Vertices.Add(new XYZ(1, 1, 0));
pline.Vertices.Add(new XYZ(0, 1, 0));
pline.Vertices.Add(new XYZ(0, 0, 0));

path.Edges.Add(pline);

hatch.Paths.Add(path);

var box = hatch.GetBoundingBox();

Assert.Equal(new XYZ(0, 0, 0), box.Min);
Assert.Equal(new XYZ(1, 1, 0), box.Max);
}
}
}
21 changes: 21 additions & 0 deletions src/ACadSharp.Tests/Entities/LineTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using ACadSharp.Entities;
using CSMath;
using Xunit;

namespace ACadSharp.Tests.Entities
{
public class LineTests
{
[Fact]
public void GetBoundingBoxTest()
{
Line line = new Line();
line.EndPoint = new XYZ(10, 10, 0);

BoundingBox boundingBox = line.GetBoundingBox();

Assert.Equal(new XYZ(0, 0, 0), boundingBox.Min);
Assert.Equal(new XYZ(10, 10, 0), boundingBox.Max);
}
}
}
39 changes: 39 additions & 0 deletions src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ACadSharp.Tables;
using CSMath;
using CSUtilities.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -107,6 +108,16 @@ public void CurrentEntityByBlock()
this.Document.Header.CurrentEntityColor = Color.ByBlock;
}

public void SingleEllipse()
{
Ellipse ellipse = new Ellipse();
ellipse.RadiusRatio = 0.5d;
ellipse.StartParameter = 0.0d;
ellipse.EndParameter = Math.PI * 2;

this.Document.Entities.Add(ellipse);
}

public void SingleLine()
{
Line line = new Line(XYZ.Zero, new XYZ(100, 100, 0));
Expand Down Expand Up @@ -361,6 +372,32 @@ public void CreateHatch()
this.Document.Entities.Add(hatch);
}

public void CreateCircleHatch()
{
Hatch hatch = new Hatch();
hatch.IsSolid = true;

hatch.SeedPoints.Add(new XY());

List<Hatch.BoundaryPath.Line> edges = new List<Hatch.BoundaryPath.Line>();

//edges
Hatch.BoundaryPath.Polyline polyline = new Hatch.BoundaryPath.Polyline();
polyline.IsClosed = true;
polyline.Vertices.Add(new XYZ(0, 2.5, 1));
polyline.Vertices.Add(new XYZ(10, 2.5, 1));

Hatch.BoundaryPath path = new Hatch.BoundaryPath();
foreach (var item in edges)
{
path.Edges.Add(item);
}

hatch.Paths.Add(path);

this.Document.Entities.Add(hatch);
}

public void ChangedEncoding()
{
this.Document.Header.CodePage = "gb2312";
Expand Down Expand Up @@ -426,6 +463,7 @@ static WriterSingleObjectTests()
}

Data.Add(new(nameof(SingleCaseGenerator.Empty)));
Data.Add(new(nameof(SingleCaseGenerator.SingleEllipse)));
Data.Add(new(nameof(SingleCaseGenerator.SingleLine)));
Data.Add(new(nameof(SingleCaseGenerator.SingleMLine)));
Data.Add(new(nameof(SingleCaseGenerator.EntityColorByLayer)));
Expand All @@ -450,6 +488,7 @@ static WriterSingleObjectTests()
Data.Add(new(nameof(SingleCaseGenerator.LineTypeWithSegments)));
Data.Add(new(nameof(SingleCaseGenerator.CreateHatchPolyline)));
Data.Add(new(nameof(SingleCaseGenerator.CreateHatch)));
Data.Add(new(nameof(SingleCaseGenerator.CreateCircleHatch)));
Data.Add(new(nameof(SingleCaseGenerator.ChangedEncoding)));
Data.Add(new(nameof(SingleCaseGenerator.AddBlockWithAttributes)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/ACadSharp/ACadSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Version>1.0.0</Version>
<Version>1.0.1</Version>
<PackageOutputPath>../nupkg</PackageOutputPath>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/ACadSharp/CadObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public CadDictionary CreateExtendedDictionary()
/// Creates a new object that is a copy of the current instance.
/// </summary>
/// <remarks>
/// The copy will be unatached from the document or any reference
/// The copy will be unattached from the document or any reference.
/// </remarks>
/// <returns>A new object that is a copy of this instance.</returns>
public virtual CadObject Clone()
Expand Down
11 changes: 10 additions & 1 deletion src/ACadSharp/Entities/Arc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using CSMath;
using System;
using System.Collections.Generic;
using System.Linq;

namespace ACadSharp.Entities
{
Expand Down Expand Up @@ -121,10 +122,18 @@ public List<XY> PolygonalVertexes(int precision)
cosine = MathUtils.IsZero(cosine) ? 0 : cosine;
sine = MathUtils.IsZero(sine) ? 0 : sine;

ocsVertexes.Add(new XY(cosine, sine));
ocsVertexes.Add(new XY(cosine + this.Center.X, sine + this.Center.Y));
}

return ocsVertexes;
}

/// <inheritdoc/>
public override BoundingBox GetBoundingBox()
{
List<XY> vertices = this.PolygonalVertexes(256);

return BoundingBox.FromPoints(vertices.Select(v => (XYZ)v));
}
}
}
8 changes: 4 additions & 4 deletions src/ACadSharp/Entities/Dimension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ public bool IsTextUserDefinedLocation
/// <b>true</b> if the arrow is to be flipped; otherwise, <b>false</b>.
/// </value>
/// <remarks>
/// Arrows are by default drawn inside the extension lines if there is enaugh
/// space; otherwise, outside. This flag overrules the standard behaviour.
/// Arrows are by default drawn inside the extension lines if there is enough
/// space; otherwise, outside. This flag overrules the standard behavior.
/// </remarks>
[DxfCodeValue(74)]
public bool FlipArrow1 { get; set; }
Expand All @@ -142,8 +142,8 @@ public bool IsTextUserDefinedLocation
/// <b>true</b> if the arrow is to be flipped; otherwise, <b>false</b>.
/// </value>
/// <remarks>
/// Arrows are by default drawn inside the extension lines if there is enaugh
/// space; otherwise, outside. This flag overrules the standard behaviour.
/// Arrows are by default drawn inside the extension lines if there is enough
/// space; otherwise, outside. This flag overrules the standard behavior.
/// </remarks>
[DxfCodeValue(75)]
public bool FlipArrow2 { get; set; }
Expand Down
Loading

0 comments on commit 09a7c51

Please sign in to comment.