Skip to content
Snippets Groups Projects
Verified Commit 069793fe authored by Tamas Gal's avatar Tamas Gal :speech_balloon:
Browse files

Add spread()

parent a46c1164
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ version = "0.13.0"
[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DocOpt = "968ba79b-81e4-546f-ab3a-2eecfa62a9db"
......
......@@ -10,6 +10,7 @@ using KM3io
using StaticArrays
using Rotations
using Combinatorics
using Setfield
using Colors
using LandauDistribution
......@@ -30,8 +31,7 @@ export
duhits, nfoldhits,
most_frequent, categorize, modulemap,
initdb, streamds, detx, # db.jl
rotator,
fibonaccisphere, fibonaccicone,
fibonaccisphere, fibonaccicone, rotator, spread,
# re-export from KM3io
Detector, Direction, Position
......
......@@ -138,3 +138,15 @@ function rotator(dir::Direction)
RotMatrix(ct*cp, -sp, st*cp, ct*sp, cp, st*sp, -st, 0.0, ct)
end
"""
Calculates the maximum angle between the given objects which have a direction.
"""
function spread(objects::Vector{T}) where T
angles = map(combinations(objects, 2)) do obj_pair
angle(obj_pair...)
end
maximum(angles)
end
......@@ -7,4 +7,24 @@ using Test
@test π/2 angle([1,0,0], [0,1,0])
@test π/2 angle([1,0,0], [0,0,1])
@test π angle([1,0,0], [-1,0,0])
end
@testset "spread()" begin
directions = [
Direction(1.0, 0.0, 0.0),
Direction(1.0, 0.0, 0.0),
]
@test 0 spread(directions)
directions = [
Direction(1.0, 0.0, 0.0),
Direction(0.0, 1.0, 0.0),
]
@test π/2 spread(directions)
directions = [
Direction(1.0, 0.0, 0.0),
Direction(-1.0, 0.0, 0.0),
]
@test π spread(directions)
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment