Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 9 additions & 1 deletion docs/object-model-schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"VimFormatVersion": "1.0.0",
"SchemaVersion": "5.6.0",
"SchemaVersion": "5.7.0",
"Tables": {
"Vim.Area": [
"byte:IsGrossInterior",
Expand Down Expand Up @@ -33,7 +33,12 @@
"index:Vim.ViewSheet:ViewSheet"
],
"Vim.BasePoint": [
"byte:IsClipped",
"byte:IsSurveyPoint",
"double:AngleToTrueNorth",
"double:EastWest",
"double:Elevation",
"double:NorthSouth",
"double:Position.X",
"double:Position.Y",
"double:Position.Z",
Expand Down Expand Up @@ -147,8 +152,11 @@
"index:Vim.View:OwnerView",
"index:Vim.Workset:Workset",
"long:Id",
"string:Creator",
"string:FamilyName",
"string:LastChangedBy",
"string:Name",
"string:Owner",
"string:Type",
"string:UniqueId"
],
Expand Down
12 changes: 12 additions & 0 deletions docs/schema-diff.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,17 @@
"Added": [
"Vim.BimDocument__long:FileLength"
]
},
"5.6.0 to 5.7.0": {
"Added": [
"Vim.BasePoint__byte:IsClipped",
"Vim.BasePoint__double:AngleToTrueNorth",
"Vim.BasePoint__double:EastWest",
"Vim.BasePoint__double:Elevation",
"Vim.BasePoint__double:NorthSouth",
"Vim.Element__string:Creator",
"Vim.Element__string:LastChangedBy",
"Vim.Element__string:Owner"
]
}
}
303 changes: 303 additions & 0 deletions src/cpp/vim/object-model.h

Large diffs are not rendered by default.

168 changes: 168 additions & 0 deletions src/cs/math3d/Vim.Math3D/DMatrix4x4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -638,5 +638,173 @@ public Matrix4x4 ToMatrix4x4()
(float) M31, (float) M32, (float) M33, (float) M34,
(float) M41, (float) M42, (float) M43, (float) M44);
}

