From fd765a767201eb6ea9b64fb81b84443e29e861cb Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Thu, 28 Jan 2021 00:34:07 -0700 Subject: [PATCH] added structures --- Project.toml | 1 + src/AstroHelper.jl | 3 ++- src/aeStructures.jl | 30 ++++++++++++++++++++++++++++++ test/runtests.jl | 19 ++++++++++++++----- 4 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 src/aeStructures.jl diff --git a/Project.toml b/Project.toml index 5021c23..3708568 100644 --- a/Project.toml +++ b/Project.toml @@ -4,4 +4,5 @@ authors = ["Anson "] version = "0.1.0" [deps] +DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/AstroHelper.jl b/src/AstroHelper.jl index 055a921..c024c71 100644 --- a/src/AstroHelper.jl +++ b/src/AstroHelper.jl @@ -1,7 +1,8 @@ module AstroHelper using LinearAlgebra - +using DataFrames include("quaternions.jl") +include("aeStructures.jl") end # module diff --git a/src/aeStructures.jl b/src/aeStructures.jl new file mode 100644 index 0000000..99e88ab --- /dev/null +++ b/src/aeStructures.jl @@ -0,0 +1,30 @@ +struct Section + data::DataFrame + xc::Float64 + yc::Float64 + Ixx::Float64 + Iyy::Float64 + Ixy::Float64 + + function Section(A, x, y) + d = DataFrame(A=A, x=x, y=y) + + d.Ax = d.A .* d.x + d.Ay = d.A .* d.y + + xc = sum(d.Ax) / sum(d.A) + yc = sum(d.Ay) / sum(d.A) + + Ixx = sum(d.A .* ((d.y .- yc).^2)) + Iyy = sum(d.A .* ((d.x .- xc).^2)) + Ixy = sum(d.A .* ((d.x .- xc) .* (d.y .- yc))) + + + new(d, xc, yc, Ixx, Iyy, Ixy) + + end + + +end + + diff --git a/test/runtests.jl b/test/runtests.jl index 7a162f4..75a8836 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,9 +1,10 @@ -using AstroHelper using Test -import AstroHelper +import AstroHelper: Quaternion, Section -@testset "Quaternion Initialization" begin + +@testset "AeroHelper" begin + @testset "Quaternion Initialization" begin @test Quaternion().r == 1.0 @test Quaternion([0,0,0,1]) == Quaternion() @test Quaternion([0 0 0], 0) == Quaternion() @@ -13,9 +14,17 @@ import AstroHelper @test Quaternion(0, 0, pi / 2) ≈ Quaternion([1 0 0], pi / 2) @test_throws ErrorException Quaternion(1, 2, 3, 4) -end + end -@testset "Quaternion Math" begin +# @testset "Quaternion Math" begin # Quaternion Multiplication is not Communitive. # @test Quaternion() * Quaternion([0 1 0 0]) != Quaternion([0 1 0 0]) * Quaternion() +# end + + + @testset "Section" begin + s = Section([2,1,0.5,0.5,0.75,0.75,2], [0,12,24,24,16,8,0], [0,0,0,6,7,8,9]) + @test all([s.Ixx == 126.075 s.Iyy == 571.2 s.Ixy ≈ -28.2]) + +end end \ No newline at end of file