Skip to content

Commit d2da595

Browse files
committed
few improvements to Object3D.AddChild method
1 parent 62b4242 commit d2da595

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/CodeCave.Threejs.Entities.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
<IsPackable>true</IsPackable>
1313
<IncludeSymbols>true</IncludeSymbols>
1414
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
15-
<Version>0.7.4</Version>
16-
<FileVersion>0.7.4</FileVersion>
17-
<AssemblyVersion>0.7.4</AssemblyVersion>
15+
<Version>0.8.2</Version>
16+
<FileVersion>0.8.2</FileVersion>
17+
<AssemblyVersion>0.8.2</AssemblyVersion>
1818
<RepositoryType>git</RepositoryType>
1919
<PackageProjectUrl>https://github.com/CodeCavePro/threejs-entities.git</PackageProjectUrl>
2020
<RepositoryUrl>https://github.com/CodeCavePro/threejs-entities.git</RepositoryUrl>
@@ -23,7 +23,7 @@
2323

2424
<ItemGroup>
2525
<PackageReference Include="JsonSubTypes" Version="1.8.*" />
26-
<PackageReference Include="Newtonsoft.Json" Version="[10.0.1, 12.1)" />
26+
<PackageReference Include="Newtonsoft.Json" Version="[10.0.1, 13.1)" />
2727
<PackageReference Include="System.Text.Json" Version="3.1.*" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
2828
<PackageReference Include="System.Text.Json" Version="5.0.*" Condition="'$(TargetFramework)' == 'net5.0'" />
2929
<PackageReference Include="System.Text.Json" Version="6.0.*" Condition="'$(TargetFramework)' == 'net6.0'" />

src/Objects/Object3D.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ namespace CodeCave.Threejs.Entities
1919
[JsonSubtypes.KnownSubType(typeof(Scene), nameof(Scene))]
2020
[JsonSubtypes.KnownSubType(typeof(Group), nameof(Group))]
2121
[System.Text.Json.Serialization.JsonConverter(typeof(Utf8Json.PolymorphicJsonConverter<Object3D>))]
22-
public class Object3D : IEquatable<Object3D>, IEqualityComparer<Object3D>
22+
public class Object3D : IEquatable<Object3D>
2323
{
24-
private List<Object3D> children;
24+
private HashSet<Object3D> children;
2525
private double[] matrix;
2626
private Vector3 position = new Vector3(0, 0, 0);
2727

@@ -34,7 +34,7 @@ public class Object3D : IEquatable<Object3D>, IEqualityComparer<Object3D>
3434
[System.Text.Json.Serialization.JsonConstructor]
3535
public Object3D(string type = nameof(Object3D), string uuid = null, long? id = null)
3636
{
37-
children = new List<Object3D>();
37+
children = new HashSet<Object3D>();
3838

3939
Id = id;
4040
UserData = new Dictionary<string, string>();
@@ -129,7 +129,7 @@ public double[] Matrix
129129
public IReadOnlyCollection<Object3D> Children
130130
{
131131
get => children as IReadOnlyCollection<Object3D>;
132-
private set => children = new List<Object3D>(value);
132+
private set => children = new HashSet<Object3D>(value);
133133
}
134134

135135
/// <summary>
@@ -268,7 +268,7 @@ public bool HasChild(Object3D childObject)
268268
/// <returns>Optimized object.</returns>
269269
public Object3D Optimize()
270270
{
271-
children = new List<Object3D>(
271+
children = new HashSet<Object3D>(
272272
children
273273
.Flatten()
274274
.Where(c => !c.IsInvisible));
@@ -277,7 +277,7 @@ public Object3D Optimize()
277277

278278
public Object3D CleanUp()
279279
{
280-
children = new List<Object3D>(
280+
children = new HashSet<Object3D>(
281281
children
282282
.Select(c => c.CleanUp())
283283
.Where(c => !c.IsInvisible));
@@ -295,6 +295,7 @@ public Object3D CleanUp()
295295
/// <returns>true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.</returns>
296296
public bool Equals(Object3D other) =>
297297
Uuid.Equals(other?.Uuid, StringComparison.OrdinalIgnoreCase) &&
298+
Position.Equals(other?.Position) &&
298299
GetHashCode().Equals(other?.GetHashCode());
299300

300301
/// <summary>Returns a hash code for this instance.</summary>
@@ -305,18 +306,16 @@ public override int GetHashCode()
305306
hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(Uuid);
306307
hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(GeometryUuid);
307308
hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(MaterialUuid);
308-
hashCode = (hashCode * -1521134295) + EqualityComparer<List<Object3D>>.Default.GetHashCode(children);
309+
hashCode = (hashCode * -1521134295) + EqualityComparer<Vector3>.Default.GetHashCode(Position);
310+
hashCode = (hashCode * -1521134295) + EqualityComparer<HashSet<Object3D>>.Default.GetHashCode(children);
309311
return hashCode;
310312
}
311313

312314
/// <summary>Determines whether the specified objects are equal.</summary>
313315
/// <param name="x">The first <see cref="Object3D" /> object to compare.</param>
314316
/// <param name="y">The second <see cref="Object3D" /> object to compare.</param>
315317
/// <returns>true if the specified objects are equal; otherwise, false.</returns>
316-
public bool Equals(Object3D x, Object3D y)
317-
{
318-
return x?.Equals(y) ?? false;
319-
}
318+
public static bool Equals(Object3D x, Object3D y) => x?.Equals(y) ?? false;
320319

321320
/// <summary>Returns a hash code for this instance.</summary>
322321
/// <param name="obj">The object.</param>

0 commit comments

Comments
 (0)