Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Aug 14, 2024
2 parents f60b432 + 44749f7 commit ab55fd4
Show file tree
Hide file tree
Showing 89 changed files with 875 additions and 271 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Coveralls

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

env:
SAMPLES_FOLDER: "../../../../samples"
OUTPUT_SAMPLES_FOLDER: "../../../../samples/out"
OUTPUT_SINGLE_CASES_FOLDER: "../../../../samples/out/single_cases"
LOCAL_ENV: "false"
DELTA: "0.00001"
DECIMAL_PRECISION: "5"
RUN_DWG_WRITER_SINGLE_CASES_TEST: "false"

jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test -p:CollectCoverage=true -p:CoverletOutput=TestResults/ -p:CoverletOutputFormat=lcov --no-build --verbosity normal ACadSharp.Tests/
- name: Coveralls action
uses: coverallsapp/github-action@master
with:
github-token: ${{ github.token }}
path-to-lcov: ACadSharp.Tests/TestResults/coverage.info
6 changes: 5 additions & 1 deletion ACadSharp.Tests/ACadSharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
<PackageReference Include="MSTest.TestAdapter" Version="3.*" />
<PackageReference Include="MSTest.TestFramework" Version="3.*" />
<PackageReference Include="coverlet.collector" Version="6.*">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
9 changes: 9 additions & 0 deletions ACadSharp.Tests/Entities/EntityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ static EntityTests()
}
}

[Theory]
[MemberData(nameof(EntityTypes))]
public void BoundingBoxTest(Type entityType)
{
Entity entity = EntityFactory.Create(entityType);

entity.GetBoundingBox();
}

[Theory]
[MemberData(nameof(EntityTypes))]
public void Clone(Type entityType)
Expand Down
2 changes: 1 addition & 1 deletion ACadSharp.Tests/IO/IOTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void DxfToDxf(string test)
{
CadDocument doc = DxfReader.Read(test);

if(doc.Header.Version < ACadVersion.AC1012)
if (doc.Header.Version < ACadVersion.AC1012)
{
return;
}
Expand Down
1 change: 0 additions & 1 deletion ACadSharp.Tests/IO/LocalSampleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public void ReadUserDxf(string test)
CadDocument doc = DxfReader.Read(test, this.onNotification);
}


[Theory]
[MemberData(nameof(StressFiles))]
public void ReadStressFiles(string test)
Expand Down
31 changes: 31 additions & 0 deletions ACadSharp.Tests/IO/WriterSingleObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,29 @@ public void CreateLayout()
this.Document.Layouts.Add(layout);
}

public void LineTypeWithSegments()
{
LineType lt = new LineType("segmented");
lt.Description = "hello";

LineType.Segment s1 = new LineType.Segment
{
Length = 12,
//Style = this.Document.TextStyles[TextStyle.DefaultName]
};

LineType.Segment s2 = new LineType.Segment
{
Length = -3,
//Style = this.Document.TextStyles[TextStyle.DefaultName]
};

lt.AddSegment(s1);
lt.AddSegment(s2);

this.Document.LineTypes.Add(lt);
}

