Skip to content

Commit 9175ae2

Browse files
authored
Merge pull request #58 from vimaec/mavimaec/v1.3.7.1
Mavimaec/v1.3.7.1
2 parents 9f8bbf3 + a14eb77 commit 9175ae2

16 files changed

Lines changed: 1454 additions & 11 deletions

File tree

docs/object-model-schema.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"VimFormatVersion": "1.0.0",
3-
"SchemaVersion": "5.6.0",
3+
"SchemaVersion": "5.7.0",
44
"Tables": {
55
"Vim.Area": [
66
"byte:IsGrossInterior",
@@ -33,7 +33,12 @@
3333
"index:Vim.ViewSheet:ViewSheet"
3434
],
3535
"Vim.BasePoint": [
36+
"byte:IsClipped",
3637
"byte:IsSurveyPoint",
38+
"double:AngleToTrueNorth",
39+
"double:EastWest",
40+
"double:Elevation",
41+
"double:NorthSouth",
3742
"double:Position.X",
3843
"double:Position.Y",
3944
"double:Position.Z",
@@ -147,8 +152,11 @@
147152
"index:Vim.View:OwnerView",
148153
"index:Vim.Workset:Workset",
149154
"long:Id",
155+
"string:Creator",
150156
"string:FamilyName",
157+
"string:LastChangedBy",
151158
"string:Name",
159+
"string:Owner",
152160
"string:Type",
153161
"string:UniqueId"
154162
],

docs/schema-diff.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,17 @@
165165
"Added": [
166166
"Vim.BimDocument__long:FileLength"
167167
]
168+
},
169+
"5.6.0 to 5.7.0": {
170+
"Added": [
171+
"Vim.BasePoint__byte:IsClipped",
172+
"Vim.BasePoint__double:AngleToTrueNorth",
173+
"Vim.BasePoint__double:EastWest",
174+
"Vim.BasePoint__double:Elevation",
175+
"Vim.BasePoint__double:NorthSouth",
176+
"Vim.Element__string:Creator",
177+
"Vim.Element__string:LastChangedBy",
178+
"Vim.Element__string:Owner"
179+
]
168180
}
169181
}

src/cpp/vim/object-model.h

Lines changed: 303 additions & 0 deletions
Large diffs are not rendered by default.

