@@ -19,9 +19,9 @@ namespace CodeCave.Threejs.Entities
19
19
[ JsonSubtypes . KnownSubType ( typeof ( Scene ) , nameof ( Scene ) ) ]
20
20
[ JsonSubtypes . KnownSubType ( typeof ( Group ) , nameof ( Group ) ) ]
21
21
[ System . Text . Json . Serialization . JsonConverter ( typeof ( Utf8Json . PolymorphicJsonConverter < Object3D > ) ) ]
22
- public class Object3D : IEquatable < Object3D > , IEqualityComparer < Object3D >
22
+ public class Object3D : IEquatable < Object3D >
23
23
{
24
- private List < Object3D > children ;
24
+ private HashSet < Object3D > children ;
25
25
private double [ ] matrix ;
26
26
private Vector3 position = new Vector3 ( 0 , 0 , 0 ) ;
27
27
@@ -34,7 +34,7 @@ public class Object3D : IEquatable<Object3D>, IEqualityComparer<Object3D>
34
34
[ System . Text . Json . Serialization . JsonConstructor ]
35
35
public Object3D ( string type = nameof ( Object3D ) , string uuid = null , long ? id = null )
36
36
{
37
- children = new List < Object3D > ( ) ;
37
+ children = new HashSet < Object3D > ( ) ;
38
38
39
39
Id = id ;
40
40
UserData = new Dictionary < string , string > ( ) ;
@@ -129,7 +129,7 @@ public double[] Matrix
129
129
public IReadOnlyCollection < Object3D > Children
130
130
{
131
131
get => children as IReadOnlyCollection < Object3D > ;
132
- private set => children = new List < Object3D > ( value ) ;
132
+ private set => children = new HashSet < Object3D > ( value ) ;
133
133
}
134
134
135
135
/// <summary>
@@ -268,7 +268,7 @@ public bool HasChild(Object3D childObject)
268
268
/// <returns>Optimized object.</returns>
269
269
public Object3D Optimize ( )
270
270
{
271
- children = new List < Object3D > (
271
+ children = new HashSet < Object3D > (
272
272
children
273
273
. Flatten ( )
274
274
. Where ( c => ! c . IsInvisible ) ) ;
@@ -277,7 +277,7 @@ public Object3D Optimize()
277
277
278
278
public Object3D CleanUp ( )
279
279
{
280
- children = new List < Object3D > (
280
+ children = new HashSet < Object3D > (
281
281
children
282
282
. Select ( c => c . CleanUp ( ) )
283
283
. Where ( c => ! c . IsInvisible ) ) ;
@@ -295,6 +295,7 @@ public Object3D CleanUp()
295
295
/// <returns>true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.</returns>
296
296
public bool Equals ( Object3D other ) =>
297
297
Uuid . Equals ( other ? . Uuid , StringComparison . OrdinalIgnoreCase ) &&
298
+ Position . Equals ( other ? . Position ) &&
298
299
GetHashCode ( ) . Equals ( other ? . GetHashCode ( ) ) ;
299
300
300
301
/// <summary>Returns a hash code for this instance.</summary>
@@ -305,18 +306,16 @@ public override int GetHashCode()
305
306
hashCode = ( hashCode * - 1521134295 ) + EqualityComparer < string > . Default . GetHashCode ( Uuid ) ;
306
307
hashCode = ( hashCode * - 1521134295 ) + EqualityComparer < string > . Default . GetHashCode ( GeometryUuid ) ;
307
308
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 ) ;
309
311
return hashCode ;
310
312
}
311
313
312
314
/// <summary>Determines whether the specified objects are equal.</summary>
313
315
/// <param name="x">The first <see cref="Object3D" /> object to compare.</param>
314
316
/// <param name="y">The second <see cref="Object3D" /> object to compare.</param>
315
317
/// <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 ;
320
319
321
320
/// <summary>Returns a hash code for this instance.</summary>
322
321
/// <param name="obj">The object.</param>
0 commit comments