diff --git a/src/Speckle.Objects/BuiltElements/Archicad/ElementShape.cs b/src/Speckle.Objects/BuiltElements/Archicad/ElementShape.cs index 257b27e4..ca48e028 100644 --- a/src/Speckle.Objects/BuiltElements/Archicad/ElementShape.cs +++ b/src/Speckle.Objects/BuiltElements/Archicad/ElementShape.cs @@ -45,7 +45,7 @@ public sealed class ElementShape : Base public double arcAngle { get; set; } public bool? bodyFlag { get; set; } public double length { get; set; } - public Interval domain { get; set; } = new(0, 1); + public Interval domain { get; set; } = Interval.UnitInterval; } /// @@ -66,6 +66,6 @@ public sealed class ElementShape : Base public List polylineSegments { get; set; } = new(); public double length { get; set; } - public Interval domain { get; set; } = new(0, 1); + public Interval domain { get; set; } = Interval.UnitInterval; } } diff --git a/src/Speckle.Objects/Geometry/Arc.cs b/src/Speckle.Objects/Geometry/Arc.cs index 54b10e9a..9765670f 100644 --- a/src/Speckle.Objects/Geometry/Arc.cs +++ b/src/Speckle.Objects/Geometry/Arc.cs @@ -41,7 +41,10 @@ public class Arc : Base, IHasBoundingBox, ICurve, IHasArea, ITransformable this.startAngle = startAngle; this.endAngle = endAngle; this.angleRadians = angleRadians; - domain = angleRadians > 0 ? new Interval(0, angleRadians) : new Interval(angleRadians, 0); + domain = + angleRadians > 0 + ? new Interval { start = 0, end = angleRadians } + : new Interval { start = angleRadians, end = 0 }; this.applicationId = applicationId; this.units = units; } @@ -64,7 +67,14 @@ public class Arc : Base, IHasBoundingBox, ICurve, IHasArea, ITransformable string? applicationId = null ) : this( - new Plane(startPoint, new Vector(0, 0, 1), new Vector(1, 0, 0), new Vector(0, 1, 0), units), + new Plane + { + origin = startPoint, + normal = new Vector(0, 0, 1), + xdir = new Vector(1, 0, 0), + ydir = new Vector(0, 1, 0), + units = units + }, startPoint, endPoint, angleRadians, @@ -106,7 +116,10 @@ public class Arc : Base, IHasBoundingBox, ICurve, IHasArea, ITransformable this.startPoint = startPoint; this.endPoint = endPoint; this.angleRadians = angleRadians; - domain = angleRadians > 0 ? new Interval(0, angleRadians) : new Interval(angleRadians, 0); + domain = + angleRadians > 0 + ? new Interval { start = 0, end = angleRadians } + : new Interval { start = angleRadians, end = 0 }; this.applicationId = applicationId; // find chord and chord angle which may differ from the arc angle @@ -204,7 +217,7 @@ public class Arc : Base, IHasBoundingBox, ICurve, IHasArea, ITransformable public string units { get; set; } /// - public Interval domain { get; set; } = new(0, 0); + public Interval domain { get; set; } = new() { start = 0, end = 0 }; /// public double length { get; set; } @@ -213,7 +226,7 @@ public class Arc : Base, IHasBoundingBox, ICurve, IHasArea, ITransformable public double area { get; set; } /// - public Box bbox { get; set; } + public Box? bbox { get; set; } /// public bool TransformTo(Transform transform, out Arc transformed) @@ -279,7 +292,7 @@ public class Arc : Base, IHasBoundingBox, ICurve, IHasArea, ITransformable startAngle = list[3], endAngle = list[4], angleRadians = list[5], - domain = new Interval(list[6], list[7]), + domain = new Interval { start = list[6], end = list[7] }, units = Units.GetUnitFromEncoding(list[list.Count - 1]), plane = Plane.FromList(list.GetRange(8, 13)) }; diff --git a/src/Speckle.Objects/Geometry/Box.cs b/src/Speckle.Objects/Geometry/Box.cs index db27ad45..f2af8df1 100644 --- a/src/Speckle.Objects/Geometry/Box.cs +++ b/src/Speckle.Objects/Geometry/Box.cs @@ -10,54 +10,25 @@ namespace Speckle.Objects.Geometry; [SpeckleType("Objects.Geometry.Box")] public class Box : Base, IHasVolume, IHasArea, IHasBoundingBox { - /// - public Box() { } - - /// - /// Constructs a new instance with a and coordinate intervals for all 3 axis {x , y , z} - /// - /// The plane the box will be oriented by. - /// The range of coordinates (min, max) for the X axis - /// The range of coordinates (min, max) for the Y axis - /// The range of coordinates (min, max) for the Z axis - /// The units the coordinates are in. - /// The unique application ID of the object. - public Box( - Plane basePlane, - Interval xSize, - Interval ySize, - Interval zSize, - string units = Units.Meters, - string? applicationId = null - ) - { - this.basePlane = basePlane; - this.xSize = xSize; - this.ySize = ySize; - this.zSize = zSize; - this.applicationId = applicationId; - this.units = units; - } - /// /// Gets or sets the plane that defines the orientation of the /// - public Plane basePlane { get; set; } + public required Plane basePlane { get; set; } /// /// Gets or sets the that defines the min and max coordinate in the X direction /// - public Interval xSize { get; set; } + public required Interval xSize { get; set; } /// /// Gets or sets the that defines the min and max coordinate in the Y direction /// - public Interval ySize { get; set; } + public required Interval ySize { get; set; } /// /// Gets or sets the that defines the min and max coordinate in the Y direction /// - public Interval zSize { get; set; } + public required Interval zSize { get; set; } /// /// The units this object's coordinates are in. @@ -65,13 +36,13 @@ public class Box : Base, IHasVolume, IHasArea, IHasBoundingBox /// /// This should be one of /// - public string units { get; set; } + public required string units { get; set; } /// public double area { get; set; } /// - public Box bbox { get; } + public Box? bbox { get; } /// public double volume { get; set; } diff --git a/src/Speckle.Objects/Geometry/Brep.cs b/src/Speckle.Objects/Geometry/Brep.cs index f0ca3c0c..17d9c1a6 100644 --- a/src/Speckle.Objects/Geometry/Brep.cs +++ b/src/Speckle.Objects/Geometry/Brep.cs @@ -14,52 +14,19 @@ namespace Speckle.Objects.Geometry; [SpeckleType("Objects.Geometry.Brep")] public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable, IDisplayValue> { - /// - /// Initializes a new instance of class. - /// - public Brep() - { - Surfaces = new List(); - Curve2D = new List(); - Curve3D = new List(); - - Vertices = new List(); - Edges = new List(); - Loops = new List(); - Trims = new List(); - Faces = new List(); - - IsClosed = false; - Orientation = BrepOrientation.None; - } - - public Brep(string provenance, Mesh displayValue, string units = Units.Meters, string? applicationId = null) - : this(provenance, new List { displayValue }, units, applicationId) { } - - public Brep(string provenance, List displayValues, string units = Units.Meters, string? applicationId = null) - : this() - { - this.provenance = provenance; - displayValue = displayValues; - this.applicationId = applicationId; - this.units = units; - } - - public string provenance { get; set; } - /// /// The unit's this object's coordinates are in. /// /// /// This should be one of /// - public string units { get; set; } + public required string units { get; set; } /// /// Gets or sets the list of surfaces in this instance. /// [JsonIgnore] - public List Surfaces { get; set; } + public required List Surfaces { get; set; } /// /// Gets or sets the flat list of numbers representing the 's surfaces. @@ -70,14 +37,10 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< get { var list = new List(); - if (Surfaces != null) + foreach (var srf in Surfaces) { - foreach (var srf in Surfaces) - { - list.AddRange(srf.ToList()); - } + list.AddRange(srf.ToList()); } - return list; } set @@ -106,7 +69,7 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< /// Gets or sets the list of 3-dimensional curves in this instance. /// [JsonIgnore] - public List Curve3D { get; set; } + public required List Curve3D { get; set; } /// /// Gets or sets the flat list of numbers representing the 's 3D curves. @@ -131,7 +94,7 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< /// Gets or sets the list of 2-dimensional UV curves in this instance. /// [JsonIgnore] - public List Curve2D { get; set; } + public required List Curve2D { get; set; } /// /// Gets or sets the flat list of numbers representing the 's 2D curves. @@ -156,7 +119,7 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< /// Gets or sets the list of vertices in this instance. /// [JsonIgnore] - public List Vertices { get; set; } + public required List Vertices { get; set; } /// /// Gets or sets the flat list of numbers representing the 's vertices. @@ -169,7 +132,7 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< { get { - var list = new List(); + var list = new List((Vertices.Count * 3) + 1); list.Add(Units.GetEncodingFromUnit(units)); foreach (var vertex in Vertices) { @@ -183,6 +146,7 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< if (value != null) { var units = value.Count % 3 == 0 ? Units.None : Units.GetUnitFromEncoding(value[0]); + Vertices = new(value.Count / 3); for (int i = value.Count % 3 == 0 ? 0 : 1; i < value.Count; i += 3) { Vertices.Add(new Point(value[i], value[i + 1], value[i + 2], units)); @@ -195,7 +159,7 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< /// Gets or sets the list of edges in this instance. /// [JsonIgnore] - public List Edges { get; set; } + public required List Edges { get; set; } /// /// Gets or sets the flat list of numbers representing the 's edges. @@ -215,8 +179,8 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< ints.Add(e.StartIndex); ints.Add(e.EndIndex); ints.Add(Convert.ToInt32(e.ProxyCurveIsReversed)); - ints.Add(e.Domain.start ?? 0); - ints.Add(e.Domain.end ?? 1); + ints.Add(e.Domain.start); + ints.Add(e.Domain.end); ints.AddRange(e.TrimIndices.Select(Convert.ToDouble).Cast()); return ints.Prepend(ints.Count); }) @@ -242,11 +206,23 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< var domainStart = loopValues[4]; var domainEnd = loopValues[5]; Interval domain = - domainStart.HasValue && domainEnd.HasValue ? new(domainStart.Value, domainEnd.Value) : new(0, 1); + domainStart.HasValue && domainEnd.HasValue + ? new() { start = domainStart.Value, end = domainEnd.Value } + : Interval.UnitInterval; var trimIndices = loopValues.GetRange(6, loopValues.Count - 6).Select(d => Convert.ToInt32(d)).ToArray(); - var edge = new BrepEdge(this, curve3dIndex, trimIndices, startIndex, endIndex, proxyReversed, domain); + var edge = new BrepEdge + { + Brep = this, + Curve3dIndex = curve3dIndex, + TrimIndices = trimIndices, + StartIndex = startIndex, + EndIndex = endIndex, + ProxyCurveIsReversed = proxyReversed, + Domain = domain + }; + Edges.Add(edge); i += n + 1; } @@ -257,7 +233,7 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< /// Gets or sets the list of closed UV loops in this instance. /// [JsonIgnore] - public List Loops { get; set; } + public required List Loops { get; set; } /// /// Gets or sets the flat list of numbers representing the 's loops. @@ -296,7 +272,13 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< var faceIndex = loopValues[0]; var type = (BrepLoopType)loopValues[1]; var trimIndices = loopValues.GetRange(2, loopValues.Count - 2); - var loop = new BrepLoop(this, faceIndex, trimIndices, type); + var loop = new BrepLoop + { + Brep = this, + FaceIndex = faceIndex, + TrimIndices = trimIndices, + Type = type + }; Loops.Add(loop); i += n + 1; } @@ -307,7 +289,7 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< /// Gets or sets the list of UV trim segments for each surface in this instance. /// [JsonIgnore] - public List Trims { get; set; } + public required List Trims { get; set; } /// /// Gets or sets the flat list of numbers representing the 's trims. @@ -320,7 +302,7 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< { get { - List list = new(); + List list = new(Trims.Count * TRIMS_ENCODING_LENGTH); foreach (var trim in Trims) { list.Add(trim.EdgeIndex); @@ -343,11 +325,12 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< return; } - var list = new List(); - for (int i = 0; i < value.Count; i += 9) + var list = new List(value.Count / TRIMS_ENCODING_LENGTH); + for (int i = 0; i < value.Count; i += TRIMS_ENCODING_LENGTH) { var trim = new BrepTrim { + Brep = this, EdgeIndex = value[i], StartIndex = value[i + 1], EndIndex = value[i + 2], @@ -356,7 +339,8 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< CurveIndex = value[i + 5], IsoStatus = value[i + 6], TrimType = (BrepTrimType)value[i + 7], - IsReversed = value[i + 8] == 1 + IsReversed = value[i + 8] == 1, + Domain = Interval.UnitInterval, //TODO: This is a problem, see CXPLA-28 }; list.Add(trim); } @@ -365,11 +349,13 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< } } + private const int TRIMS_ENCODING_LENGTH = 9; + /// /// Gets or sets the list of faces in this instance. /// [JsonIgnore] - public List Faces { get; set; } + public required List Faces { get; set; } /// /// Gets or sets the flat list of numbers representing the 's faces. @@ -394,11 +380,11 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< .ToList(); set { - Faces = new List(); if (value == null || value.Count == 0) { return; } + Faces = new List(); var i = 0; while (i < value.Count) @@ -410,7 +396,14 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< var outerLoopIndex = faceValues[1]; var orientationIsReversed = faceValues[2] == 1; var loopIndices = faceValues.GetRange(3, faceValues.Count - 3); - var face = new BrepFace(this, surfIndex, loopIndices, outerLoopIndex, orientationIsReversed); + var face = new BrepFace + { + Brep = this, + SurfaceIndex = surfIndex, + LoopIndices = loopIndices, + OuterLoopIndex = outerLoopIndex, + OrientationReversed = orientationIsReversed + }; Faces.Add(face); i += n + 1; } @@ -420,22 +413,22 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< /// /// Gets or sets if this instance is closed or not. /// - public bool IsClosed { get; set; } + public required bool IsClosed { get; set; } /// /// Gets or sets the list of surfaces in this instance. /// - public BrepOrientation Orientation { get; set; } + public required BrepOrientation Orientation { get; set; } /// [DetachProperty] - public List displayValue { get; set; } + public required List displayValue { get; set; } /// public double area { get; set; } /// - public Box bbox { get; set; } + public Box? bbox { get; set; } /// public double volume { get; set; } @@ -476,7 +469,7 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< } // transform vertices - var transformedVertices = new List(); + var transformedVertices = new List(Vertices.Count); foreach (var vertex in Vertices) { vertex.TransformTo(transform, out Point transformedVertex); @@ -485,7 +478,6 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< transformed = new Brep { - provenance = provenance, units = units, displayValue = displayValues, Surfaces = surfaces, @@ -504,45 +496,63 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< foreach (var e in Edges) { transformed.Edges.Add( - new BrepEdge( - transformed, - e.Curve3dIndex, - e.TrimIndices, - e.StartIndex, - e.EndIndex, - e.ProxyCurveIsReversed, - e.Domain - ) + new BrepEdge + { + Brep = transformed, + Curve3dIndex = e.Curve3dIndex, + TrimIndices = e.TrimIndices, + StartIndex = e.StartIndex, + EndIndex = e.EndIndex, + ProxyCurveIsReversed = e.ProxyCurveIsReversed, + Domain = e.Domain + } ); } foreach (var l in Loops) { - transformed.Loops.Add(new BrepLoop(transformed, l.FaceIndex, l.TrimIndices, l.Type)); + transformed.Loops.Add( + new BrepLoop + { + Brep = transformed, + FaceIndex = l.FaceIndex, + TrimIndices = l.TrimIndices, + Type = l.Type + } + ); } foreach (var t in Trims) { transformed.Trims.Add( - new BrepTrim( - transformed, - t.EdgeIndex, - t.FaceIndex, - t.LoopIndex, - t.CurveIndex, - t.IsoStatus, - t.TrimType, - t.IsReversed, - t.StartIndex, - t.EndIndex - ) + new BrepTrim + { + Brep = transformed, + EdgeIndex = t.EdgeIndex, + FaceIndex = t.FaceIndex, + LoopIndex = t.LoopIndex, + CurveIndex = t.CurveIndex, + IsoStatus = t.IsoStatus, + TrimType = t.TrimType, + IsReversed = t.IsReversed, + StartIndex = t.StartIndex, + EndIndex = t.EndIndex, + Domain = null!, + } ); } foreach (var f in Faces) { transformed.Faces.Add( - new BrepFace(transformed, f.SurfaceIndex, f.LoopIndices, f.OuterLoopIndex, f.OrientationReversed) + new BrepFace + { + Brep = transformed, + SurfaceIndex = f.SurfaceIndex, + LoopIndices = f.LoopIndices, + OuterLoopIndex = f.OuterLoopIndex, + OrientationReversed = f.OrientationReversed + } ); } @@ -565,21 +575,22 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< for (var i = 0; i < Edges.Count; i++) { var e = Edges[i]; - lock (e) + var existing = e; + lock (existing) { if (e.Brep != null) { -#pragma warning disable CS0728 // Possibly incorrect assignment to local which is the argument to a using or lock statement - e = new BrepEdge( -#pragma warning restore CS0728 // Possibly incorrect assignment to local which is the argument to a using or lock statement - this, - e.Curve3dIndex, - e.TrimIndices, - e.StartIndex, - e.EndIndex, - e.ProxyCurveIsReversed, - e.Domain - ); + e = new BrepEdge + { + Brep = this, + Curve3dIndex = e.Curve3dIndex, + TrimIndices = e.TrimIndices, + StartIndex = e.StartIndex, + EndIndex = e.EndIndex, + ProxyCurveIsReversed = e.ProxyCurveIsReversed, + Domain = e.Domain, + }; + Edges[i] = e; } else @@ -592,13 +603,19 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< for (var i = 0; i < Loops.Count; i++) { var l = Loops[i]; - lock (l) + var existingLoop = l; + lock (existingLoop) { if (l.Brep != null) { -#pragma warning disable CS0728 // Possibly incorrect assignment to local which is the argument to a using or lock statement - l = new BrepLoop(this, l.FaceIndex, l.TrimIndices, l.Type); -#pragma warning restore CS0728 // Possibly incorrect assignment to local which is the argument to a using or lock statement + l = new BrepLoop + { + Brep = this, + FaceIndex = l.FaceIndex, + TrimIndices = l.TrimIndices, + Type = l.Type, + }; + Loops[i] = l; } else @@ -611,24 +628,25 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< for (var i = 0; i < Trims.Count; i++) { var t = Trims[i]; - lock (t) + var existingTrim = t; + lock (existingTrim) { if (t.Brep != null) { -#pragma warning disable CS0728 // Possibly incorrect assignment to local which is the argument to a using or lock statement - t = new BrepTrim( -#pragma warning restore CS0728 // Possibly incorrect assignment to local which is the argument to a using or lock statement - this, - t.EdgeIndex, - t.FaceIndex, - t.LoopIndex, - t.CurveIndex, - t.IsoStatus, - t.TrimType, - t.IsReversed, - t.StartIndex, - t.EndIndex - ); + t = new BrepTrim + { + Brep = this, + EdgeIndex = t.EdgeIndex, + LoopIndex = t.LoopIndex, + CurveIndex = t.CurveIndex, + IsoStatus = t.IsoStatus, + TrimType = t.TrimType, + IsReversed = t.IsReversed, + StartIndex = t.StartIndex, + EndIndex = t.EndIndex, + FaceIndex = t.FaceIndex, + Domain = Interval.UnitInterval, //TODO: This is a problem, see CXPLA-28 + }; Trims[i] = t; } else @@ -641,13 +659,19 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable< for (var i = 0; i < Faces.Count; i++) { var f = Faces[i]; - lock (f) + var existingFace = f; + lock (existingFace) { if (f.Brep != null) { -#pragma warning disable CS0728 // Possibly incorrect assignment to local which is the argument to a using or lock statement - f = new BrepFace(this, f.SurfaceIndex, f.LoopIndices, f.OuterLoopIndex, f.OrientationReversed); -#pragma warning restore CS0728 // Possibly incorrect assignment to local which is the argument to a using or lock statement + f = new BrepFace + { + Brep = this, + SurfaceIndex = f.SurfaceIndex, + LoopIndices = f.LoopIndices, + OuterLoopIndex = f.OuterLoopIndex, + OrientationReversed = f.OrientationReversed + }; Faces[i] = f; } else diff --git a/src/Speckle.Objects/Geometry/BrepEdge.cs b/src/Speckle.Objects/Geometry/BrepEdge.cs index 81caa908..b2009157 100644 --- a/src/Speckle.Objects/Geometry/BrepEdge.cs +++ b/src/Speckle.Objects/Geometry/BrepEdge.cs @@ -10,38 +10,17 @@ namespace Speckle.Objects.Geometry; [SpeckleType("Objects.Geometry.BrepEdge")] public class BrepEdge : Base { - public BrepEdge() { } - - public BrepEdge( - Brep brep, - int curve3dIndex, - int[] trimIndices, - int startIndex, - int endIndex, - bool proxyCurvedIsReversed, - Interval? domain - ) - { - Brep = brep; - Curve3dIndex = curve3dIndex; - TrimIndices = trimIndices; - StartIndex = startIndex; - EndIndex = endIndex; - ProxyCurveIsReversed = proxyCurvedIsReversed; - Domain = domain ?? new(0, 1); - } - [JsonIgnore] - public Brep Brep { get; set; } + public required Brep Brep { get; set; } - public int Curve3dIndex { get; set; } - public int[] TrimIndices { get; set; } - public int StartIndex { get; set; } - public int EndIndex { get; set; } + public required int Curve3dIndex { get; set; } + public required int[] TrimIndices { get; set; } + public required int StartIndex { get; set; } + public required int EndIndex { get; set; } - public bool ProxyCurveIsReversed { get; set; } + public required bool ProxyCurveIsReversed { get; set; } - public Interval Domain { get; set; } = new(0, 1); + public required Interval Domain { get; set; } [JsonIgnore] public Point StartVertex => Brep.Vertices[StartIndex]; diff --git a/src/Speckle.Objects/Geometry/BrepFace.cs b/src/Speckle.Objects/Geometry/BrepFace.cs index 73295a7b..748f65d8 100644 --- a/src/Speckle.Objects/Geometry/BrepFace.cs +++ b/src/Speckle.Objects/Geometry/BrepFace.cs @@ -9,24 +9,13 @@ namespace Speckle.Objects.Geometry; [SpeckleType("Objects.Geometry.BrepFace")] public class BrepFace : Base { - public BrepFace() { } - - public BrepFace(Brep brep, int surfaceIndex, List loopIndices, int outerLoopIndex, bool orientationReversed) - { - Brep = brep; - SurfaceIndex = surfaceIndex; - LoopIndices = loopIndices; - OuterLoopIndex = outerLoopIndex; - OrientationReversed = orientationReversed; - } - [JsonIgnore] - public Brep Brep { get; set; } + public required Brep Brep { get; set; } - public int SurfaceIndex { get; set; } - public List LoopIndices { get; set; } - public int OuterLoopIndex { get; set; } - public bool OrientationReversed { get; set; } + public required int SurfaceIndex { get; set; } + public required List LoopIndices { get; set; } + public required int OuterLoopIndex { get; set; } + public required bool OrientationReversed { get; set; } [JsonIgnore] public BrepLoop OuterLoop => Brep.Loops[OuterLoopIndex]; diff --git a/src/Speckle.Objects/Geometry/BrepLoop.cs b/src/Speckle.Objects/Geometry/BrepLoop.cs index 9fc1e4c6..095e1b7b 100644 --- a/src/Speckle.Objects/Geometry/BrepLoop.cs +++ b/src/Speckle.Objects/Geometry/BrepLoop.cs @@ -9,22 +9,12 @@ namespace Speckle.Objects.Geometry; [SpeckleType("Objects.Geometry.BrepLoop")] public class BrepLoop : Base { - public BrepLoop() { } - - public BrepLoop(Brep brep, int faceIndex, List trimIndices, BrepLoopType type) - { - Brep = brep; - FaceIndex = faceIndex; - TrimIndices = trimIndices; - Type = type; - } - [JsonIgnore] - public Brep Brep { get; set; } + public required Brep Brep { get; set; } - public int FaceIndex { get; set; } - public List TrimIndices { get; set; } - public BrepLoopType Type { get; set; } + public required int FaceIndex { get; set; } + public required List TrimIndices { get; set; } + public required BrepLoopType Type { get; set; } [JsonIgnore] public BrepFace Face => Brep.Faces[FaceIndex]; diff --git a/src/Speckle.Objects/Geometry/BrepTrim.cs b/src/Speckle.Objects/Geometry/BrepTrim.cs index 0542e559..267a7454 100644 --- a/src/Speckle.Objects/Geometry/BrepTrim.cs +++ b/src/Speckle.Objects/Geometry/BrepTrim.cs @@ -10,47 +10,19 @@ namespace Speckle.Objects.Geometry; [SpeckleType("Objects.Geometry.BrepTrim")] public class BrepTrim : Base { - public BrepTrim() { } - - public BrepTrim( - Brep brep, - int edgeIndex, - int faceIndex, - int loopIndex, - int curveIndex, - int isoStatus, - BrepTrimType trimType, - bool reversed, - int startIndex, - int endIndex - ) - { - Brep = brep; - EdgeIndex = edgeIndex; - FaceIndex = faceIndex; - LoopIndex = loopIndex; - CurveIndex = curveIndex; - IsoStatus = isoStatus; - TrimType = trimType; - IsReversed = reversed; - StartIndex = startIndex; - EndIndex = endIndex; - } - [JsonIgnore] - public Brep Brep { get; set; } + public required Brep Brep { get; set; } + public required int EdgeIndex { get; set; } + public required int StartIndex { get; set; } + public required int EndIndex { get; set; } + public required int FaceIndex { get; set; } + public required int LoopIndex { get; set; } + public required int CurveIndex { get; set; } + public required int IsoStatus { get; set; } + public required BrepTrimType TrimType { get; set; } + public required bool IsReversed { get; set; } - public int EdgeIndex { get; set; } - public int StartIndex { get; set; } - public int EndIndex { get; set; } - public int FaceIndex { get; set; } - public int LoopIndex { get; set; } - public int CurveIndex { get; set; } - public int IsoStatus { get; set; } - public BrepTrimType TrimType { get; set; } - public bool IsReversed { get; set; } - - public Interval Domain { get; set; } = new(0, 1); + public required Interval Domain { get; set; } [JsonIgnore] public BrepFace Face => Brep.Faces[FaceIndex]; diff --git a/src/Speckle.Objects/Geometry/Circle.cs b/src/Speckle.Objects/Geometry/Circle.cs index 283f8407..776dd083 100644 --- a/src/Speckle.Objects/Geometry/Circle.cs +++ b/src/Speckle.Objects/Geometry/Circle.cs @@ -7,46 +7,30 @@ namespace Speckle.Objects.Geometry; /// /// Represents a circular curve based on a base and a as radius. /// +/// +/// These circles are expected to be full (untrimmed) circles. +/// For trimmed circles, convert them as s instead +/// [SpeckleType("Objects.Geometry.Circle")] public class Circle : Base, ICurve, IHasArea, IHasBoundingBox { - /// - /// Constructs an empty instance. - /// - public Circle() { } - - /// - /// Constructs a new instance. - /// - /// The plane where the circle lies - /// The radius of the circle - /// The units the circle is modeled in - /// The unique ID of this circle in a specific application - public Circle(Plane plane, double radius, string units = Units.Meters, string? applicationId = null) - { - this.plane = plane; - this.radius = radius; - this.applicationId = applicationId; - this.units = units; - } - /// /// The radius of the circle /// - public double? radius { get; set; } + public required double radius { get; set; } /// /// The the circle lies in. /// - public Plane plane { get; set; } + public required Plane plane { get; set; } /// /// The units this object was modeled in. /// - public string units { get; set; } + public required string units { get; set; } /// - public Interval domain { get; set; } = new(0, 1); + public Interval domain { get; set; } = Interval.UnitInterval; /// public double length { get; set; } @@ -57,7 +41,7 @@ public class Circle : Base, ICurve, IHasArea, IHasBoundingBox public double area { get; set; } /// - public Box bbox { get; set; } + public Box? bbox { get; set; } /// /// Returns the coordinates of this as a list of numbers @@ -67,9 +51,9 @@ public class Circle : Base, ICurve, IHasArea, IHasBoundingBox { var list = new List(); - list.Add(radius ?? 0); - list.Add(domain?.start ?? 0); - list.Add(domain?.end ?? 1); + list.Add(radius); + list.Add(domain.start); + list.Add(domain.end); list.AddRange(plane.ToList()); list.Add(Units.GetEncodingFromUnit(units)); @@ -88,7 +72,7 @@ public class Circle : Base, ICurve, IHasArea, IHasBoundingBox var circle = new Circle { radius = list[2], - domain = new Interval(list[3], list[4]), + domain = new Interval { start = list[3], end = list[4] }, plane = Plane.FromList(list.GetRange(5, 13)), units = Units.GetUnitFromEncoding(list[list.Count - 1]) }; diff --git a/src/Speckle.Objects/Geometry/Curve.cs b/src/Speckle.Objects/Geometry/Curve.cs index 3e597c6b..65564a23 100644 --- a/src/Speckle.Objects/Geometry/Curve.cs +++ b/src/Speckle.Objects/Geometry/Curve.cs @@ -2,7 +2,6 @@ using Speckle.Objects.Other; using Speckle.Objects.Primitive; using Speckle.Sdk; using Speckle.Sdk.Common; -using Speckle.Sdk.Logging; using Speckle.Sdk.Models; namespace Speckle.Objects.Geometry; @@ -10,70 +9,52 @@ namespace Speckle.Objects.Geometry; [SpeckleType("Objects.Geometry.Curve")] public class Curve : Base, ICurve, IHasBoundingBox, IHasArea, ITransformable, IDisplayValue { - /// - /// Constructs an empty instance. - /// - public Curve() { } + public required int degree { get; set; } - /// - /// Constructs a new instance based on displayValue a polyline. - /// - /// The polyline that will be this curve's - /// The units this curve is be modelled in - /// The unique ID of this curve in a specific application - public Curve(Polyline poly, string units = Units.Meters, string? applicationId = null) - { - displayValue = poly; - this.applicationId = applicationId; - this.units = units; - } - - public int degree { get; set; } - - public bool periodic { get; set; } + public required bool periodic { get; set; } /// /// "True" if weights differ, "False" if weights are the same. /// - public bool rational { get; set; } + public required bool rational { get; set; } [DetachProperty, Chunkable(31250)] - public List points { get; set; } + public required List points { get; set; } /// /// Gets or sets the weights for this . Use a default value of 1 for unweighted points. /// [DetachProperty, Chunkable(31250)] - public List weights { get; set; } + public required List weights { get; set; } /// /// Gets or sets the knots for this . Count should be equal to count + + 1. /// [DetachProperty, Chunkable(31250)] - public List knots { get; set; } + public required List knots { get; set; } - public bool closed { get; set; } + public required bool closed { get; set; } /// /// The units this object was specified in. /// - public string units { get; set; } + public required string units { get; set; } /// - public Interval domain { get; set; } = new Interval(0, 1); + public Interval domain { get; set; } = Interval.UnitInterval; /// public double length { get; set; } /// [DetachProperty] - public Polyline displayValue { get; set; } + public required Polyline displayValue { get; set; } /// public double area { get; set; } /// - public Box bbox { get; set; } + public Box? bbox { get; set; } /// public bool TransformTo(Transform transform, out Curve transformed) @@ -99,7 +80,7 @@ public class Curve : Base, ICurve, IHasBoundingBox, IHasArea, ITransformable public static Curve FromList(List list) { - if (list[0] != list.Count - 1) + if ((int)list[0] != list.Count - 1) { - throw new Exception($"Incorrect length. Expected {list[0]}, got {list.Count}."); + throw new ArgumentException($"Incorrect length. Expected {list[0]}, got {list.Count}", nameof(list)); } if (list[1] != CurveTypeEncoding.Curve) { - throw new Exception($"Wrong curve type. Expected {CurveTypeEncoding.Curve}, got {list[1]}."); + throw new ArgumentException($"Wrong curve type. Expected {CurveTypeEncoding.Curve}, got {list[1]}", nameof(list)); } - string units = Units.GetUnitFromEncoding(list[list.Count - 1]); - var curve = new Curve - { - degree = (int)list[2], - periodic = list[3] == 1, - rational = list[4] == 1, - closed = list[5] == 1, - domain = new Interval(list[6], list[7]), - displayValue = new Polyline() { units = units } // this is unique to breps, so we do not create curves with null displayValues - }; - var pointsCount = (int)list[8]; var weightsCount = (int)list[9]; var knotsCount = (int)list[10]; - curve.points = list.GetRange(11, pointsCount); - curve.weights = list.GetRange(11 + pointsCount, weightsCount); - curve.knots = list.GetRange(11 + pointsCount + weightsCount, knotsCount); - curve.units = units; + string units = Units.GetUnitFromEncoding(list[^1]); + var curve = new Curve + { + degree = (int)list[2], + periodic = (int)list[3] == 1, + rational = (int)list[4] == 1, + closed = (int)list[5] == 1, + domain = new Interval { start = list[6], end = list[7] }, + displayValue = new Polyline { value = new(), units = units }, // this is unique to breps, so we do not create curves with null displayValues + points = list.GetRange(11, pointsCount), + weights = list.GetRange(11 + pointsCount, weightsCount), + knots = list.GetRange(11 + pointsCount + weightsCount, knotsCount), + units = units, + }; return curve; } diff --git a/src/Speckle.Objects/Geometry/Ellipse.cs b/src/Speckle.Objects/Geometry/Ellipse.cs index 16e0c340..37d4b394 100644 --- a/src/Speckle.Objects/Geometry/Ellipse.cs +++ b/src/Speckle.Objects/Geometry/Ellipse.cs @@ -7,65 +7,20 @@ namespace Speckle.Objects.Geometry; [SpeckleType("Objects.Geometry.Ellipse")] public class Ellipse : Base, ICurve, IHasArea { - /// - /// Initializes a new instance of the class. - /// This constructor is only intended for serialization/deserialization purposes. - /// Use other constructors to manually create ellipses. - /// - public Ellipse() { } - - /// - /// Initializes a new instance of the class. - /// - /// The plane to draw the ellipse in. - /// First radius of the ellipse. - /// Second radius of the ellipse. - /// Application ID, defaults to null. - public Ellipse(Plane plane, double radius1, double radius2, string units = Units.Meters, string? applicationId = null) - : this(plane, radius1, radius2, new Interval(0, 1), null, units) { } - - /// - /// Initializes a new instance of the class. - /// - /// The plane to draw the ellipse in. - /// First radius of the ellipse. - /// Second radius of the ellipse. - /// The curve's internal parametrization domain. - /// The domain to trim the curve with. Will be null if the ellipse is not trimmed. - /// Application ID, defaults to null. - public Ellipse( - Plane plane, - double radius1, - double radius2, - Interval domain, - Interval? trimDomain, - string units = Units.Meters, - string? applicationId = null - ) - { - this.plane = plane; - firstRadius = radius1; - secondRadius = radius2; - this.domain = domain; - this.trimDomain = trimDomain; - this.applicationId = applicationId; - this.units = units; - } - /// /// Gets or sets the first radius of the . This is usually the major radius. /// - public double? firstRadius { get; set; } + public required double firstRadius { get; set; } /// /// Gets or sets the second radius of the . This is usually the minor radius. /// - public double? secondRadius { get; set; } + public required double secondRadius { get; set; } /// /// Gets or sets the plane to draw this ellipse in. /// - public Plane plane { get; set; } + public required Plane plane { get; set; } /// /// Gets or set the domain interval to trim this with. @@ -73,14 +28,14 @@ public class Ellipse : Base, ICurve, IHasArea public Interval? trimDomain { get; set; } /// - public Box bbox { get; set; } + public Box? bbox { get; set; } - public string units { get; set; } + public required string units { get; set; } /// /// Gets or sets the domain interval for this . /// - public Interval domain { get; set; } = new(0, 0); + public required Interval domain { get; set; } /// public double length { get; set; } @@ -93,10 +48,10 @@ public class Ellipse : Base, ICurve, IHasArea public List ToList() { var list = new List(); - list.Add(firstRadius ?? 0); - list.Add(secondRadius ?? 0); - list.Add(domain?.start ?? 0); - list.Add(domain?.end ?? 0); + list.Add(firstRadius); + list.Add(secondRadius); + list.Add(domain.start); + list.Add(domain.end); list.AddRange(plane.ToList()); @@ -112,7 +67,7 @@ public class Ellipse : Base, ICurve, IHasArea { firstRadius = list[2], secondRadius = list[3], - domain = new Interval(list[4], list[5]), + domain = new Interval { start = list[4], end = list[5] }, plane = Plane.FromList(list.GetRange(6, 13)), units = Units.GetUnitFromEncoding(list[list.Count - 1]) }; diff --git a/src/Speckle.Objects/Geometry/Extrusion.cs b/src/Speckle.Objects/Geometry/Extrusion.cs index 5425ed7c..5dd2c617 100644 --- a/src/Speckle.Objects/Geometry/Extrusion.cs +++ b/src/Speckle.Objects/Geometry/Extrusion.cs @@ -35,6 +35,6 @@ public class Extrusion : Base, IHasVolume, IHasArea, IHasBoundingBox public double area { get; set; } - public Box bbox { get; set; } + public Box? bbox { get; set; } public double volume { get; set; } } diff --git a/src/Speckle.Objects/Geometry/Line.cs b/src/Speckle.Objects/Geometry/Line.cs index 1b62db57..b4b6c8f1 100644 --- a/src/Speckle.Objects/Geometry/Line.cs +++ b/src/Speckle.Objects/Geometry/Line.cs @@ -81,10 +81,10 @@ public class Line : Base, ICurve, IHasBoundingBox, ITransformable public Point start { get; set; } public Point end { get; set; } - public Interval domain { get; set; } = new(0, 1); + public Interval domain { get; set; } = Interval.UnitInterval; public double length { get; set; } - public Box bbox { get; set; } + public Box? bbox { get; set; } public bool TransformTo(Transform transform, out Line transformed) { @@ -96,7 +96,7 @@ public class Line : Base, ICurve, IHasBoundingBox, ITransformable end = transformedEnd, applicationId = applicationId, units = units, - domain = domain is null ? new(0, 1) : new() { start = domain.start, end = domain.end } + domain = domain is null ? Interval.UnitInterval : new() { start = domain.start, end = domain.end } }; return true; } @@ -126,7 +126,10 @@ public class Line : Base, ICurve, IHasBoundingBox, ITransformable var units = Units.GetUnitFromEncoding(list[list.Count - 1]); var startPt = new Point(list[2], list[3], list[4], units); var endPt = new Point(list[5], list[6], list[7], units); - var line = new Line(startPt, endPt, units) { domain = new Interval(list[8], list[9]) }; + var line = new Line(startPt, endPt, units) + { + domain = new Interval { start = list[8], end = list[9] } + }; return line; } } diff --git a/src/Speckle.Objects/Geometry/Mesh.cs b/src/Speckle.Objects/Geometry/Mesh.cs index 26c9cd95..0b12498d 100644 --- a/src/Speckle.Objects/Geometry/Mesh.cs +++ b/src/Speckle.Objects/Geometry/Mesh.cs @@ -79,7 +79,7 @@ public class Mesh : Base, IHasBoundingBox, IHasVolume, IHasArea, ITransformable< public double area { get; set; } /// - public Box bbox { get; set; } + public Box? bbox { get; set; } /// public double volume { get; set; } diff --git a/src/Speckle.Objects/Geometry/Plane.cs b/src/Speckle.Objects/Geometry/Plane.cs index 635ed64b..d270c3ef 100644 --- a/src/Speckle.Objects/Geometry/Plane.cs +++ b/src/Speckle.Objects/Geometry/Plane.cs @@ -10,62 +10,31 @@ namespace Speckle.Objects.Geometry; [SpeckleType("Objects.Geometry.Plane")] public class Plane : Base, ITransformable { - /// - /// Constructs an empty - /// - public Plane() { } - - /// - /// Constructs a new given it's individual values. - /// - /// The point to be used as origin - /// The vector to be used as Z axis - /// The vector to be used as the X axis - /// The vector to be used as the Y axis - /// The units the coordinates are in. - /// The unique ID of this polyline in a specific application - public Plane( - Point origin, - Vector normal, - Vector xDir, - Vector yDir, - string units = Units.Meters, - string? applicationId = null - ) - { - this.origin = origin; - this.normal = normal; - xdir = xDir; - ydir = yDir; - this.applicationId = applicationId; - this.units = units; - } - /// /// The s origin point. /// - public Point origin { get; set; } + public required Point origin { get; set; } /// /// The s Z axis. /// - public Vector normal { get; set; } + public required Vector normal { get; set; } /// /// The s X axis. /// - public Vector xdir { get; set; } + public required Vector xdir { get; set; } /// /// The s Y axis. /// - public Vector ydir { get; set; } + public required Vector ydir { get; set; } /// /// The unit's this is in. /// This should be one of /// - public string units { get; set; } + public required string units { get; set; } /// public bool TransformTo(Transform transform, out Plane transformed) @@ -120,13 +89,15 @@ public class Plane : Base, ITransformable /// A new with the provided values. public static Plane FromList(List list) { - var plane = new Plane(); - var units = Units.GetUnitFromEncoding(list[list.Count - 1]); - plane.origin = new Point(list[0], list[1], list[2], units); - plane.normal = new Vector(list[3], list[4], list[5], units); - plane.xdir = new Vector(list[6], list[7], list[8], units); - plane.ydir = new Vector(list[9], list[10], list[11], units); + var plane = new Plane + { + origin = new Point(list[0], list[1], list[2], units), + normal = new Vector(list[3], list[4], list[5], units), + xdir = new Vector(list[6], list[7], list[8], units), + ydir = new Vector(list[9], list[10], list[11], units), + units = units, + }; return plane; } diff --git a/src/Speckle.Objects/Geometry/Point.cs b/src/Speckle.Objects/Geometry/Point.cs index e310113b..24ea8673 100644 --- a/src/Speckle.Objects/Geometry/Point.cs +++ b/src/Speckle.Objects/Geometry/Point.cs @@ -75,10 +75,7 @@ public class Point : Base, ITransformable /// The units this is in. /// This should be one of the units specified in /// - public string units { get; set; } = Units.None; - - [JsonIgnore, Obsolete("Bounding box no longer applicable to point as of 2.18", true)] - public Box? bbox { get; set; } + public string units { get; set; } /// public bool TransformTo(Transform transform, out Point transformed) @@ -219,11 +216,6 @@ public class Point : Base, ITransformable return Math.Sqrt(Math.Pow(x - point.x, 2) + Math.Pow(y - point.y, 2) + Math.Pow(z - point.z, 2)); } - public static Point Add(Point left, Point right) - { - throw new NotImplementedException(); - } - public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) diff --git a/src/Speckle.Objects/Geometry/Pointcloud.cs b/src/Speckle.Objects/Geometry/Pointcloud.cs index 2b6de5ec..30969db9 100644 --- a/src/Speckle.Objects/Geometry/Pointcloud.cs +++ b/src/Speckle.Objects/Geometry/Pointcloud.cs @@ -54,7 +54,7 @@ public class Pointcloud : Base, IHasBoundingBox, ITransformable public string units { get; set; } /// - public Box bbox { get; set; } + public Box? bbox { get; set; } /// public bool TransformTo(Transform transform, out Pointcloud transformed) diff --git a/src/Speckle.Objects/Geometry/Polycurve.cs b/src/Speckle.Objects/Geometry/Polycurve.cs index 8157ec97..82c63ca6 100644 --- a/src/Speckle.Objects/Geometry/Polycurve.cs +++ b/src/Speckle.Objects/Geometry/Polycurve.cs @@ -11,26 +11,10 @@ namespace Speckle.Objects.Geometry; [SpeckleType("Objects.Geometry.Polycurve")] public class Polycurve : Base, ICurve, IHasArea, IHasBoundingBox, ITransformable { - /// - /// Constructs a new empty instance. - /// - public Polycurve() { } - - /// - /// Constructs a new empty with defined units and unique application ID. - /// - /// The units the Polycurve was modelled in. - /// The unique ID of this polyline in a specific application - public Polycurve(string units = Units.Meters, string? applicationId = null) - { - this.applicationId = applicationId; - this.units = units; - } - /// /// Gets or sets the list of segments that comprise this /// - public List segments { get; set; } = new(); + public required List segments { get; set; } /// /// Gets or sets a Boolean value indicating if the is closed @@ -42,12 +26,12 @@ public class Polycurve : Base, ICurve, IHasArea, IHasBoundingBox, ITransformable /// The unit's this is in. /// This should be one of /// - public string units { get; set; } + public required string units { get; set; } /// /// The internal domain of this curve. /// - public Interval domain { get; set; } = new(0, 1); + public Interval domain { get; set; } = Interval.UnitInterval; /// public double length { get; set; } @@ -56,7 +40,7 @@ public class Polycurve : Base, ICurve, IHasArea, IHasBoundingBox, ITransformable public double area { get; set; } /// - public Box bbox { get; set; } + public Box? bbox { get; set; } /// public bool TransformTo(Transform transform, out ITransformable polycurve) @@ -98,6 +82,7 @@ public class Polycurve : Base, ICurve, IHasArea, IHasBoundingBox, ITransformable Polycurve polycurve = new() { + segments = new(), units = polyline.units, area = polyline.area, domain = polyline.domain, @@ -114,7 +99,7 @@ public class Polycurve : Base, ICurve, IHasArea, IHasBoundingBox, ITransformable } if (polyline.closed) { - var line = new Line(points[points.Count - 1], points[0], polyline.units); + var line = new Line(points[^1], points[0], polyline.units); polycurve.segments.Add(line); } @@ -129,8 +114,8 @@ public class Polycurve : Base, ICurve, IHasArea, IHasBoundingBox, ITransformable { var list = new List(); list.Add(closed ? 1 : 0); - list.Add(domain?.start ?? 0); - list.Add(domain?.end ?? 1); + list.Add(domain.start); + list.Add(domain.end); var crvs = CurveArrayEncodingExtensions.ToArray(segments); list.Add(crvs.Count); @@ -150,16 +135,15 @@ public class Polycurve : Base, ICurve, IHasArea, IHasBoundingBox, ITransformable /// A new with the provided values. public static Polycurve FromList(List list) { - var polycurve = new Polycurve { closed = list[2] == 1, domain = new Interval(list[3], list[4]) }; - var temp = list.GetRange(6, (int)list[5]); - polycurve.segments = CurveArrayEncodingExtensions.FromArray(temp); - polycurve.units = Units.GetUnitFromEncoding(list[list.Count - 1]); + var polycurve = new Polycurve + { + segments = CurveArrayEncodingExtensions.FromArray(temp), + closed = (int)list[2] == 1, + domain = new Interval { start = list[3], end = list[4] }, + units = Units.GetUnitFromEncoding(list[^1]), + }; + return polycurve; } - - public Polycurve ToPolycurve() - { - throw new NotImplementedException(); - } } diff --git a/src/Speckle.Objects/Geometry/Polyline.cs b/src/Speckle.Objects/Geometry/Polyline.cs index 2ab12a92..3f96c9fa 100644 --- a/src/Speckle.Objects/Geometry/Polyline.cs +++ b/src/Speckle.Objects/Geometry/Polyline.cs @@ -1,9 +1,7 @@ -using Speckle.Newtonsoft.Json; using Speckle.Objects.Other; using Speckle.Objects.Primitive; using Speckle.Sdk; using Speckle.Sdk.Common; -using Speckle.Sdk.Logging; using Speckle.Sdk.Models; namespace Speckle.Objects.Geometry; @@ -12,170 +10,29 @@ namespace Speckle.Objects.Geometry; /// A polyline curve, defined by a set of vertices. /// [SpeckleType("Objects.Geometry.Polyline")] -public class Polyline : Base, ICurve, IHasArea, IHasBoundingBox, IConvertible, ITransformable +public class Polyline : Base, ICurve, IHasArea, IHasBoundingBox, ITransformable { - /// - /// Constructs an empty - /// - public Polyline() { } - - /// - /// Constructs a new instance from a flat list of coordinates. - /// - /// The array of 3-dimensional coordinates [x1,y1,z1,x2,y2,... - /// The units the coordinates are in. - /// The unique ID of this polyline in a specific application - [Obsolete("Use list constructor instead", true)] - public Polyline(IEnumerable coordinatesArray, string units = Units.Meters, string? applicationId = null) - : this(coordinatesArray.ToList(), units, applicationId) { } - - /// - /// Constructs a new instance from a flat list of coordinates. - /// - /// The list of 3-dimensional coordinates [x1,y1,z1,x2,y2,... - /// The units the coordinates are in. - /// The unique ID of this polyline in a specific application - public Polyline(List coordinates, string units = Units.Meters, string? applicationId = null) - { - value = coordinates; - this.units = units; - this.applicationId = applicationId; - } - /// /// Gets or sets the raw coordinates that define this polyline. Use GetPoints instead to access this data as instances instead. /// [DetachProperty, Chunkable(31250)] - public List value { get; set; } = new(); + public required List value { get; set; } - /// + /// /// If true, do not add the last point to the value list. Polyline first and last points should be unique. - /// + /// public bool closed { get; set; } /// /// The unit's this is in. /// This should be one of /// - public string units { get; set; } - - /// - /// Gets the list of points representing the vertices of this polyline. - /// - [JsonIgnore, Obsolete("Use " + nameof(GetPoints) + " Instead", true)] - public List points => GetPoints(); - - /// - public object ToType(Type conversionType, IFormatProvider provider) - { - if (conversionType == typeof(Polycurve)) - { - return (Polycurve)this; - } - - throw new InvalidCastException(); - } - - /// - public TypeCode GetTypeCode() - { - throw new NotImplementedException(); - } - - /// - public bool ToBoolean(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - /// - public byte ToByte(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - /// - public char ToChar(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - /// - public DateTime ToDateTime(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - /// - public decimal ToDecimal(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - /// - public double ToDouble(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - /// - public short ToInt16(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - /// - public int ToInt32(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - /// - public long ToInt64(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - /// - public sbyte ToSByte(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - /// - public float ToSingle(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - /// - public string ToString(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - /// - public ushort ToUInt16(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - /// - public uint ToUInt32(IFormatProvider provider) - { - throw new NotImplementedException(); - } - - /// - public ulong ToUInt64(IFormatProvider provider) - { - throw new NotImplementedException(); - } + public required string units { get; set; } /// /// The internal domain of this curve. /// - public Interval domain { get; set; } = new(0, 1); + public Interval domain { get; set; } = Interval.UnitInterval; /// public double length { get; set; } @@ -184,7 +41,7 @@ public class Polyline : Base, ICurve, IHasArea, IHasBoundingBox, IConvertible, I public double area { get; set; } /// - public Box bbox { get; set; } + public Box? bbox { get; set; } /// public bool TransformTo(Transform transform, out ITransformable transformed) @@ -253,13 +110,15 @@ public class Polyline : Base, ICurve, IHasArea, IHasBoundingBox, IConvertible, I /// /// The list of values representing this polyline /// A new with the provided values. - public static Polyline FromList(List list) { - var polyline = new Polyline { closed = list[2] == 1, domain = new Interval(list[3], list[4]) }; - var pointCount = (int)list[5]; - polyline.value = list.GetRange(6, pointCount); - polyline.units = Units.GetUnitFromEncoding(list[list.Count - 1]); - return polyline; + int pointCount = (int)list[5]; + return new() + { + closed = (int)list[2] == 1, + domain = new Interval { start = list[3], end = list[4] }, + value = list.GetRange(6, pointCount), + units = Units.GetUnitFromEncoding(list[^1]) + }; } } diff --git a/src/Speckle.Objects/Geometry/Spiral.cs b/src/Speckle.Objects/Geometry/Spiral.cs index a918858a..35d9d944 100644 --- a/src/Speckle.Objects/Geometry/Spiral.cs +++ b/src/Speckle.Objects/Geometry/Spiral.cs @@ -37,5 +37,5 @@ public class Spiral : Base, ICurve, IHasBoundingBox, IDisplayValue [DetachProperty] public Polyline displayValue { get; set; } - public Box bbox { get; set; } + public Box? bbox { get; set; } } diff --git a/src/Speckle.Objects/Geometry/Surface.cs b/src/Speckle.Objects/Geometry/Surface.cs index 71f05f3f..896b7988 100644 --- a/src/Speckle.Objects/Geometry/Surface.cs +++ b/src/Speckle.Objects/Geometry/Surface.cs @@ -101,7 +101,7 @@ public class Surface : Base, IHasBoundingBox, IHasArea, ITransformable public double area { get; set; } /// - public Box bbox { get; set; } + public Box? bbox { get; set; } /// public bool TransformTo(Transform transform, out Surface transformed) @@ -203,10 +203,10 @@ public class Surface : Base, IHasBoundingBox, IHasArea, ITransformable list.Add(rational ? 1 : 0); list.Add(closedU ? 1 : 0); list.Add(closedV ? 1 : 0); - list.Add(domainU.start ?? 0); // 7 - list.Add(domainU.end ?? 1); - list.Add(domainV.start ?? 0); - list.Add(domainV.end ?? 1); // [0] 10 + list.Add(domainU.start); // 7 + list.Add(domainU.end); + list.Add(domainV.start); + list.Add(domainV.end); // [0] 10 list.Add(pointData.Count); // 11 list.Add(knotsU.Count); // 12 diff --git a/src/Speckle.Objects/Geometry/Vector.cs b/src/Speckle.Objects/Geometry/Vector.cs index 9f352d9f..a63e5fb9 100644 --- a/src/Speckle.Objects/Geometry/Vector.cs +++ b/src/Speckle.Objects/Geometry/Vector.cs @@ -104,7 +104,7 @@ public class Vector : Base, IHasBoundingBox, ITransformable public double Length => Math.Sqrt(DotProduct(this, this)); /// - public Box bbox { get; set; } + public Box? bbox { get; set; } /// public bool TransformTo(Transform transform, out Vector transformed) diff --git a/src/Speckle.Objects/Interfaces.cs b/src/Speckle.Objects/Interfaces.cs index 994845c9..d3167dd4 100644 --- a/src/Speckle.Objects/Interfaces.cs +++ b/src/Speckle.Objects/Interfaces.cs @@ -16,7 +16,7 @@ public interface IHasBoundingBox /// /// The bounding box containing the object. /// - Box bbox { get; } + Box? bbox { get; } } /// diff --git a/src/Speckle.Objects/Other/Instance.cs b/src/Speckle.Objects/Other/Instance.cs index 3bd03201..42503914 100644 --- a/src/Speckle.Objects/Other/Instance.cs +++ b/src/Speckle.Objects/Other/Instance.cs @@ -149,13 +149,14 @@ public class BlockInstance : Instance public Plane GetInsertionPlane() { // TODO: UPDATE! - var plane = new Plane( - typedDefinition.basePoint ?? new Point(0, 0, 0, units), - new Vector(0, 0, 1, units), - new Vector(1, 0, 0, units), - new Vector(0, 1, 0, units), - units - ); + var plane = new Plane() + { + origin = typedDefinition.basePoint ?? new Point(0, 0, 0, units), + normal = new Vector(0, 0, 1, units), + xdir = new Vector(1, 0, 0, units), + ydir = new Vector(0, 1, 0, units), + units = units + }; plane.TransformTo(transform, out Plane tPlane); return tPlane; } diff --git a/src/Speckle.Objects/Other/Revit/RevitInstance.cs b/src/Speckle.Objects/Other/Revit/RevitInstance.cs index d4eabcf7..d9dd67c7 100644 --- a/src/Speckle.Objects/Other/Revit/RevitInstance.cs +++ b/src/Speckle.Objects/Other/Revit/RevitInstance.cs @@ -56,13 +56,14 @@ public class RevitInstance : Instance public Plane GetInsertionPlane() { // TODO: Check for Revit in GH/DYN - var plane = new Plane( - new Point(0, 0, 0, units), - new Vector(0, 0, 1, units), - new Vector(1, 0, 0, units), - new Vector(0, 1, 0, units), - units - ); + var plane = new Plane() + { + origin = new Point(0, 0, 0, units), + normal = new Vector(0, 0, 1, units), + xdir = new Vector(1, 0, 0, units), + ydir = new Vector(0, 1, 0, units), + units = units, + }; plane.TransformTo(transform, out Plane tPlane); return tPlane; } diff --git a/src/Speckle.Objects/Primitive/Interval.cs b/src/Speckle.Objects/Primitive/Interval.cs index b1d03016..0ffcfc79 100644 --- a/src/Speckle.Objects/Primitive/Interval.cs +++ b/src/Speckle.Objects/Primitive/Interval.cs @@ -6,22 +6,16 @@ namespace Speckle.Objects.Primitive; [SpeckleType("Objects.Primitive.Interval")] public class Interval : Base { - public Interval() { } - - public Interval(double start, double end) - { - this.start = start; - this.end = end; - } - - public double? start { get; set; } - public double? end { get; set; } + public required double start { get; set; } + public required double end { get; set; } [JsonIgnore] - public double Length => Math.Abs((end ?? 0) - (start ?? 0)); + public double Length => Math.Abs((end) - (start)); public override string ToString() { return base.ToString() + $"[{start}, {end}]"; } + + public static Interval UnitInterval => new() { start = 0, end = 1 }; } diff --git a/src/Speckle.Objects/Primitive/Interval2d.cs b/src/Speckle.Objects/Primitive/Interval2d.cs index 528f4a99..8254e08e 100644 --- a/src/Speckle.Objects/Primitive/Interval2d.cs +++ b/src/Speckle.Objects/Primitive/Interval2d.cs @@ -15,8 +15,8 @@ public class Interval2d : Base public Interval2d(double start_u, double end_u, double start_v, double end_v) { - u = new Interval(start_u, end_u); - v = new Interval(start_v, end_v); + u = new Interval { start = start_u, end = end_u }; + v = new Interval { start = start_v, end = end_v }; } public Interval u { get; set; } diff --git a/src/Speckle.Objects/Structural/CSI/Geometry/CSINode.cs b/src/Speckle.Objects/Structural/CSI/Geometry/CSINode.cs index 43657985..0476938f 100644 --- a/src/Speckle.Objects/Structural/CSI/Geometry/CSINode.cs +++ b/src/Speckle.Objects/Structural/CSI/Geometry/CSINode.cs @@ -3,6 +3,7 @@ using Speckle.Objects.Structural.CSI.Properties; using Speckle.Objects.Structural.Geometry; using Speckle.Objects.Structural.Properties; using Speckle.Objects.Structural.Results; +using Speckle.Sdk.Common; using Speckle.Sdk.Host; using Speckle.Sdk.Models; @@ -40,7 +41,14 @@ public class CSINode : Node ?? new Axis( "Global", AxisType.Cartesian, - new Plane(new Point(0, 0), new Vector(0, 0, 1), new Vector(1, 0, 0), new Vector(0, 1, 0)) + new Plane + { + origin = new Point(0, 0), + normal = new Vector(0, 0, 1), + xdir = new Vector(1, 0, 0), + ydir = new Vector(0, 1, 0), + units = Units.Meters, //Not sure if defaulting to meters is correct, but it was what we were doing previously inside Plane's ctor + } ); CSISpringProperty = springProperty; this.massProperty = massProperty; diff --git a/src/Speckle.Objects/Structural/GSA/Geometry/GSANode.cs b/src/Speckle.Objects/Structural/GSA/Geometry/GSANode.cs index fe71cc29..37a9b7bc 100644 --- a/src/Speckle.Objects/Structural/GSA/Geometry/GSANode.cs +++ b/src/Speckle.Objects/Structural/GSA/Geometry/GSANode.cs @@ -1,6 +1,7 @@ using Speckle.Objects.Geometry; using Speckle.Objects.Structural.Geometry; using Speckle.Objects.Structural.Properties; +using Speckle.Sdk.Common; using Speckle.Sdk.Host; using Speckle.Sdk.Models; @@ -42,7 +43,14 @@ public class GSANode : Node ? new Axis( "Global", AxisType.Cartesian, - new Plane(new Point(0, 0), new Vector(0, 0, 1), new Vector(1, 0, 0), new Vector(0, 1, 0)) + new Plane() + { + origin = new Point(0, 0), + normal = new Vector(0, 0, 1), + xdir = new Vector(1, 0, 0), + ydir = new Vector(0, 1, 0), + units = Units.Meters //Not sure if defaulting to meters is correct, but it was what we were doing previously inside Plane's ctor + } ) : constraintAxis; this.springProperty = springProperty; diff --git a/src/Speckle.Objects/Structural/Geometry/Node.cs b/src/Speckle.Objects/Structural/Geometry/Node.cs index 0ba5559a..359b4dc6 100644 --- a/src/Speckle.Objects/Structural/Geometry/Node.cs +++ b/src/Speckle.Objects/Structural/Geometry/Node.cs @@ -43,7 +43,14 @@ public class Node : Base ?? new Axis( "Global", AxisType.Cartesian, - new Plane(new Point(0, 0), new Vector(0, 0, 1), new Vector(1, 0, 0), new Vector(0, 1, 0)) + new Plane + { + origin = new Point(0, 0), + normal = new Vector(0, 0, 1), + xdir = new Vector(1, 0, 0), + ydir = new Vector(0, 1, 0), + units = Units.Meters, //Not sure if defaulting to meters is correct, but it was what we were doing previously inside Plane's ctor + } ); this.springProperty = springProperty; this.massProperty = massProperty; diff --git a/tests/Speckle.Objects.Tests.Unit/Geometry/ArcTests.cs b/tests/Speckle.Objects.Tests.Unit/Geometry/ArcTests.cs index f7839178..e7a2cffc 100644 --- a/tests/Speckle.Objects.Tests.Unit/Geometry/ArcTests.cs +++ b/tests/Speckle.Objects.Tests.Unit/Geometry/ArcTests.cs @@ -1,13 +1,22 @@ using System; using NUnit.Framework; using Speckle.Objects.Geometry; +using Speckle.Sdk.Common; namespace Objects.Tests.Unit.Geometry; [TestFixture, TestOf(typeof(Arc))] public class ArcTests { - private Plane TestPlane => new(new Point(0, 0), new Vector(0, 0, 1), new Vector(1, 0, 0), new Vector(0, 1, 0)); + private Plane TestPlane => + new() + { + origin = new Point(0, 0), + normal = new Vector(0, 0, 1), + xdir = new Vector(1, 0, 0), + ydir = new Vector(0, 1, 0), + units = Units.Meters, + }; [Test] public void CanCreateArc_HalfCircle() diff --git a/tests/Speckle.Sdk.Tests.Unit/Serialisation/SerializerNonBreakingChanges.cs b/tests/Speckle.Sdk.Tests.Unit/Serialisation/SerializerNonBreakingChanges.cs index 4e9481b7..a0247f45 100644 --- a/tests/Speckle.Sdk.Tests.Unit/Serialisation/SerializerNonBreakingChanges.cs +++ b/tests/Speckle.Sdk.Tests.Unit/Serialisation/SerializerNonBreakingChanges.cs @@ -56,6 +56,24 @@ public class SerializerNonBreakingChanges : PrimitiveTestFixture Assert.That(res.value, Is.EqualTo(testCase)); } + [Test] + public void NullToInt() + { + var from = new ObjectValueMock { value = null }; + + var res = from.SerializeAsTAndDeserialize(); + Assert.That(res.value, Is.EqualTo(default(int))); + } + + [Test] + public void NullToDouble() + { + var from = new ObjectValueMock { value = null }; + + var res = from.SerializeAsTAndDeserialize(); + Assert.That(res.value, Is.EqualTo(default(double))); + } + [ Test, TestCaseSource(nameof(Int8TestCases)), @@ -277,6 +295,12 @@ public class EnumValueMock : SerializerMock public MyEnum value { get; set; } } +[SpeckleType("Speckle.Core.Tests.Unit.Serialisation.ObjectValueMock")] +public class ObjectValueMock : SerializerMock +{ + public object? value { get; set; } +} + public enum MyEnum { Zero,