/// <summary>
/// Attempts to calculate the inverse of the given matrix. If successful, result will contain the inverted matrix.
/// </summary>
/// <param name="matrix">The source matrix to invert.</param>
/// <param name="result">If successful, contains the inverted matrix.</param>
/// <returns>True if the source matrix could be inverted; False otherwise.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Invert(DMatrix4x4 matrix, out DMatrix4x4 result)
{
// -1
// If you have matrix M, inverse Matrix M can compute
//
// -1 1
// M = --------- A
// det(M)
//
// A is adjugate (adjoint) of M, where,
//
// T
// A = C
//
// C is Cofactor matrix of M, where,
// i + j
// C = (-1) * det(M )
// ij ij
//
// [ a b c d ]
// M = [ e f g h ]
// [ i j k l ]
// [ m n o p ]
//
// First Row
// 2 | f g h |
// C = (-1) | j k l | = + ( f ( kp - lo ) - g ( jp - ln ) + h ( jo - kn ) )
// 11 | n o p |
//
// 3 | e g h |
// C = (-1) | i k l | = - ( e ( kp - lo ) - g ( ip - lm ) + h ( io - km ) )
// 12 | m o p |
//
// 4 | e f h |
// C = (-1) | i j l | = + ( e ( jp - ln ) - f ( ip - lm ) + h ( in - jm ) )
// 13 | m n p |
//
// 5 | e f g |
// C = (-1) | i j k | = - ( e ( jo - kn ) - f ( io - km ) + g ( in - jm ) )
// 14 | m n o |
//
// Second Row
// 3 | b c d |
// C = (-1) | j k l | = - ( b ( kp - lo ) - c ( jp - ln ) + d ( jo - kn ) )
// 21 | n o p |
//
// 4 | a c d |
// C = (-1) | i k l | = + ( a ( kp - lo ) - c ( ip - lm ) + d ( io - km ) )
// 22 | m o p |
//
// 5 | a b d |
// C = (-1) | i j l | = - ( a ( jp - ln ) - b ( ip - lm ) + d ( in - jm ) )
// 23 | m n p |
//
// 6 | a b c |
// C = (-1) | i j k | = + ( a ( jo - kn ) - b ( io - km ) + c ( in - jm ) )
// 24 | m n o |
//
// Third Row
// 4 | b c d |
// C = (-1) | f g h | = + ( b ( gp - ho ) - c ( fp - hn ) + d ( fo - gn ) )
// 31 | n o p |
//
// 5 | a c d |
// C = (-1) | e g h | = - ( a ( gp - ho ) - c ( ep - hm ) + d ( eo - gm ) )
// 32 | m o p |
//
// 6 | a b d |
// C = (-1) | e f h | = + ( a ( fp - hn ) - b ( ep - hm ) + d ( en - fm ) )
// 33 | m n p |
//
// 7 | a b c |
// C = (-1) | e f g | = - ( a ( fo - gn ) - b ( eo - gm ) + c ( en - fm ) )
// 34 | m n o |
//
// Fourth Row
// 5 | b c d |
// C = (-1) | f g h | = - ( b ( gl - hk ) - c ( fl - hj ) + d ( fk - gj ) )
// 41 | j k l |
//
// 6 | a c d |
// C = (-1) | e g h | = + ( a ( gl - hk ) - c ( el - hi ) + d ( ek - gi ) )
// 42 | i k l |
//
// 7 | a b d |
// C = (-1) | e f h | = - ( a ( fl - hj ) - b ( el - hi ) + d ( ej - fi ) )
// 43 | i j l |
//
// 8 | a b c |
// C = (-1) | e f g | = + ( a ( fk - gj ) - b ( ek - gi ) + c ( ej - fi ) )
// 44 | i j k |
//
// Cost of operation
// 53 adds, 104 muls, and 1 div.
double a = matrix.M11, b = matrix.M12, c = matrix.M13, d = matrix.M14;
double e = matrix.M21, f = matrix.M22, g = matrix.M23, h = matrix.M24;
double i = matrix.M31, j = matrix.M32, k = matrix.M33, l = matrix.M34;
double m = matrix.M41, n = matrix.M42, o = matrix.M43, p = matrix.M44;

var kp_lo = k * p - l * o;
var jp_ln = j * p - l * n;
var jo_kn = j * o - k * n;
var ip_lm = i * p - l * m;
var io_km = i * o - k * m;
var in_jm = i * n - j * m;

var a11 = +(f * kp_lo - g * jp_ln + h * jo_kn);
var a12 = -(e * kp_lo - g * ip_lm + h * io_km);
var a13 = +(e * jp_ln - f * ip_lm + h * in_jm);
var a14 = -(e * jo_kn - f * io_km + g * in_jm);

var det = a * a11 + b * a12 + c * a13 + d * a14;

if (det.Abs() < float.Epsilon)
{
result = new DMatrix4x4(float.NaN, float.NaN, float.NaN, float.NaN,
float.NaN, float.NaN, float.NaN, float.NaN,
float.NaN, float.NaN, float.NaN, float.NaN,
float.NaN, float.NaN, float.NaN, float.NaN);
return false;
}

var invDet = 1.0f / det;

result.M11 = a11 * invDet;
result.M21 = a12 * invDet;
result.M31 = a13 * invDet;
result.M41 = a14 * invDet;

result.M12 = -(b * kp_lo - c * jp_ln + d * jo_kn) * invDet;
result.M22 = +(a * kp_lo - c * ip_lm + d * io_km) * invDet;
result.M32 = -(a * jp_ln - b * ip_lm + d * in_jm) * invDet;
result.M42 = +(a * jo_kn - b * io_km + c * in_jm) * invDet;

var gp_ho = g * p - h * o;
var fp_hn = f * p - h * n;
var fo_gn = f * o - g * n;
var ep_hm = e * p - h * m;
var eo_gm = e * o - g * m;
var en_fm = e * n - f * m;

result.M13 = +(b * gp_ho - c * fp_hn + d * fo_gn) * invDet;
result.M23 = -(a * gp_ho - c * ep_hm + d * eo_gm) * invDet;
result.M33 = +(a * fp_hn - b * ep_hm + d * en_fm) * invDet;
result.M43 = -(a * fo_gn - b * eo_gm + c * en_fm) * invDet;

var gl_hk = g * l - h * k;
var fl_hj = f * l - h * j;
var fk_gj = f * k - g * j;
var el_hi = e * l - h * i;
var ek_gi = e * k - g * i;
var ej_fi = e * j - f * i;

result.M14 = -(b * gl_hk - c * fl_hj + d * fk_gj) * invDet;
result.M24 = +(a * gl_hk - c * el_hi + d * ek_gi) * invDet;
result.M34 = -(a * fl_hj - b * el_hi + d * ej_fi) * invDet;
result.M44 = +(a * fk_gj - b * ek_gi + c * ej_fi) * invDet;

return true;
}
}
}
4 changes: 2 additions & 2 deletions src/cs/math3d/Vim.Math3D/MathOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public static partial class MathOps
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Distance(this double v1, double v2) => (v1 - v2).Abs();
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsInfinity(this double v) => double.IsInfinity(v);
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsNaN(this double v) => double.IsNaN(v);
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AlmostEquals(this double v1, double v2, float tolerance = Constants.Tolerance) => (v2 - v1).AlmostZero(tolerance);
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AlmostZero(this double v, float tolerance = Constants.Tolerance) => v.Abs() < tolerance;
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AlmostEquals(this double v1, double v2, double tolerance = Constants.Tolerance) => (v2 - v1).AlmostZero(tolerance);
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AlmostZero(this double v, double tolerance = Constants.Tolerance) => v.Abs() < tolerance;
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Smoothstep(this double v) => v * v * (3 - 2 * v);

[MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Add (this int v1, int v2) => v1 + v2;
Expand Down
4 changes: 2 additions & 2 deletions src/cs/math3d/Vim.Math3D/MathOps.tt
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ foreach (var t in floatTypes) {
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static <#= t #> Distance(this <#= t #> v1, <#= t #> v2) => (v1 - v2).Abs();
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsInfinity(this <#= t #> v) => <#= t #>.IsInfinity(v);
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsNaN(this <#= t #> v) => <#= t #>.IsNaN(v);
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AlmostEquals(this <#= t #> v1, <#= t #> v2, float tolerance = Constants.Tolerance) => (v2 - v1).AlmostZero(tolerance);
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AlmostZero(this <#= t #> v, float tolerance = Constants.Tolerance) => v.Abs() < tolerance;
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AlmostEquals(this <#= t #> v1, <#= t #> v2, <#= t #> tolerance = Constants.Tolerance) => (v2 - v1).AlmostZero(tolerance);
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool AlmostZero(this <#= t #> v, <#= t #> tolerance = Constants.Tolerance) => v.Abs() < tolerance;
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static <#= t #> Smoothstep(this <#= t #> v) => v * v * (3 - 2 * v);
<# } #>

Expand Down
16 changes: 15 additions & 1 deletion src/cs/math3d/Vim.Math3D/MathOpsPartial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,24 @@ public static Matrix4x4 ToMatrix(this Quaternion self)
=> Matrix4x4.CreateRotation(self);

/// <summary>
/// Returns a matri for translation and then rotation.
/// Returns a matrix for translation and then rotation.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix4x4 ToMatrix(this Transform self)
=> Matrix4x4.CreateTRS(self.Position, self.Orientation, Vector3.One);

/// <summary>
/// Casts the doubles in a DVector3 to create a Vector3
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3 ToVector3(this DVector3 self)
=> new Vector3((float) self.X, (float) self.Y, (float) self.Z);

/// <summary>
/// Returns a DVector3 based on the given Vector3.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static DVector3 ToDVector3(this Vector3 self)
=> new DVector3(self.X, self.Y, self.Z);
}
}
1 change: 0 additions & 1 deletion src/cs/math3d/Vim.Math3D/Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ public readonly partial struct Vector3
[MethodImpl(MethodImplOptions.AggressiveInlining)] public Vector3(float value) : this(value, value, value) { }
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector3 operator -(Vector3 value) => Zero - value;
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Dot(Vector3 value1, Vector3 value2) => value1.X * value2.X + value1.Y * value2.Y + value1.Z * value2.Z;
[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);
[MethodImpl(MethodImplOptions.AggressiveInlining)] public float Dot(Vector3 value) => Vector3.Dot(this, value);
[MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AlmostZero(float tolerance = Constants.Tolerance) => X.Abs() < tolerance && Y.Abs() < tolerance && Z.Abs() < tolerance;
[MethodImpl(MethodImplOptions.AggressiveInlining)] public bool AnyComponentNegative() => MinComponent() < 0;
Expand Down
7 changes: 7 additions & 0 deletions src/cs/math3d/Vim.Math3D/StructsPartial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ public Vector3 Cross(Vector3 vector2)
Z * vector2.X - X * vector2.Z,
X * vector2.Y - Y * vector2.X);

/// <summary>
/// Computes the cross product of two vectors.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3 Cross(Vector3 v1, Vector3 v2)
=> v1.Cross(v2);

/// <summary>
/// Returns the mixed product
/// </summary>
Expand Down
11 changes: 8 additions & 3 deletions src/cs/vim/Vim.Format.Core/EntityTable_v2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,20 @@ private static T GetColumnOrDefault<T>(Dictionary<string, T> map, string key, T
/// Returns the index column based on the given column name.
/// </summary>
public int[] GetIndexColumnValues(string columnName)
=> GetColumnOrDefault(IndexColumns, columnName)?.GetColumnValues<int>();
=> GetColumnOrDefault(IndexColumns, columnName)?.GetColumnValues<int>() ?? Array.Empty<int>();

/// <summary>
/// Returns the integer string indices column based on the given column name.
/// </summary>
public int[] GetStringIndices(string columnName)
=> GetColumnOrDefault(StringColumns, columnName)?.GetColumnValues<int>() ?? Array.Empty<int>();

/// <summary>
/// Returns the string column based on the given column name.
/// </summary>
public string[] GetStringColumnValues(string columnName)
{
var stringIndices = GetColumnOrDefault(StringColumns, columnName)
?.GetColumnValues<int>() ?? Array.Empty<int>();
var stringIndices = GetStringIndices(columnName);

var strings = new string[stringIndices.Length];

Expand Down
29 changes: 29 additions & 0 deletions src/cs/vim/Vim.Format.Tests/ElementParameterInfoServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,33 @@ public static void TestUniformatLevelSplit()
Assert.AreEqual("B20", FamilyTypeUniformatInfo.GetUniformatLevel2(partial));
Assert.AreEqual("", FamilyTypeUniformatInfo.GetUniformatLevel3(partial));
}


public static IEnumerable<(List<string>, int, int, int, int)> TestSortAndGetCountCases = new[]
{
(new List<string> { }, 0, 0, 0, 0),
(new List<string> { "a" }, 1, 1, 0, 1),
(new List<string> { "" }, 1, 0, 0, 1),
(new List<string> { "", "" }, 2, 0, 0, 1),
(new List<string> { "a", "" }, 2, 1, 0, 2),
(new List<string> { "-1" }, 1, 1, 1, 1),
(new List<string> { "-1", "" }, 2, 1, 1, 2),
(new List<string> { "-1", "0" }, 2, 2, 2, 2),
(new List<string> { "0", "0" }, 2, 2, 2, 1),
(new List<string> { "a", "b", "c", "d" }, 4, 4, 0, 4),
(new List<string> { "a", "a", "a", "a" }, 4, 4, 0, 1),
(new List<string> { "a", "b", "b", "a" }, 4, 4, 0, 2),
(new List<string> { "", "a", "0", "-1" }, 4, 3, 2, 4),
};

[TestCaseSource(nameof(TestSortAndGetCountCases))]
public static void TestSortAndGetCounts((List<string>, int, int, int, int) item)
{
ParameterSummary.SortAndGetCounts(item.Item1, out var countTotal, out var countFilled, out var countSuspicious, out var countDistinct);

Assert.AreEqual(item.Item2, countTotal);
Assert.AreEqual(item.Item3, countFilled);
Assert.AreEqual(item.Item4, countSuspicious);
Assert.AreEqual(item.Item5, countDistinct);
}
}
Loading
Loading