diff --git a/source/model/modelutils.js b/source/model/modelutils.js index d43c0c8..42bb5fa 100644 --- a/source/model/modelutils.js +++ b/source/model/modelutils.js @@ -236,16 +236,24 @@ OV.IsSolid = function (element) return null; } - // TODO: two cubes connecting in one edge is solid, but it detects it as not solid const topology = OV.GetTopology (element); for (let edgeIndex = 0; edgeIndex < topology.edges.length; edgeIndex++) { const edge = topology.edges[edgeIndex]; - if (edge.triangles.length !== 2) { + let triCount = edge.triangles.length; + if (triCount === 0 || triCount % 2 !== 0) { return false; } - const edgeOrientation1 = GetEdgeOrientationInTriangle (topology, edge.triangles[0], edgeIndex); - const edgeOrientation2 = GetEdgeOrientationInTriangle (topology, edge.triangles[1], edgeIndex); - if (edgeOrientation1 === edgeOrientation2) { + let edgesDirection = 0; + for (let triIndex = 0; triIndex < edge.triangles.length; triIndex++) { + const triangleIndex = edge.triangles[triIndex]; + const edgeOrientation = GetEdgeOrientationInTriangle (topology, triangleIndex, edgeIndex); + if (edgeOrientation) { + edgesDirection += 1; + } else { + edgesDirection -= 1; + } + } + if (edgesDirection !== 0) { return false; } } diff --git a/test/tests/modelutils_test.js b/test/tests/modelutils_test.js index eeb6f2b..f911d9d 100644 --- a/test/tests/modelutils_test.js +++ b/test/tests/modelutils_test.js @@ -178,6 +178,13 @@ describe ('Model Utils', function () { const model = testUtils.GetTwoCubesConnectingInOneEdgeModel (); let topology = OV.GetTopology (model); assert.strictEqual (topology.vertices.length, 14); - assert (!OV.IsSolid (model)); // TODO: should be identified as solid - }); + assert (OV.IsSolid (model)); + }); + + it ('Two Cubes Connecting in One Face Topology Calculation', function () { + const model = testUtils.GetTwoCubesConnectingInOneFaceModel (); + let topology = OV.GetTopology (model); + assert.strictEqual (topology.vertices.length, 12); + assert (OV.IsSolid (model)); + }); }); diff --git a/test/tests/quantities_test.js b/test/tests/quantities_test.js index 726e886..07e5028 100644 --- a/test/tests/quantities_test.js +++ b/test/tests/quantities_test.js @@ -15,6 +15,21 @@ describe ('Quantities', function () { assert.strictEqual (OV.CalculateVolume (model), null); }); + it ('Two Cubes Connecting in One Vertex Volume Calculation', function () { + const model = testUtils.GetTwoCubesConnectingInOneVertexModel (); + assert (OV.IsEqual (OV.CalculateVolume (model), 2.0)); + }); + + it ('Two Cubes Connecting in One Edge Volume Calculation', function () { + const model = testUtils.GetTwoCubesConnectingInOneEdgeModel (); + assert (OV.IsEqual (OV.CalculateVolume (model), 2.0)); + }); + + it ('Two Cubes Connecting in One Face Volume Calculation', function () { + const model = testUtils.GetTwoCubesConnectingInOneFaceModel (); + assert (OV.IsEqual (OV.CalculateVolume (model), 2.0)); + }); + it ('Cube with Wrongly Oriented Triangle Volume Calculation', function () { var mesh = new OV.Mesh (); mesh.AddVertex (new OV.Coord3D (0.0, 0.0, 0.0)); diff --git a/test/utils/testutils.js b/test/utils/testutils.js index 98ed01b..606ba6f 100644 --- a/test/utils/testutils.js +++ b/test/utils/testutils.js @@ -197,6 +197,24 @@ module.exports = return model; }, + + GetTwoCubesConnectingInOneFaceModel () + { + let model = new OV.Model (); + + let cube1 = this.GetCubeMesh (); + model.AddMesh (cube1); + + let cube2 = this.GetCubeMesh (); + let matrix = new OV.Matrix ().CreateTranslation (1.0, 0.0, 0.0); + let transformation = new OV.Transformation (matrix); + OV.TransformMesh (cube2, transformation); + model.AddMesh (cube2); + + OV.FinalizeModel (model, function () { new OV.Material () }); + return model; + }, + GetCubeWithOneMissingFaceMesh () { var cube = new OV.Mesh ();