Skip to content

Commit

Permalink
Refactor RegularSampling
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Mar 17, 2024
1 parent fe1ad1e commit 5a287b6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 49 deletions.
22 changes: 11 additions & 11 deletions src/sampling/regular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,21 @@ end
floattype(T::Type{<:Quantity}) = floattype(Unitful.numtype(T))
floattype(T::Type) = float(T)

firstoffset(::Sphere{3}) = (n -> inv(n + 1), n -> zero(n))
lastoffset(::Sphere{3}) = (n -> inv(n + 1), n -> inv(n))
extrapoints(s::Sphere{3}) = (s(0, 0), s(1, 0))
firstoffset(g::Geometry) = ntuple(i -> (n -> zero(n)), paramdim(g))
lastoffset(g::Geometry) = ntuple(i -> (n -> isperiodic(g)[i] ? inv(n) : zero(n)), paramdim(g))
extrapoints(::Geometry) = ()

firstoffset(d::Disk) = (n -> inv(n), firstoffset(boundary(d))...)
lastoffset(d::Disk) = (n -> zero(n), lastoffset(boundary(d))...)
extrapoints(d::Disk) = (center(d),)

firstoffset(b::Ball) = (n -> inv(n + 1), firstoffset(boundary(b))...)
firstoffset(b::Ball) = (n -> inv(n), firstoffset(boundary(b))...)
lastoffset(b::Ball) = (n -> zero(n), lastoffset(boundary(b))...)
extrapoints(b::Ball) = (center(b),)

firstoffset(d::Disk) = (n -> inv(n + 1), firstoffset(boundary(d))...)
lastoffset(d::Disk) = (n -> zero(n), lastoffset(boundary(d))...)
extrapoints(d::Disk) = (center(d),)
firstoffset(::Sphere{3}) = (n -> inv(n + 1), n -> zero(n))
lastoffset(::Sphere{3}) = (n -> inv(n + 1), n -> inv(n))
extrapoints(s::Sphere{3}) = (s(0, 0), s(1, 0))

firstoffset(::CylinderSurface) = (n -> zero(n), n -> zero(n))
lastoffset(::CylinderSurface) = (n -> inv(n), n -> zero(n))
Expand All @@ -60,10 +64,6 @@ firstoffset(::ConeSurface) = (n -> zero(n), n -> inv(n))
lastoffset(::ConeSurface) = (n -> inv(n), n -> zero(n))
extrapoints(c::ConeSurface) = (apex(c), base(c)(0, 0))

firstoffset(g::Geometry) = ntuple(i -> (n -> zero(n)), paramdim(g))
lastoffset(g::Geometry) = ntuple(i -> (n -> isperiodic(g)[i] ? inv(n) : zero(n)), paramdim(g))
extrapoints(::Geometry) = ()

