Skip to content

Simplify rev #1139

Open
Open
@yaxu

Description

@yaxu

I think @polymorphicengine pointed out that rev could just negate time, rather than the complex mirroring it's doing now.

Here's an implementation of that:

negateArc (Arc b e) = Arc (negate e) (negate b)
rev' = withQueryArc negateArc . withResultArc negateArc

Can we drop this in or does it have different behaviour? I think it's similar but the cycles are also in reverse order?

for comparison:

rev :: Pattern a -> Pattern a
rev p =
keepMeta p $
splitQueries $
p
{ query = \st ->
map makeWholeAbsolute $
mapParts (mirrorArc (midCycle $ arc st)) $
map
makeWholeRelative
( query
p
st
{ arc = mirrorArc (midCycle $ arc st) (arc st)
}
)
}
where
makeWholeRelative :: Event a -> Event a
makeWholeRelative e@Event {whole = Nothing} = e
makeWholeRelative (Event c (Just (Arc s e)) p'@(Arc s' e') v) =
Event c (Just $ Arc (s' - s) (e - e')) p' v
makeWholeAbsolute :: Event a -> Event a
makeWholeAbsolute e@Event {whole = Nothing} = e
makeWholeAbsolute (Event c (Just (Arc s e)) p'@(Arc s' e') v) =
Event c (Just $ Arc (s' - e) (e' + s)) p' v
midCycle :: Arc -> Time
midCycle (Arc s _) = sam s + 0.5
mapParts :: (Arc -> Arc) -> [Event a] -> [Event a]
mapParts f es = (\(Event c w p' v) -> Event c w (f p') v) <$> es
-- Returns the `mirror image' of a 'Arc' around the given point in time
mirrorArc :: Time -> Arc -> Arc
mirrorArc mid' (Arc s e) = Arc (mid' - (e - mid')) (mid' + (mid' - s))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions