Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jedd/cxpla 55 add required keyword for more geometry types #101

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bbd2cd5
Sdk
JR-Morgan Aug 28, 2024
ac0cbef
Objects
JR-Morgan Aug 28, 2024
db8556a
Merge branch 'dev' into jedd/cxpla-21-sdk-repo-sort-our-warnings-anal…
JR-Morgan Aug 28, 2024
a70c9a0
Supressed IDE warnings via editor config instead of nowarn
JR-Morgan Aug 28, 2024
d7ec74a
Nullability and other warnings
JR-Morgan Sep 2, 2024
ac59f9e
using
JR-Morgan Sep 2, 2024
b33b44d
Required keyword on lines and meshes
JR-Morgan Sep 3, 2024
4173c1a
Merge branch 'dev' into jrm/requiredv2
JR-Morgan Sep 4, 2024
a6960a2
Fixed test project
JR-Morgan Sep 4, 2024
5a0eca5
fixed tests
JR-Morgan Sep 4, 2024
cd33c4b
Proxies
JR-Morgan Sep 4, 2024
521ea79
Merge remote-tracking branch 'origin/dev' into jedd/cxpla-55-add-requ…
JR-Morgan Sep 6, 2024
4e3ee4b
Fixed equality of Point
JR-Morgan Sep 9, 2024
fa2bf91
IEquatable
JR-Morgan Sep 9, 2024
11df5c9
Fixed issue with serialization of detached lists
JR-Morgan Sep 9, 2024
fde459f
Added tests for jsonIgnore affecting id calc
JR-Morgan Sep 9, 2024
6c18217
Merge branch 'dev' into jedd/cxpla-55-add-required-keyword-for-more-g…
JR-Morgan Sep 10, 2024
808cdc4
Merge remote-tracking branch 'origin/dev' into jedd/cxpla-55-add-requ…
JR-Morgan Sep 10, 2024
6cad565
Merge remote-tracking branch 'origin/jedd/cxpla-55-add-required-keywo…
JR-Morgan Sep 10, 2024
57f0f24
removed comments
JR-Morgan Sep 10, 2024
7853669
Fixed issue with fallback to double on large values
JR-Morgan Sep 10, 2024
dc3e42c
Fixed undocumented large number support
JR-Morgan Sep 10, 2024
a9ba6a8
Merge remote-tracking branch 'origin/dev' into jedd/cxpla-55-add-requ…
JR-Morgan Sep 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions src/Speckle.Objects/BuiltElements/Revit/RevitTopography.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
using Speckle.Objects.Geometry;
using Speckle.Objects.Utils;
using Speckle.Sdk.Host;
using Speckle.Sdk.Models;

namespace Speckle.Objects.BuiltElements.Revit;

[SpeckleType("Objects.BuiltElements.Revit.RevitTopography")]
public class RevitTopography : Topography
{
public RevitTopography() { }

[SchemaInfo("RevitTopography", "Creates a Revit topography", "Revit", "Architecture")]
public RevitTopography([SchemaMainParam] Mesh displayMesh, List<Parameter>? parameters = null)
{
displayValue = new List<Mesh> { displayMesh };
this.parameters = parameters?.ToBase();
}

public string elementId { get; set; }
public string? elementId { get; set; }
public Base? parameters { get; set; }
}
20 changes: 3 additions & 17 deletions src/Speckle.Objects/BuiltElements/Topography.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
using Speckle.Objects.Geometry;
using Speckle.Sdk.Host;
using Speckle.Sdk.Models;

namespace Speckle.Objects.BuiltElements;

[SpeckleType("Objects.BuiltElements.Topography")]
public class Topography : Base, IDisplayValue<List<Mesh>>
{
public Topography()
{
displayValue = new List<Mesh>();
}

[SchemaInfo("Topography", "Creates a Speckle topography", "BIM", "Architecture")]
public Topography([SchemaMainParam] Mesh displayMesh)
{
displayValue = new List<Mesh> { displayMesh };
}

public Mesh baseGeometry { get; set; } = new();

public string units { get; set; }
public required Mesh baseGeometry { get; set; }
public required string units { get; set; }

[DetachProperty]
public List<Mesh> displayValue { get; set; }
//TODO Figure out if we should add a new constructor that takes a List<Mesh> or if Topography should just have a single mesh display value
public required List<Mesh> displayValue { get; set; }
}
18 changes: 9 additions & 9 deletions src/Speckle.Objects/Geometry/Arc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public Arc(
new Plane
{
origin = startPoint,
normal = new Vector(0, 0, 1),
xdir = new Vector(1, 0, 0),
ydir = new Vector(0, 1, 0),
normal = new Vector(0, 0, 1, units),
xdir = new Vector(1, 0, 0, units),
ydir = new Vector(0, 1, 0, units),
units = units
},
startPoint,
Expand Down Expand Up @@ -138,17 +138,17 @@ public Arc(

// find the chord vector then calculate the perpendicular vector which points to the centre
// which can be used to find the circle centre point
var dir = chordAngle < 0 ? -1 : 1;
var centreToChord = Math.Sqrt(Math.Pow((double)radius, 2) - Math.Pow(chordLength * 0.5, 2));
var perp = Vector.CrossProduct(new Vector(endPoint - startPoint), plane.normal);
var circleCentre = chordMidpoint + new Point(perp.Unit() * centreToChord * -dir);
int dir = chordAngle < 0 ? -1 : 1;
double centreToChord = Math.Sqrt(Math.Pow((double)radius, 2) - Math.Pow(chordLength * 0.5, 2));
Vector perp = Vector.CrossProduct((endPoint - startPoint).ToVector(), plane.normal);
Point circleCentre = chordMidpoint + (perp.Unit() * centreToChord * -dir).ToPoint();
plane.origin = circleCentre;

// use the perpendicular vector in the other direction (from the centre to the arc) to find the arc midpoint
midPoint =
angleRadians > Math.PI
? chordMidpoint + new Point(perp.Unit() * ((double)radius + centreToChord) * -dir)
: chordMidpoint + new Point(perp.Unit() * ((double)radius - centreToChord) * dir);
? chordMidpoint + (perp.Unit() * ((double)radius + centreToChord) * -dir).ToPoint()
: chordMidpoint + (perp.Unit() * ((double)radius - centreToChord) * dir).ToPoint();

// find the start angle using trig (correcting for quadrant position) and add the arc angle to get the end angle
startAngle = Math.Tan((startPoint.y - circleCentre.y) / (startPoint.x - circleCentre.x)) % (2 * Math.PI);
Expand Down
12 changes: 4 additions & 8 deletions src/Speckle.Objects/Geometry/ControlPoint.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Speckle.Newtonsoft.Json;
using Speckle.Objects.Other;
using Speckle.Sdk.Models;
Expand All @@ -9,18 +10,15 @@ public class ControlPoint : Point, ITransformable<ControlPoint>
{
public ControlPoint() { }

public ControlPoint(double x, double y, double z, string units, string? applicationId = null)
: base(x, y, z, units, applicationId)
{
weight = 1;
}

[SetsRequiredMembers]
public ControlPoint(double x, double y, double z, double w, string units, string? applicationId = null)
: base(x, y, z, units, applicationId)
{
weight = w;
}

public required double weight { get; set; }

/// <summary>
/// OBSOLETE - This is just here for backwards compatibility.
/// </summary>
Expand All @@ -42,8 +40,6 @@ public ControlPoint(double x, double y, double z, double w, string units, string
}
}

public double weight { get; set; }

public bool TransformTo(Transform transform, out ControlPoint transformed)
{
TransformTo(transform, out Point transformedPoint);
Expand Down
101 changes: 42 additions & 59 deletions src/Speckle.Objects/Geometry/Line.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Speckle.Newtonsoft.Json;
using Speckle.Objects.Other;
using Speckle.Objects.Primitive;
using Speckle.Sdk;
using Speckle.Sdk.Common;
using Speckle.Sdk.Models;

Expand All @@ -12,76 +12,33 @@ public class Line : Base, ICurve, IHasBoundingBox, ITransformable<Line>
{
public Line() { }

[Obsolete("Line should not use a constructor that only sets the start point. Deprecated in 2.18.", true)]
public Line(double x, double y, double z = 0, string units = Units.Meters, string? applicationId = null)
{
start = new Point(x, y, z);
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. Reason: Obsolete.
end = null;
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. Reason: Obsolete.
this.applicationId = applicationId;
this.units = units;
}

public Line(Point start, Point end, string units = Units.Meters, string? applicationId = null)
{
this.start = start;
this.end = end;
length = Point.Distance(start, end);
this.applicationId = applicationId;
this.units = units;
}

public Line(IList<double> coordinates, string units = Units.Meters, string? applicationId = null)
/// <param name="coordinates"></param>
/// <param name="units"></param>
/// <param name="applicationId"></param>
/// <exception cref="ArgumentException"><paramref name="coordinates"/> must have a length of 6</exception>
[SetsRequiredMembers]
public Line(IList<double> coordinates, string units, string? applicationId = null)
{
if (coordinates.Count < 6)
{
throw new SpeckleException("Line from coordinate array requires 6 coordinates.");
throw new ArgumentException("Line from coordinate array requires 6 coordinates.", nameof(coordinates));
}

start = new Point(coordinates[0], coordinates[1], coordinates[2], units, applicationId);
end = new Point(coordinates[3], coordinates[4], coordinates[5], units, applicationId);
length = Point.Distance(start, end);
this.applicationId = applicationId;
this.units = units;
}

[Obsolete("Use IList constructor", true)]
public Line(IEnumerable<double> coordinatesArray, string units = Units.Meters, string? applicationId = null)
: this(coordinatesArray.ToList(), units, applicationId) { }

/// <summary>
/// OBSOLETE - This is just here for backwards compatibility.
/// You should not use this for anything. Access coordinates using start and end point.
/// </summary>

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public List<double> value
{
#pragma warning disable CS8603 // Possible null reference return. Reason: Obsolete.
get => null;
#pragma warning restore CS8603 // Possible null reference return. Reason: Obsolete.
set
{
if (value == null)
{
return;
}

start = new Point(value[0], value[1], value[2]);
end = new Point(value[3], value[4], value[5]);
}
this.applicationId = applicationId;
}

public double area { get; set; }

public string units { get; set; }
public required string units { get; set; }

public Point start { get; set; }
public Point end { get; set; }
public required Point start { get; set; }
public required Point end { get; set; }

public Interval domain { get; set; } = Interval.UnitInterval;
public double length { get; set; }
public double length => Point.Distance(start, end);

public Box? bbox { get; set; }

Expand All @@ -95,7 +52,7 @@ public bool TransformTo(Transform transform, out Line transformed)
end = transformedEnd,
applicationId = applicationId,
units = units,
domain = domain is null ? Interval.UnitInterval : new() { start = domain.start, end = domain.end }
domain = new() { start = domain.start, end = domain.end }
};
return true;
}
Expand Down Expand Up @@ -125,10 +82,36 @@ public static Line FromList(IReadOnlyList<double> list)
var units = Units.GetUnitFromEncoding(list[^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)
var line = new Line
{
domain = new Interval { start = list[8], end = list[9] }
start = startPt,
end = endPt,
units = units,
domain = new Interval { start = list[8], end = list[9] },
};
return line;
}

/// <summary>
/// OBSOLETE - This is just here for backwards compatibility.
/// You should not use this for anything. Access coordinates using start and end point.
/// </summary>
[
JsonProperty(NullValueHandling = NullValueHandling.Ignore),
Obsolete("Access coordinates using start and end point", true)
]
public List<double>? value
{
get => null;
set
{
if (value == null)
{
return;
}

start = new Point(value[0], value[1], value[2], Units.Meters);
end = new Point(value[3], value[4], value[5], Units.Meters);
}
}
}
52 changes: 3 additions & 49 deletions src/Speckle.Objects/Geometry/Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,11 @@ namespace Speckle.Objects.Geometry;
[SpeckleType("Objects.Geometry.Mesh")]
public class Mesh : Base, IHasBoundingBox, IHasVolume, IHasArea, ITransformable<Mesh>
{
public Mesh() { }

/// <summary>
/// Constructs a new mesh from it's raw values.
/// </summary>
/// <param name="vertices"></param>
/// <param name="faces"></param>
/// <param name="colors"></param>
/// <param name="texture_coords"></param>
/// <param name="units"></param>
/// <param name="applicationId"></param>
public Mesh(
List<double> vertices,
List<int> faces,
List<int>? colors = null,
List<double>? texture_coords = null,
string units = Units.Meters,
string? applicationId = null
)
{
this.vertices = vertices;
this.faces = faces;
this.colors = colors ?? this.colors;
textureCoordinates = texture_coords ?? textureCoordinates;
this.applicationId = applicationId;
this.units = units;
}

[Obsolete("Use lists constructor", true)]
public Mesh(
double[] vertices,
int[] faces,
int[]? colors = null,
double[]? texture_coords = null,
string units = Units.Meters,
string? applicationId = null
)
: this(
vertices.ToList(),
faces.ToList(),
colors?.ToList() ?? new(),
texture_coords?.ToList() ?? new(),
units,
applicationId
) { }

[DetachProperty, Chunkable(31250)]
public List<double> vertices { get; set; } = new();
public required List<double> vertices { get; set; }

[DetachProperty, Chunkable(62500)]
public List<int> faces { get; set; } = new();
public required List<int> faces { get; set; }

/// <summary> Vertex colors as ARGB <see cref="int"/>s</summary>
[DetachProperty, Chunkable(62500)]
Expand All @@ -72,7 +26,7 @@ public Mesh(
/// The unit's this <see cref="Mesh"/> is in.
/// This should be one of <see cref="Units"/>
/// </summary>
public string units { get; set; } = Units.None;
public required string units { get; set; }

/// <inheritdoc/>
public double area { get; set; }
Expand Down
Loading
Loading