# --------------
# SPECIAL CASES
# --------------
Expand Down
76 changes: 38 additions & 38 deletions test/sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,18 @@
ps = sample(b, RegularSampling(3, 4))
@test all((b), ps)
ts = P2[
(0.5, 0.0),
(1.25, 0.0),
(0.6666666666666666, 0.0),
(1.3333333333333333, 0.0),
(2.0, 0.0),
(3.061616997868383e-17, 0.5),
(7.654042494670958e-17, 1.25),
(1.2246467991473532e-16, 2.0),
(-0.5, 6.123233995736766e-17),
(-1.25, 1.5308084989341916e-16),
(-2.0, 2.4492935982947064e-16),
(-9.184850993605148e-17, -0.5),
(-2.296212748401287e-16, -1.25),
(-3.6739403974420594e-16, -2.0),
(0.0, 0.6666666666666666),
(0.0, 1.3333333333333333),
(0.0, 2.0),
(-0.6666666666666666, 0.0),
(-1.3333333333333333, 0.0),
(-2.0, 0.0),
(0.0, -0.6666666666666666),
(0.0, -1.3333333333333333),
(0.0, -2.0),
(0.0, 0.0)
]
for (p, t) in zip(ps, ts)
Expand All @@ -129,17 +129,17 @@
ps = sample(b, RegularSampling(4, 3))
@test all((b), ps)
ts = P2[
(10.4, 10.0),
(10.933333333333334, 10.0),
(11.466666666666667, 10.0),
(10.5, 10.0),
(11.0, 10.0),
(11.5, 10.0),
(12.0, 10.0),
(9.8, 10.346410161513775),
(9.533333333333333, 10.808290376865475),
(9.266666666666666, 11.270170592217177),
(9.75, 10.433012701892219),
(9.5, 10.86602540378444),
(9.25, 11.299038105676658),
(9.0, 11.732050807568877),
(9.8, 9.653589838486225),
(9.533333333333333, 9.191709623134523),
(9.266666666666667, 8.729829407782823),
(9.75, 9.566987298107781),
(9.5, 9.13397459621556),
(9.25, 8.700961894323342),
(9.0, 8.267949192431121),
(10.0, 10.0)
]
Expand All @@ -151,24 +151,24 @@
ps = sample(b, RegularSampling(3, 2, 3))
@test all((b), ps)
ts = P3[
(0.4330127018922193, 0.0, 0.25000000000000006),
(1.0825317547305482, 0.0, 0.6250000000000001),
(1.7320508075688772, 0.0, 1.0000000000000002),
(0.4330127018922193, 0.0, -0.2500000000000001),
(1.0825317547305482, 0.0, -0.6250000000000002),
(1.7320508075688772, 0.0, -1.0000000000000004),
(-0.21650635094610973, 0.37499999999999994, 0.25000000000000006),
(-0.5412658773652743, 0.9374999999999999, 0.6250000000000001),
(-0.8660254037844389, 1.4999999999999998, 1.0000000000000002),
(-0.21650635094610973, 0.37499999999999994, -0.2500000000000001),
(-0.5412658773652743, 0.9374999999999999, -0.6250000000000002),
(-0.8660254037844389, 1.4999999999999998, -1.0000000000000004),
(-0.21650635094610948, -0.37500000000000006, 0.25000000000000006),
(-0.5412658773652737, -0.9375000000000001, 0.6250000000000001),
(-0.8660254037844379, -1.5000000000000002, 1.0000000000000002),
(-0.21650635094610948, -0.37500000000000006, -0.2500000000000001),
(-0.5412658773652737, -0.9375000000000001, -0.6250000000000002),
(-0.8660254037844379, -1.5000000000000002, -1.0000000000000004),
(0.5773502691896257, 0.0, 0.3333333333333333),
(1.1547005383792515, 0.0, 0.6666666666666666),
(1.7320508075688772, 0.0, 1.0),
(0.5773502691896256, 0.0, -0.3333333333333335),
(1.1547005383792512, 0.0, -0.666666666666667),
(1.732050807568877, 0.0, -1.0000000000000004),
(-0.288675134594813, 0.4999999999999999, 0.3333333333333333),
(-0.577350269189626, 0.9999999999999998, 0.6666666666666666),
(-0.8660254037844389, 1.4999999999999996, 1.0),
(-0.2886751345948129, 0.4999999999999998, -0.3333333333333335),
(-0.5773502691896258, 0.9999999999999996, -0.666666666666667),
(-0.8660254037844388, 1.4999999999999993, -1.0000000000000004),
(-0.28867513459481264, -0.5000000000000001, 0.3333333333333333),
(-0.5773502691896253, -1.0000000000000002, 0.6666666666666666),
(-0.8660254037844379, -1.5000000000000004, 1.0),
(-0.2886751345948126, -0.5, -0.3333333333333335),
(-0.5773502691896252, -1.0, -0.666666666666667),
(-0.8660254037844378, -1.5000000000000002, -1.0000000000000004),
(0.0, 0.0, 0.0)
]
for (p, t) in zip(ps, ts)
Expand Down

0 comments on commit 5a287b6

Please sign in to comment.