Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
[2022/05/27]
Browse files Browse the repository at this point in the history
* Added the Matrix3.Reflection method that builds a reflection matrix for a mirror plane that passes through the origin. See sample ReflectionMatrix().
* Added the Matrix4.Reflection method that builds a reflection matrix for a mirror plane that passes through an arbitrary point. See sample ReflectionMatrix().
* Corrected the comments in the Ellipse.Center property.
* (fixed) In the Ellipse.SetAxis method the validity checks must be performed with the arguments of the method not the actual major and minor axis of the ellipse.
  • Loading branch information
haplokuon committed May 27, 2022
1 parent 5144bff commit 7bff33a
Show file tree
Hide file tree
Showing 30 changed files with 730 additions and 51 deletions.
35 changes: 34 additions & 1 deletion TestDxfDocument/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Program
{
public static void Main()
{
DxfDocument doc = Test(@"sample.dxf");
DxfDocument doc = Test(@"sample.dxf");

#region Samples for GTE classes

Expand All @@ -48,6 +48,7 @@ public static void Main()

#region Samples for new and modified features 3.0.0

//ReflectionMatrix();
//PolygonMesh();
//UcsTransform();
//SmoothPolyline2D();
Expand Down Expand Up @@ -710,6 +711,38 @@ public static void NURBSSurface()

#region Samples for new and modified features 3.0.0

public static void ReflectionMatrix()
{
Polyline2D polyline = new Polyline2D(new []{
new Polyline2DVertex(-5,-5),
new Polyline2DVertex(-5,5),
new Polyline2DVertex(0,0),
new Polyline2DVertex(5,5),
new Polyline2DVertex(5,-5)}, true) {Color = AciColor.Blue};

polyline.TransformBy(Matrix3.Identity, new Vector3(20,20,0));

Line mirrorLine = new Line(new Vector3(20,5,0), new Vector3(0,15,0)) {Color = AciColor.Yellow};
Vector3 mirrorNormal = Vector3.CrossProduct(mirrorLine.Direction, Vector3.UnitZ);

Polyline2D reflection = (Polyline2D) polyline.Clone();
reflection.Color = AciColor.Red;

// reflection matrix of a mirror plane given its normal and a point on the plane
Matrix4 reflectionMatrix = Matrix4.Reflection(mirrorNormal, mirrorLine.StartPoint);

// for a mirror plane that passes through the origin, you can also use
//Matrix3 reflectionMatrix = Matrix3.Reflection(mirrorNormal);
reflection.TransformBy(reflectionMatrix);

DxfDocument doc = new DxfDocument();
doc.Entities.Add(polyline);
doc.Entities.Add(mirrorLine);
doc.Entities.Add(reflection);

doc.Save("test.dxf");
}

public static void PolygonMesh()
{
short u = 4;
Expand Down
6 changes: 6 additions & 0 deletions doc/Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Change history

### [2022/05/27]
* Added the Matrix3.Reflection method that builds a reflection matrix for a mirror plane that passes through the origin. See sample ReflectionMatrix().
* Added the Matrix4.Reflection method that builds a reflection matrix for a mirror plane that passes through an arbitrary point. See sample ReflectionMatrix().
* Corrected the comments in the Ellipse.Center property.
* (fixed) In the Ellipse.SetAxis method the validity checks must be performed with the arguments of the method not the actual major and minor axis of the ellipse.

### [2022/04/19]
* Added more GTE classes. See the Samples for GTE classes
* Deleted the SplineVertex class. Now the Spline constructors take two lists: a Vector3 to define the controls points and a double array to define the weights.
Expand Down
2 changes: 1 addition & 1 deletion netDxf/Entities/Circle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Circle(Vector2 center, double radius)
#region public properties

/// <summary>
/// Gets or sets the circle <see cref="netDxf.Vector3">center</see> in world coordinates.
/// Gets or sets the circle <see cref="Vector3">center</see> in world coordinates.
/// </summary>
public Vector3 Center
{
Expand Down
13 changes: 6 additions & 7 deletions netDxf/Entities/Ellipse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,8 @@ public Ellipse(Vector3 center, double majorAxis, double minorAxis)
#region public properties

/// <summary>
/// Gets or sets the ellipse <see cref="Vector3">center</see>.
/// Gets or sets the ellipse <see cref="Vector3">center</see> in world coordinates.
/// </summary>
/// <remarks>The center Z coordinate represents the elevation of the arc along the normal.</remarks>
public Vector3 Center
{
get { return this.center; }
Expand Down Expand Up @@ -364,17 +363,17 @@ public bool IsFullEllipse
/// <param name="minor">Ellipse minor axis.</param>
public void SetAxis(double major, double minor)
{
if (majorAxis <= 0)
if (major <= 0)
{
throw new ArgumentOutOfRangeException(nameof(majorAxis), majorAxis, "The major axis value must be greater than zero.");
throw new ArgumentOutOfRangeException(nameof(major), major, "The major axis value must be greater than zero.");
}

if (minorAxis <= 0)
if (minor <= 0)
{
throw new ArgumentOutOfRangeException(nameof(minorAxis), minorAxis, "The minor axis value must be greater than zero.");
throw new ArgumentOutOfRangeException(nameof(minor), minor, "The minor axis value must be greater than zero.");
}

if ( minorAxis > majorAxis)
if ( minor > major)
{
throw new ArgumentException("The ellipse major axis must be greater than the minor axis.");
}
Expand Down
12 changes: 6 additions & 6 deletions netDxf/Entities/Spline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public class Spline :
{
#region private fields

private Vector3[] fitPoints;
private readonly Vector3[] fitPoints;
private readonly SplineCreationMethod creationMethod;
private Vector3? startTangent;
private Vector3? endTangent;
private Vector3[] controlPoints;
private double[] weights;
private readonly Vector3[] controlPoints;
private readonly double[] weights;
private double[] knots;
private readonly short degree;
private bool isClosedPeriodic;
Expand Down Expand Up @@ -505,9 +505,9 @@ public double[] Knots
/// </summary>
public void Reverse()
{
this.fitPoints = this.fitPoints.Reverse().ToArray();
this.controlPoints = this.controlPoints.Reverse().ToArray();
this.weights = this.weights.Reverse().ToArray();
Array.Reverse(this.fitPoints);
Array.Reverse(this.controlPoints);
Array.Reverse(this.weights);
Vector3? tmp = this.startTangent;
this.startTangent = -this.endTangent;
this.endTangent = -tmp;
Expand Down
27 changes: 26 additions & 1 deletion netDxf/GTE/BSplineCurve.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
// This is a translation to C# from the original C++ code of the Geometric Tool Library
#region netDxf library licensed under the MIT License
//
// netDxf library
// Copyright (c) Daniel Carvajal (haplokuon@gmail.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#endregion

// This is a translation to C# from the original C++ code of the Geometric Tool Library
// Original license
// David Eberly, Geometric Tools, Redmond WA 98052
// Copyright (c) 1998-2022
Expand Down
29 changes: 28 additions & 1 deletion netDxf/GTE/BSplineCurveFit.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
// David Eberly, Geometric Tools, Redmond WA 98052
#region netDxf library licensed under the MIT License
//
// netDxf library
// Copyright (c) Daniel Carvajal (haplokuon@gmail.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#endregion

// This is a translation to C# from the original C++ code of the Geometric Tool Library
// Original license
// David Eberly, Geometric Tools, Redmond WA 98052
// Copyright (c) 1998-2022
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
Expand Down
29 changes: 28 additions & 1 deletion netDxf/GTE/BSplineReduction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
// David Eberly, Geometric Tools, Redmond WA 98052
#region netDxf library licensed under the MIT License
//
// netDxf library
// Copyright (c) Daniel Carvajal (haplokuon@gmail.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#endregion

// This is a translation to C# from the original C++ code of the Geometric Tool Library
// Original license
// David Eberly, Geometric Tools, Redmond WA 98052
// Copyright (c) 1998-2022
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
Expand Down
27 changes: 26 additions & 1 deletion netDxf/GTE/BSplineSurface.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
// This is a translation to C# from the original C++ code of the Geometric Tool Library
#region netDxf library licensed under the MIT License
//
// netDxf library
// Copyright (c) Daniel Carvajal (haplokuon@gmail.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#endregion

// This is a translation to C# from the original C++ code of the Geometric Tool Library
// Original license
// David Eberly, Geometric Tools, Redmond WA 98052
// Copyright (c) 1998-2022
Expand Down
29 changes: 28 additions & 1 deletion netDxf/GTE/BSplineSurfaceFit.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
// David Eberly, Geometric Tools, Redmond WA 98052
#region netDxf library licensed under the MIT License
//
// netDxf library
// Copyright (c) Daniel Carvajal (haplokuon@gmail.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#endregion

// This is a translation to C# from the original C++ code of the Geometric Tool Library
// Original license
// David Eberly, Geometric Tools, Redmond WA 98052
// Copyright (c) 1998-2022
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
Expand Down
29 changes: 28 additions & 1 deletion netDxf/GTE/BandedMatrix.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
// David Eberly, Geometric Tools, Redmond WA 98052
#region netDxf library licensed under the MIT License
//
// netDxf library
// Copyright (c) Daniel Carvajal (haplokuon@gmail.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#endregion

// This is a translation to C# from the original C++ code of the Geometric Tool Library
// Original license
// David Eberly, Geometric Tools, Redmond WA 98052
// Copyright (c) 1998-2022
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
Expand Down
35 changes: 30 additions & 5 deletions netDxf/GTE/BasisFunction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
// This is a translation to C# from the original C++ code of the Geometric Tool Library
#region netDxf library licensed under the MIT License
//
// netDxf library
// Copyright (c) Daniel Carvajal (haplokuon@gmail.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#endregion

// This is a translation to C# from the original C++ code of the Geometric Tool Library
// Original license
// David Eberly, Geometric Tools, Redmond WA 98052
// Copyright (c) 1998-2022
Expand Down Expand Up @@ -141,10 +166,10 @@ public UniqueKnot[] UniqueKnots
// for 1 <= i <= d.
public class BasisFunction
{
private struct Key
private readonly struct Key
{
private double knotValue;
private int knotIndex;
private readonly double knotValue;
private readonly int knotIndex;

public Key(double knotValue, int knotIndex)
{
Expand Down Expand Up @@ -229,7 +254,7 @@ public void Create(BasisFunctionInput input)
int mult0 = this.uniqueKnots[0].Multiplicity;
Debug.Assert(mult0 >= 1 && mult0 <= this.degree + 1, "Invalid first multiplicity.");

int mult1 = this.uniqueKnots[this.uniqueKnots.Length -1].Multiplicity;
int mult1 = this.uniqueKnots[this.uniqueKnots.Length - 1].Multiplicity;
Debug.Assert(mult1 >= 1 && mult1 <= this.degree + 1, "Invalid last multiplicity.");

for (int i = 1; i <= input.NumUniqueKnots - 2; i++)
Expand Down
Loading

0 comments on commit 7bff33a

Please sign in to comment.