src/cs/math3d/Vim.Math3D/DMatrix4x4.cs

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,5 +638,173 @@ public Matrix4x4 ToMatrix4x4()
638638
(float) M31, (float) M32, (float) M33, (float) M34,
639639
(float) M41, (float) M42, (float) M43, (float) M44);
640640
}
641+
642+
/// <summary>
643+
/// Attempts to calculate the inverse of the given matrix. If successful, result will contain the inverted matrix.
644+
/// </summary>
645+
/// <param name="matrix">The source matrix to invert.</param>
646+
/// <param name="result">If successful, contains the inverted matrix.</param>
647+
/// <returns>True if the source matrix could be inverted; False otherwise.</returns>
648+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
649+
public static bool Invert(DMatrix4x4 matrix, out DMatrix4x4 result)
650+
{
651+
// -1
652+
// If you have matrix M, inverse Matrix M can compute
653+
//
654+
// -1 1
655+
// M = --------- A
656+
// det(M)
657+
//
658+
// A is adjugate (adjoint) of M, where,
659+
//
660+
// T
661+
// A = C
662+
//
663+
// C is Cofactor matrix of M, where,
664+
// i + j
665+
// C = (-1) * det(M )
666+
// ij ij
667+
//
668+
// [ a b c d ]
669+
// M = [ e f g h ]
670+
// [ i j k l ]
671+
// [ m n o p ]
672+
//
673+
// First Row
674+
// 2 | f g h |
675+
// C = (-1) | j k l | = + ( f ( kp - lo ) - g ( jp - ln ) + h ( jo - kn ) )
676+
// 11 | n o p |
677+
//
678+
// 3 | e g h |
679+
// C = (-1) | i k l | = - ( e ( kp - lo ) - g ( ip - lm ) + h ( io - km ) )
680+
// 12 | m o p |
681+
//
682+
// 4 | e f h |
683+
// C = (-1) | i j l | = + ( e ( jp - ln ) - f ( ip - lm ) + h ( in - jm ) )
684+
// 13 | m n p |
685+
//
686+
// 5 | e f g |
687+
// C = (-1) | i j k | = - ( e ( jo - kn ) - f ( io - km ) + g ( in - jm ) )
688+
// 14 | m n o |
689+
//
690+
// Second Row
691+
// 3 | b c d |
692+
// C = (-1) | j k l | = - ( b ( kp - lo ) - c ( jp - ln ) + d ( jo - kn ) )
693+
// 21 | n o p |
694+
//
695+
// 4 | a c d |
696+
// C = (-1) | i k l | = + ( a ( kp - lo ) - c ( ip - lm ) + d ( io - km ) )
697+
// 22 | m o p |
698+
//
699+
// 5 | a b d |
700+
// C = (-1) | i j l | = - ( a ( jp - ln ) - b ( ip - lm ) + d ( in - jm ) )
701+
// 23 | m n p |
702+
//
703+
// 6 | a b c |
704+
// C = (-1) | i j k | = + ( a ( jo - kn ) - b ( io - km ) + c ( in - jm ) )
705+
// 24 | m n o |
706+
//
707+
// Third Row
708+
// 4 | b c d |
709+
// C = (-1) | f g h | = + ( b ( gp - ho ) - c ( fp - hn ) + d ( fo - gn ) )
710+
// 31 | n o p |
711+
//
712+
// 5 | a c d |
713+
// C = (-1) | e g h | = - ( a ( gp - ho ) - c ( ep - hm ) + d ( eo - gm ) )
714+
// 32 | m o p |
715+
//
716+
// 6 | a b d |
717+
// C = (-1) | e f h | = + ( a ( fp - hn ) - b ( ep - hm ) + d ( en - fm ) )
718+
// 33 | m n p |
719+
//
720+
// 7 | a b c |
721+
// C = (-1) | e f g | = - ( a ( fo - gn ) - b ( eo - gm ) + c ( en - fm ) )
722+
// 34 | m n o |
723+
//
724+
// Fourth Row
725+
// 5 | b c d |
726+
// C = (-1) | f g h | = - ( b ( gl - hk ) - c ( fl - hj ) + d ( fk - gj ) )
727+
// 41 | j k l |
728+
//
729+
// 6 | a c d |
730+
// C = (-1) | e g h | = + ( a ( gl - hk ) - c ( el - hi ) + d ( ek - gi ) )
731+
// 42 | i k l |
732+
//
733+
// 7 | a b d |
734+
// C = (-1) | e f h | = - ( a ( fl - hj ) - b ( el - hi ) + d ( ej - fi ) )
735+
// 43 | i j l |
736+
//
737+
// 8 | a b c |
738+
// C = (-1) | e f g | = + ( a ( fk - gj ) - b ( ek - gi ) + c ( ej - fi ) )
739+
// 44 | i j k |
740+
//
741+
// Cost of operation
742+
// 53 adds, 104 muls, and 1 div.
743+
double a = matrix.M11, b = matrix.M12, c = matrix.M13, d = matrix.M14;
744+
double e = matrix.M21, f = matrix.M22, g = matrix.M23, h = matrix.M24;
745+
double i = matrix.M31, j = matrix.M32, k = matrix.M33, l = matrix.M34;
746+
double m = matrix.M41, n = matrix.M42, o = matrix.M43, p = matrix.M44;
747+
748+
var kp_lo = k * p - l * o;
749+
var jp_ln = j * p - l * n;
750+
var jo_kn = j * o - k * n;
751+
var ip_lm = i * p - l * m;
752+
var io_km = i * o - k * m;
753+
var in_jm = i * n - j * m;
754+
755+
var a11 = +(f * kp_lo - g * jp_ln + h * jo_kn);
756+
var a12 = -(e * kp_lo - g * ip_lm + h * io_km);
757+
var a13 = +(e * jp_ln - f * ip_lm + h * in_jm);
758+
var a14 = -(e * jo_kn - f * io_km + g * in_jm);
759+
760+
var det = a * a11 + b * a12 + c * a13 + d * a14;
761+
762+
if (det.Abs() < float.Epsilon)
763+
{
764+
result = new DMatrix4x4(float.NaN, float.NaN, float.NaN, float.NaN,
765+
float.NaN, float.NaN, float.NaN, float.NaN,
766+
float.NaN, float.NaN, float.NaN, float.NaN,
767+
float.NaN, float.NaN, float.NaN, float.NaN);
768+
return false;
769+
}
770+
771+
var invDet = 1.0f / det;
772+
773+
result.M11 = a11 * invDet;
774+
result.M21 = a12 * invDet;
775+
result.M31 = a13 * invDet;
776+
result.M41 = a14 * invDet;
777+
778+
result.M12 = -(b * kp_lo - c * jp_ln + d * jo_kn) * invDet;
779+
result.M22 = +(a * kp_lo - c * ip_lm + d * io_km) * invDet;
780+
result.M32 = -(a * jp_ln - b * ip_lm + d * in_jm) * invDet;
781+
result.M42 = +(a * jo_kn - b * io_km + c * in_jm) * invDet;
782+
783+
var gp_ho = g * p - h * o;
784+
var fp_hn = f * p - h * n;
785+
var fo_gn = f * o - g * n;
786+
var ep_hm = e * p - h * m;
787+
var eo_gm = e * o - g * m;
788+
var en_fm = e * n - f * m;
789+
790+
result.M13 = +(b * gp_ho - c * fp_hn + d * fo_gn) * invDet;
791+
result.M23 = -(a * gp_ho - c * ep_hm + d * eo_gm) * invDet;
792+
result.M33 = +(a * fp_hn - b * ep_hm + d * en_fm) * invDet;
793+
result.M43 = -(a * fo_gn - b * eo_gm + c * en_fm) * invDet;
794+
795+
var gl_hk = g * l - h * k;
796+
var fl_hj = f * l - h * j;
797+
var fk_gj = f * k - g * j;
798+
var el_hi = e * l - h * i;
799+
var ek_gi = e * k - g * i;
800+
var ej_fi = e * j - f * i;
801+
802+
result.M14 = -(b * gl_hk - c * fl_hj + d * fk_gj) * invDet;
803+
result.M24 = +(a * gl_hk - c * el_hi + d * ek_gi) * invDet;
804+
result.M34 = -(a * fl_hj - b * el_hi + d * ej_fi) * invDet;
805+
result.M44 = +(a * fk_gj - b * ek_gi + c * ej_fi) * invDet;
806+
807+
return true;
808+
}
641809
}
642810
}

