Remove solidity check from volume calculation.

This commit is contained in:
kovacsv 2021-12-18 10:31:40 +01:00
parent d5976ec8db
commit 1cf59b750f
4 changed files with 24 additions and 9 deletions

View File

@ -18,9 +18,6 @@ OV.GetTetrahedronSignedVolume = function (v0, v1, v2)
OV.CalculateVolume = function (object3D) OV.CalculateVolume = function (object3D)
{ {
if (!OV.IsSolid (object3D)) {
return null;
}
let volume = 0.0; let volume = 0.0;
object3D.EnumerateTriangleVertices ((v0, v1, v2) => { object3D.EnumerateTriangleVertices ((v0, v1, v2) => {
volume += OV.GetTetrahedronSignedVolume (v0, v1, v2); volume += OV.GetTetrahedronSignedVolume (v0, v1, v2);

View File

@ -111,6 +111,7 @@ describe ('O3dv Importer', function () {
assert.strictEqual (model.MeshCount (), 5); assert.strictEqual (model.MeshCount (), 5);
assert.strictEqual (model.MeshInstanceCount (), 5); assert.strictEqual (model.MeshInstanceCount (), 5);
assert (OV.IsSolid (model));
assert (OV.IsEqual (OV.CalculateVolume (model), 8.707448863695035)); assert (OV.IsEqual (OV.CalculateVolume (model), 8.707448863695035));
assert (OV.IsEqual (OV.CalculateSurfaceArea (model), 39.636169009449105)); assert (OV.IsEqual (OV.CalculateSurfaceArea (model), 39.636169009449105));

View File

@ -5,6 +5,8 @@ describe ('Quantities', function () {
it ('Cube Volume Calculation', function () { it ('Cube Volume Calculation', function () {
const mesh = OV.GenerateCuboid (null, 1.0, 1.0, 1.0); const mesh = OV.GenerateCuboid (null, 1.0, 1.0, 1.0);
const model = testUtils.GetModelWithOneMesh (mesh); const model = testUtils.GetModelWithOneMesh (mesh);
assert (OV.IsSolid (mesh));
assert (OV.IsSolid (model));
assert (OV.IsEqual (OV.CalculateVolume (mesh), 1.0)); assert (OV.IsEqual (OV.CalculateVolume (mesh), 1.0));
assert (OV.IsEqual (OV.CalculateVolume (model), 1.0)); assert (OV.IsEqual (OV.CalculateVolume (model), 1.0));
}); });
@ -12,21 +14,24 @@ describe ('Quantities', function () {
it ('Cube with Missing Face Volume Calculation', function () { it ('Cube with Missing Face Volume Calculation', function () {
const mesh = testUtils.GetCubeWithOneMissingFaceMesh (); const mesh = testUtils.GetCubeWithOneMissingFaceMesh ();
const model = testUtils.GetModelWithOneMesh (mesh); const model = testUtils.GetModelWithOneMesh (mesh);
assert.strictEqual (OV.CalculateVolume (model), null); assert (!OV.IsSolid (model));
}); });
it ('Two Cubes Connecting in One Vertex Volume Calculation', function () { it ('Two Cubes Connecting in One Vertex Volume Calculation', function () {
const model = testUtils.GetTwoCubesConnectingInOneVertexModel (); const model = testUtils.GetTwoCubesConnectingInOneVertexModel ();
assert (OV.IsSolid (model));
assert (OV.IsEqual (OV.CalculateVolume (model), 2.0)); assert (OV.IsEqual (OV.CalculateVolume (model), 2.0));
}); });
it ('Two Cubes Connecting in One Edge Volume Calculation', function () { it ('Two Cubes Connecting in One Edge Volume Calculation', function () {
const model = testUtils.GetTwoCubesConnectingInOneEdgeModel (); const model = testUtils.GetTwoCubesConnectingInOneEdgeModel ();
assert (OV.IsSolid (model));
assert (OV.IsEqual (OV.CalculateVolume (model), 2.0)); assert (OV.IsEqual (OV.CalculateVolume (model), 2.0));
}); });
it ('Two Cubes Connecting in One Face Volume Calculation', function () { it ('Two Cubes Connecting in One Face Volume Calculation', function () {
const model = testUtils.GetTwoCubesConnectingInOneFaceModel (); const model = testUtils.GetTwoCubesConnectingInOneFaceModel ();
assert (OV.IsSolid (model));
assert (OV.IsEqual (OV.CalculateVolume (model), 2.0)); assert (OV.IsEqual (OV.CalculateVolume (model), 2.0));
}); });
@ -53,13 +58,15 @@ describe ('Quantities', function () {
mesh.AddTriangle (new OV.Triangle (4, 5, 6)); mesh.AddTriangle (new OV.Triangle (4, 5, 6));
mesh.AddTriangle (new OV.Triangle (4, 7, 6)); mesh.AddTriangle (new OV.Triangle (4, 7, 6));
const model = testUtils.GetModelWithOneMesh (mesh); const model = testUtils.GetModelWithOneMesh (mesh);
assert.strictEqual (OV.CalculateVolume (mesh), null); assert (!OV.IsSolid (mesh));
assert.strictEqual (OV.CalculateVolume (model), null); assert (!OV.IsSolid (model));
}); });
it ('Cube Surface Area Calculation', function () { it ('Cube Surface Area Calculation', function () {
const mesh = OV.GenerateCuboid (null, 1.0, 1.0, 1.0); const mesh = OV.GenerateCuboid (null, 1.0, 1.0, 1.0);
const model = testUtils.GetModelWithOneMesh (mesh); const model = testUtils.GetModelWithOneMesh (mesh);
assert (OV.IsSolid (mesh));
assert (OV.IsSolid (model));
assert (OV.IsEqual (OV.CalculateSurfaceArea (mesh), 6.0)); assert (OV.IsEqual (OV.CalculateSurfaceArea (mesh), 6.0));
assert (OV.IsEqual (OV.CalculateSurfaceArea (model), 6.0)); assert (OV.IsEqual (OV.CalculateSurfaceArea (model), 6.0));
}); });
@ -67,6 +74,8 @@ describe ('Quantities', function () {
it ('Cube with Missing Face Surface Area Calculation', function () { it ('Cube with Missing Face Surface Area Calculation', function () {
const mesh = testUtils.GetCubeWithOneMissingFaceMesh (); const mesh = testUtils.GetCubeWithOneMissingFaceMesh ();
const model = testUtils.GetModelWithOneMesh (mesh); const model = testUtils.GetModelWithOneMesh (mesh);
assert (!OV.IsSolid (mesh));
assert (!OV.IsSolid (model));
assert (OV.IsEqual (OV.CalculateSurfaceArea (mesh), 5.0)); assert (OV.IsEqual (OV.CalculateSurfaceArea (mesh), 5.0));
assert (OV.IsEqual (OV.CalculateSurfaceArea (model), 5.0)); assert (OV.IsEqual (OV.CalculateSurfaceArea (model), 5.0));
}); });
@ -75,6 +84,8 @@ describe ('Quantities', function () {
const edgeLength = OV.CoordDistance3D (new OV.Coord3D (1.0, 1.0, 1.0), new OV.Coord3D (-1.0, -1.0, 1.0)); const edgeLength = OV.CoordDistance3D (new OV.Coord3D (1.0, 1.0, 1.0), new OV.Coord3D (-1.0, -1.0, 1.0));
const mesh = testUtils.GetTetrahedronMesh (); const mesh = testUtils.GetTetrahedronMesh ();
const model = testUtils.GetModelWithOneMesh (mesh); const model = testUtils.GetModelWithOneMesh (mesh);
assert (OV.IsSolid (mesh));
assert (OV.IsSolid (model));
assert (OV.IsEqual (OV.CalculateVolume (mesh), Math.pow (edgeLength, 3.0) / (6.0 * Math.sqrt (2)))); assert (OV.IsEqual (OV.CalculateVolume (mesh), Math.pow (edgeLength, 3.0) / (6.0 * Math.sqrt (2))));
assert (OV.IsEqual (OV.CalculateVolume (model), Math.pow (edgeLength, 3.0) / (6.0 * Math.sqrt (2)))); assert (OV.IsEqual (OV.CalculateVolume (model), Math.pow (edgeLength, 3.0) / (6.0 * Math.sqrt (2))));
}); });
@ -83,6 +94,8 @@ describe ('Quantities', function () {
const edgeLength = OV.CoordDistance3D (new OV.Coord3D (1.0, 1.0, 1.0), new OV.Coord3D (-1.0, -1.0, 1.0)); const edgeLength = OV.CoordDistance3D (new OV.Coord3D (1.0, 1.0, 1.0), new OV.Coord3D (-1.0, -1.0, 1.0));
const mesh = testUtils.GetTetrahedronMesh (); const mesh = testUtils.GetTetrahedronMesh ();
const model = testUtils.GetModelWithOneMesh (mesh); const model = testUtils.GetModelWithOneMesh (mesh);
assert (OV.IsSolid (mesh));
assert (OV.IsSolid (model));
assert (OV.IsEqual (OV.CalculateSurfaceArea (mesh), Math.sqrt (3) * Math.pow (edgeLength, 2.0))); assert (OV.IsEqual (OV.CalculateSurfaceArea (mesh), Math.sqrt (3) * Math.pow (edgeLength, 2.0)));
assert (OV.IsEqual (OV.CalculateSurfaceArea (model), Math.sqrt (3) * Math.pow (edgeLength, 2.0))); assert (OV.IsEqual (OV.CalculateSurfaceArea (model), Math.sqrt (3) * Math.pow (edgeLength, 2.0)));
}); });
@ -93,6 +106,7 @@ describe ('Quantities', function () {
let node = new OV.Node (); let node = new OV.Node ();
node.SetTransformation (transformation); node.SetTransformation (transformation);
const meshInstance = new OV.MeshInstance (node, mesh); const meshInstance = new OV.MeshInstance (node, mesh);
assert (OV.IsSolid (meshInstance));
assert (OV.IsEqual (OV.CalculateVolume (meshInstance), 8.0)); assert (OV.IsEqual (OV.CalculateVolume (meshInstance), 8.0));
assert (OV.IsEqual (OV.CalculateSurfaceArea (meshInstance), 24.0)); assert (OV.IsEqual (OV.CalculateSurfaceArea (meshInstance), 24.0));
}); });

View File

@ -27,6 +27,9 @@ OV.SidebarDetailsPanel = class extends OV.SidebarPanel
this.AddProperty (table, new OV.Property (OV.PropertyType.Number, 'Size Y', size.y)); this.AddProperty (table, new OV.Property (OV.PropertyType.Number, 'Size Y', size.y));
this.AddProperty (table, new OV.Property (OV.PropertyType.Number, 'Size Z', size.z)); this.AddProperty (table, new OV.Property (OV.PropertyType.Number, 'Size Z', size.z));
this.AddCalculatedProperty (table, 'Volume', () => { this.AddCalculatedProperty (table, 'Volume', () => {
if (!OV.IsSolid (object3D)) {
return null;
}
const volume = OV.CalculateVolume (object3D); const volume = OV.CalculateVolume (object3D);
if (volume === null) { if (volume === null) {
return null; return null;
@ -34,11 +37,11 @@ OV.SidebarDetailsPanel = class extends OV.SidebarPanel
return new OV.Property (OV.PropertyType.Number, null, volume); return new OV.Property (OV.PropertyType.Number, null, volume);
}); });
this.AddCalculatedProperty (table, 'Surface', () => { this.AddCalculatedProperty (table, 'Surface', () => {
const volume = OV.CalculateSurfaceArea (object3D); const surfaceArea = OV.CalculateSurfaceArea (object3D);
if (volume === null) { if (surfaceArea === null) {
return null; return null;
} }
return new OV.Property (OV.PropertyType.Number, null, volume); return new OV.Property (OV.PropertyType.Number, null, surfaceArea);
}); });
if (object3D.PropertyGroupCount () > 0) { if (object3D.PropertyGroupCount () > 0) {
let customTable = OV.AddDiv (this.contentDiv, 'ov_property_table ov_property_table_custom'); let customTable = OV.AddDiv (this.contentDiv, 'ov_property_table ov_property_table_custom');