1
0
mirror of https://gitlab.com/MisterBiggs/stl-process.git synced 2025-08-03 12:01:33 +00:00

made tests like way better

This commit is contained in:
2022-04-05 16:43:36 -07:00
parent a14208245d
commit 834cfc3d1a
8 changed files with 62 additions and 30 deletions

View File

@@ -74,7 +74,7 @@ function get_mass_properties(triangles; scale=1)
inertia[2, 3] = inertia[3, 2] = -(intg[9] - volume .* center_of_gravity[2] .* center_of_gravity[3]) inertia[2, 3] = inertia[3, 2] = -(intg[9] - volume .* center_of_gravity[2] .* center_of_gravity[3])
inertia[1, 3] = inertia[3, 1] = -(intg[10] - volume .* center_of_gravity[3] .* center_of_gravity[1]) inertia[1, 3] = inertia[3, 1] = -(intg[10] - volume .* center_of_gravity[3] .* center_of_gravity[1])
return Properties(volume, center_of_gravity, inertia) return Properties(volume, center_of_gravity, inertia ./ volume)
end end
function fast_volume(triangles; scale=1) function fast_volume(triangles; scale=1)

View File

@@ -1,6 +1,7 @@
using Test using Test
using stlProcess using stlProcess
import stlProcess.Properties
using FileIO using FileIO
using MeshIO using MeshIO
@@ -45,37 +46,41 @@ function _check_volume(triangles; scale=1)
return volume return volume
end end
@testset "simple cube stl" begin @testset "3D Models" begin
""" I_mat = Matrix(I, 3, 3)
inertia math: center = [0, 0, 0]
https://hepweb.ucsd.edu/ph110b/110b_notes/node26.html
Cube is a standard cube with a length of 2 for each side. models = Dict(
""" # Inertia math: https://en.wikipedia.org/wiki/List_of_moments_of_inertia#List_of_3D_inertia_tensors
cube_path = raw"test_assets\cubeblender.stl" # Properties(volume, center_of_gravity, inertia)
stl = load(cube_path) "cube.stl" => Properties(2.0^3, center, I_mat .* 2^2 / 6), # l = 2
"sphere.stl" => Properties(4 / 3 * pi, center, I_mat .* 2 / 5), # r = 1
"2_4_8_cuboid.stl" => Properties(2 * 4 * 8, center, diagm([2^2 + 4^2, 8^2 + 2^2, 8^2 + 4^2]) ./ 12), # h, d, w = 2, 4, 8
"slender_y.stl" => Properties(10 * π * 0.1^2, center, diagm([1, 0, 1]) .* (10^2 / 12)), # l_z = 10, r = 0.1
"cylinder.stl" => Properties(10 * π * 1^2, center, diagm([(3 + 10^2) / 12, (3 + 10^2) / 12, 1^2 / 2])), # l_z = 10, r = 1
)
@testset "$model" for (model, control) in models
path = "test_assets\\$model"
stl = load(path)
@testset "get_mass_properties function" begin @testset "get_mass_properties" begin
props = get_mass_properties(stl) props = get_mass_properties(stl)
@test props.volume == 8.0 @test props.volume control.volume atol = 0.5
@test all(props.center_of_gravity .== 0.0) @test props.center_of_gravity control.center_of_gravity atol = 0.01
@test all(eigvals(props.inertia) . (5.0 + 1 / 3)) @test eigvals(props.inertia) eigvals(control.inertia) atol = 0.1
@testset "get_volume function" begin
@test _check_volume(stl; scale=1) props.volume rtol = 0.01
@test _check_volume(stl; scale=4) (4 * 2)^3 rtol = 0.01
end
end end
@testset "Compare volumes with scaling" begin @testset "Compare volumes with scaling" begin
for scale in 1:5 for scale in 1:5
props = get_mass_properties(stl; scale=scale) props = get_mass_properties(stl; scale=scale)
volume = _check_volume(stl; scale=scale) volume = _check_volume(stl; scale=scale)
@test props.volume volume atol = 0.1
@test props.volume volume rtol = 0.01 end
end
@testset "find_volume" begin
for scale in [0.5, 1, 1.0, 10, 2 / 3]
@test fast_volume(stl; scale=find_scale(stl; desired_volume=scale)) scale
end end
end end
@testset "Find Scale" begin
@test fast_volume(stl; scale=find_scale(stl)) == 1.0
end end
end end

Binary file not shown.

View File

@@ -0,0 +1,27 @@
# Test Assets
## cube.stl
Perfect cube with length of 2 for all sides and a center of gravity at origin.
## 2_4_8_cuboid.stl
Cube with dimensions:
- height = 2
- depth = 4
- width = 8
Center of gravity at origin.
## sphere.stl
Perfect sphere with radius of 1 and a center of gravity at origin.
## slender_rod.stl
Negligible thickness cylinder with length of 10, radius of 0.1, and a center of gravity at origin.
## cylinder.stl
Cylinder with length of 10, radius of 1, and a center of gravity at origin.

Binary file not shown.

Binary file not shown.

BIN
test/test_assets/sphere.stl Normal file

Binary file not shown.