src/cs/math3d/Vim.Math3D/MathOps.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public static partial class MathOps
6969
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Distance(this double v1, double v2) => (v1 - v2).Abs();
7070
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsInfinity(this double v) => double.IsInfinity(v);
7171
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsNaN(this double v) => double.IsNaN(v);
72-
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AlmostEquals(this double v1, double v2, float tolerance = Constants.Tolerance) => (v2 - v1).AlmostZero(tolerance);
73-
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AlmostZero(this double v, float tolerance = Constants.Tolerance) => v.Abs() < tolerance;
72+
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AlmostEquals(this double v1, double v2, double tolerance = Constants.Tolerance) => (v2 - v1).AlmostZero(tolerance);
73+
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AlmostZero(this double v, double tolerance = Constants.Tolerance) => v.Abs() < tolerance;
7474
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Smoothstep(this double v) => v * v * (3 - 2 * v);
7575

7676
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Add (this int v1, int v2) => v1 + v2;

src/cs/math3d/Vim.Math3D/MathOps.tt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ foreach (var t in floatTypes) {
6262
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static <#= t #> Distance(this <#= t #> v1, <#= t #> v2) => (v1 - v2).Abs();
6363
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsInfinity(this <#= t #> v) => <#= t #>.IsInfinity(v);
6464
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsNaN(this <#= t #> v) => <#= t #>.IsNaN(v);
65-
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AlmostEquals(this <#= t #> v1, <#= t #> v2, float tolerance = Constants.Tolerance) => (v2 - v1).AlmostZero(tolerance);
66-
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AlmostZero(this <#= t #> v, float tolerance = Constants.Tolerance) => v.Abs() < tolerance;
65+
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AlmostEquals(this <#= t #> v1, <#= t #> v2, <#= t #> tolerance = Constants.Tolerance) => (v2 - v1).AlmostZero(tolerance);
66+
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AlmostZero(this <#= t #> v, <#= t #> tolerance = Constants.Tolerance) => v.Abs() < tolerance;
6767
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static <#= t #> Smoothstep(this <#= t #> v) => v * v * (3 - 2 * v);
6868
<# } #>
6969

src/cs/math3d/Vim.Math3D/MathOpsPartial.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,24 @@ public static Matrix4x4 ToMatrix(this Quaternion self)
568568
=> Matrix4x4.CreateRotation(self);
569569

570570
/// <summary>
571-
/// Returns a matri for translation and then rotation.
571+
/// Returns a matrix for translation and then rotation.
572572
/// </summary>
573573
[MethodImpl(MethodImplOptions.AggressiveInlining)]
574574
public static Matrix4x4 ToMatrix(this Transform self)
575575
=> Matrix4x4.CreateTRS(self.Position, self.Orientation, Vector3.One);
576+
577+
/// <summary>
578+
/// Casts the doubles in a DVector3 to create a Vector3
579+
/// </summary>
580+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
581+
public static Vector3 ToVector3(this DVector3 self)
582+
=> new Vector3((float) self.X, (float) self.Y, (float) self.Z);
583+
584+
/// <summary>
585+
/// Returns a DVector3 based on the given Vector3.
586+
/// </summary>
587+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
588+
public static DVector3 ToDVector3(this Vector3 self)
589+
=> new DVector3(self.X, self.Y, self.Z);
576590
}
577591
}

src/cs/math3d/Vim.Math3D/Structs.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ public readonly partial struct Vector3
129129
[MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector3(float value) : this(value, value, value) { }
130130
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector3 operator -(Vector3 value) => Zero - value;
131131
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Dot(Vector3 value1, Vector3 value2) => value1.X * value2.X + value1.Y * value2.Y + value1.Z * value2.Z;
132-
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector3 Cross(Vector3 v1, Vector3 v2) => new Vector3(v1.Y * v2.Z - v1.Z * v2.Y, v1.Z * v2.X - v1.X * v2.Z, v1.X * v2.Y - v1.Y * v2.X);
133132
[MethodImpl(MethodImplOptions.AggressiveInlining)] public float Dot(Vector3 value) => Vector3.Dot(this, value);
134133
[MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AlmostZero(float tolerance = Constants.Tolerance) => X.Abs() < tolerance && Y.Abs() < tolerance && Z.Abs() < tolerance;
135134
[MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyComponentNegative() => MinComponent() < 0;

src/cs/math3d/Vim.Math3D/StructsPartial.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ public Vector3 Cross(Vector3 vector2)
7878
Z * vector2.X - X * vector2.Z,
7979
X * vector2.Y - Y * vector2.X);
8080

81+
/// <summary>
82+
/// Computes the cross product of two vectors.
83+
/// </summary>
84+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
85+
public static Vector3 Cross(Vector3 v1, Vector3 v2)
86+
=> v1.Cross(v2);
87+
8188
/// <summary>
8289
/// Returns the mixed product
8390
/// </summary>

src/cs/vim/Vim.Format.Core/EntityTable_v2.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,20 @@ private static T GetColumnOrDefault<T>(Dictionary<string, T> map, string key, T
6464
/// Returns the index column based on the given column name.
6565
/// </summary>
6666
public int[] GetIndexColumnValues(string columnName)
67-
=> GetColumnOrDefault(IndexColumns, columnName)?.GetColumnValues<int>();
67+
=> GetColumnOrDefault(IndexColumns, columnName)?.GetColumnValues<int>() ?? Array.Empty<int>();
68+
69+
/// <summary>
70+
/// Returns the integer string indices column based on the given column name.
71+
/// </summary>
72+
public int[] GetStringIndices(string columnName)
73+
=> GetColumnOrDefault(StringColumns, columnName)?.GetColumnValues<int>() ?? Array.Empty<int>();
6874

6975
/// <summary>
7076
/// Returns the string column based on the given column name.
7177
/// </summary>
7278
public string[] GetStringColumnValues(string columnName)
7379
{
74-
var stringIndices = GetColumnOrDefault(StringColumns, columnName)
75-
?.GetColumnValues<int>() ?? Array.Empty<int>();
80+
var stringIndices = GetStringIndices(columnName);
7681

7782
var strings = new string[stringIndices.Length];
7883

0 commit comments

Comments
 (0)