public void ClosedLwPolyline()
{
List<LwPolyline.Vertex> vertices = new List<LwPolyline.Vertex>() {
Expand Down Expand Up @@ -236,6 +259,12 @@ public void EntityTransparency()
this.Document.Entities.Add(line);
}

public void ChangedEncoding()
{
this.Document.Header.CodePage = "gb2312";
this.Document.Layers.Add(new Layer("我的自定义层"));
}

public void Deserialize(IXunitSerializationInfo info)
{
this.Name = info.GetValue<string>(nameof(this.Name));
Expand Down Expand Up @@ -279,6 +308,8 @@ static WriterSingleObjectTests()
Data.Add(new(nameof(SingleCaseGenerator.SingleWipeout)));
Data.Add(new(nameof(SingleCaseGenerator.CreateLayout)));
Data.Add(new(nameof(SingleCaseGenerator.EntityTransparency)));
Data.Add(new(nameof(SingleCaseGenerator.LineTypeWithSegments)));
Data.Add(new(nameof(SingleCaseGenerator.ChangedEncoding)));
}

protected string getPath(string name, string ext, ACadVersion version)
Expand Down
2 changes: 1 addition & 1 deletion ACadSharp.Tests/Internal/DwgHandleWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void WriteTest(ACadVersion version)
writer.Write();

IDwgStreamReader sreader = DwgStreamReaderBase.GetStreamHandler(version, stream, resetPositon: true);
DwgHandleReader reader = new DwgHandleReader(sreader, version);
DwgHandleReader reader = new DwgHandleReader(version, sreader);
reader.OnNotification += onNotification;

var outmap = reader.Read();
Expand Down
3 changes: 2 additions & 1 deletion ACadSharp.Tests/Internal/DwgHeaderWriterTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ACadSharp.Header;
using ACadSharp.IO.DWG;
using System.IO;
using System.Text;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -20,7 +21,7 @@ public void WriteTest(ACadVersion version)
CadDocument document = new CadDocument();
document.Header.Version = version;

DwgHeaderWriter writer = new DwgHeaderWriter(stream, document);
DwgHeaderWriter writer = new DwgHeaderWriter(stream, document, Encoding.Default);
writer.Write();

IDwgStreamReader sreader = DwgStreamReaderBase.GetStreamHandler(version, stream, resetPositon: true);
Expand Down
3 changes: 2 additions & 1 deletion ACadSharp.Tests/Internal/DwgObjectWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -121,7 +122,7 @@ private DwgDocumentBuilder writeInfo(CadDocument docToWrite)
{
Stream stream = new MemoryStream();

DwgObjectWriter writer = new DwgObjectWriter(stream, docToWrite);
DwgObjectWriter writer = new DwgObjectWriter(stream, docToWrite, Encoding.Default);
writer.OnNotification += onNotification;
writer.Write();

Expand Down
2 changes: 1 addition & 1 deletion ACadSharp.Tests/Objects/CadDictionaryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ACadSharp.Tests.Objects
{
public class CadDictionaryTests
public class CadDictionaryTests : NonGraphicalObjectTests<CadDictionary>
{
[Fact]
public void AvoidDuplicatedEntries()
Expand Down
2 changes: 1 addition & 1 deletion ACadSharp.Tests/Objects/LayoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace ACadSharp.Tests.Objects
{
public class LayoutTests
public class LayoutTests: NonGraphicalObjectTests<Layout>
{
[Fact]
public void AddLayout()
Expand Down
20 changes: 20 additions & 0 deletions ACadSharp.Tests/Objects/NonGraphicalObjectTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using ACadSharp.Objects;
using System;
using Xunit;

namespace ACadSharp.Tests.Objects
{
public abstract class NonGraphicalObjectTests<T>
where T : NonGraphicalObject
{
[Fact]
public void InitName()
{
string name = "custom_name";
T obj = (T)Activator.CreateInstance(typeof(T), name);

Assert.NotNull(obj.Name);
Assert.Equal(name, obj.Name);
}
}
}
3 changes: 3 additions & 0 deletions ACadSharp.Tests/TestVariables.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using CSUtilities;
using System;
using System.IO;

namespace ACadSharp.Tests
{
public static class TestVariables
{
public static string DesktopFolder { get { return Environment.GetFolderPath(Environment.SpecialFolder.Desktop); } }

public static string SamplesFolder { get { return EnvironmentVars.Get<string>("SAMPLES_FOLDER"); } }

public static string OutputSamplesFolder { get { return EnvironmentVars.Get<string>("OUTPUT_SAMPLES_FOLDER"); } }
Expand Down
1 change: 1 addition & 0 deletions ACadSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\build.yml = .github\workflows\build.yml
.github\workflows\build_n_test.yml = .github\workflows\build_n_test.yml
publish.yml = publish.yml
.github\workflows\coveralls.yml = .github\workflows\coveralls.yml
.github\workflows\wiki-gen.yml = .github\workflows\wiki-gen.yml
EndProjectSection
EndProject
Expand Down
11 changes: 11 additions & 0 deletions ACadSharp/Blocks/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,16 @@ public override CadObject Clone()

return clone;
}

public override BoundingBox GetBoundingBox()
{
BoundingBox box = BoundingBox.Null;
foreach (var item in this.BlockOwner.Entities)
{
box = box.Merge(item.GetBoundingBox());
}

return box;
}
}
}
7 changes: 7 additions & 0 deletions ACadSharp/Blocks/BlockEnd.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ACadSharp.Attributes;
using ACadSharp.Entities;
using ACadSharp.Tables;
using CSMath;

namespace ACadSharp.Blocks
{
Expand Down Expand Up @@ -36,5 +37,11 @@ public override CadObject Clone()
clone.Owner = new BlockRecord((this.Owner as BlockRecord).Name);
return clone;
}

/// <inheritdoc/>
public override BoundingBox GetBoundingBox()
{
return BoundingBox.Null;
}
}
}
43 changes: 43 additions & 0 deletions ACadSharp/Entities/Arc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class Arc : Circle
[DxfCodeValue(DxfReferenceType.IsAngle, 51)]
public double EndAngle { get; set; } = Math.PI;

/// <summary>
/// Default constructor
/// </summary>
public Arc() : base() { }

/// <summary>
Expand Down Expand Up @@ -73,5 +76,45 @@ public static Arc CreateFromBulge(XY p1, XY p2, double bulge)
EndAngle = endAngle,
};
}

/// <summary>
/// Process the 2 points limiting the arc segment
/// </summary>
/// <param name="start">Start point of the arc segment</param>
/// <param name="end">End point of the arc segment</param>
public void GetEndVertices(out XYZ start, out XYZ end)
{
if (this.Normal != XYZ.AxisZ)
{
throw new NotImplementedException("GetBoundPoints box for not aligned Normal is not implemented");
}

double tmpEndAngle = this.EndAngle;

if (this.EndAngle < this.StartAngle)
{
tmpEndAngle += 2 * Math.PI;
}

double delta = tmpEndAngle - this.StartAngle;

double angle = this.StartAngle + delta;
double startX = this.Radius * Math.Sin(angle);
double startY = this.Radius * Math.Cos(angle);

startX = MathUtils.IsZero(startX) ? 0 : startX;
startY = MathUtils.IsZero(startY) ? 0 : startY;

start = new XYZ(startX, startY, 0);

double angle2 = this.StartAngle + delta * 2;
double endX = (this.Radius * Math.Sin(angle2));
double endY = (this.Radius * Math.Cos(angle2));

endX = MathUtils.IsZero(endX) ? 0 : endX;
endY = MathUtils.IsZero(endY) ? 0 : endY;

end = new XYZ(endX, endY, 0);
}
}
}
26 changes: 26 additions & 0 deletions ACadSharp/Entities/CadImageBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
using System.Collections.Generic;
using System;
using ACadSharp.Objects;
using System.Linq;

namespace ACadSharp.Entities
{
/// <summary>
/// Common base class for <see cref="RasterImage" /> and <see cref="Wipeout" />.
/// </summary>
[DxfSubClass(null, true)]
public abstract class CadImageBase : Entity
{
Expand Down Expand Up @@ -185,6 +189,28 @@ internal ImageDefinitionReactor DefinitionReactor
private ImageDefinition _definition;
private ImageDefinitionReactor _definitionReactor;

/// <inheritdoc/>
public override BoundingBox GetBoundingBox()
{
if (!this.ClipBoundaryVertices.Any())
{
return BoundingBox.Null;
}

double minX = this.ClipBoundaryVertices.Select(v => v.X).Min();
double minY = this.ClipBoundaryVertices.Select(v => v.Y).Min();
XYZ min = new XYZ(minX, minY, 0) + this.InsertPoint;

double maxX = this.ClipBoundaryVertices.Select(v => v.X).Max();
double maxY = this.ClipBoundaryVertices.Select(v => v.Y).Max();
XYZ max = new XYZ(maxX, maxY, 0) + this.InsertPoint;

BoundingBox box = new BoundingBox(min, max);

return box;
}

/// <inheritdoc/>
public override CadObject Clone()
{
CadImageBase clone = (CadImageBase)base.Clone();
Expand Down
Loading

0 comments on commit ab55fd4

Please sign in to comment.