Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream some Diagrams utilities #180

Open
georgefst opened this issue Nov 26, 2024 · 4 comments
Open

Upstream some Diagrams utilities #180

georgefst opened this issue Nov 26, 2024 · 4 comments

Comments

@georgefst
Copy link

In a similar vein to #40, there are various definitions in the diagrams-lib library which seem like they'd be useful here. Personally I've ended up vendoring the following because diagrams-lib can be a bit of a problematic dependency (it has a big footprint, and doesn't work with Wasm for example: diagrams/diagrams-lib#370):

type P2 = Point V2
unitX :: (R1 v, Additive v, Num n) => v n
unitX = zero & lensVL _x .~ 1
unit_X :: (R1 v, Additive v, Num n) => v n
unit_X = zero & lensVL _x .~ -1
unitY :: (R2 v, Additive v, Num n) => v n
unitY = zero & lensVL _y .~ 1
unit_Y :: (R2 v, Additive v, Num n) => v n
unit_Y = zero & lensVL _y .~ -1

Would you consider copying some of these to this library?

Cc @byorgey

@RyanGlScott
Copy link
Collaborator

linear does offer the unit combinator, which allows you to write unit _x and unit _y to achieve what you have called unitX and unitY above. Does unit address that need?

Similarly, I wonder if it would make more sense for linear to offer a combinator for defining unit vectors in a negative direction. Perhaps:

-- | Create a unit vector in a negative direction.
--
-- >>> unitNeg _x :: V2 Int
-- V2 (-1) 0
unitNeg :: (Additive t, Num a) => ASetter' (t a) a -> t a
unitNeg l = set' l (-1) zero

@georgefst
Copy link
Author

georgefst commented Nov 26, 2024

Oh nice, I hadn't noticed unit.

Similarly, I wonder if it would make more sense for linear to offer a combinator for defining unit vectors in a negative direction.

Yeah, I think that'd make sense, although using negate <$> unit _x isn't too bad really.

@Taneb
Copy link
Collaborator

Taneb commented Nov 26, 2024

You can also write negated (unit _x), with negated in Linear.Vector

@georgefst
Copy link
Author

I'd also quite like to see these, although they might be less general than the diagrams versions and thus clash:

reflectX :: (R1 v, Num n) => v n -> v n
reflectX = lensVL _x %~ negate
reflectY :: (R2 v, Num n) => v n -> v n
reflectY = lensVL _y %~ negate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants