-
Notifications
You must be signed in to change notification settings - Fork 63
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
Direction type #186
Merged
Direction type #186
Changes from 7 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2d18288
Add Direction type
bergey a7c3b0f
Add Semigroup and Monoid instances for Angle
bergey 8d365fb
Remove old direction functions operating on Angles
bergey 9d4794e
Update arrow code to use Direction
bergey b3c3b8f
Change Arc code to use a Direction and a sweep Angle
bergey e6c1433
Update everything else to use Direction
bergey ddce8f6
Wall: add instances for Polar
bergey b0b39eb
fix header in Direction
bergey 9f84cdc
avoid use of `e` in Arrowheads
bergey fbc97d0
Use atan2 instead of atan
bergey d89c025
Export xDir, Direction module
bergey c3c6724
Export Deform from 3D
bergey d4d7398
Remove law-breaking AffineSpace instance
bergey 42b85ed
add atan2A function
bergey ed7410c
atDirection is no longer specific to R2
bergey e79f568
revise arc functions to respect sign of Angle
bergey 6a27bf9
glue circle into a Loop
bergey 1ac0743
add Transformable instance for Direction
bergey 7be96f6
Add UndecidableInstances pragma to Direction
bergey 02dd838
angleBetween is commutative
bergey d5e265e
fix implementation of pointAt
bergey 34c1266
Merge remote-tracking branch 'origin/master' into direction
bergey df10acf
fix imports, add some parens
bergey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE RankNTypes #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
----------------------------------------------------------------------------- | ||
-- | | ||
-- Module : Diagrams.Angle | ||
-- Copyright : (c) 2013 diagrams-lib team (see LICENSE) | ||
-- License : BSD-style (see LICENSE) | ||
-- Maintainer : diagrams-discuss@googlegroups.com | ||
-- | ||
-- Type for representing directions, polymorphic in vector space | ||
-- | ||
----------------------------------------------------------------------------- | ||
|
||
module Diagrams.Direction | ||
( Direction | ||
, _Dir | ||
, direction, fromDirection | ||
, angleBetweenDirs | ||
) where | ||
|
||
import Control.Lens | ||
import Data.VectorSpace | ||
|
||
import Diagrams.Angle | ||
|
||
-------------------------------------------------------------------------------- | ||
-- Direction | ||
|
||
-- | A vector is described by a @Direction@ and a magnitude. So we | ||
-- can think of a @Direction@ as a vector that has forgotten its | ||
-- magnitude. @Direction@s can be used with 'fromDirection' and the | ||
-- lenses provided by its instances. | ||
data Direction v = Direction v | ||
|
||
-- | _Dir is provided to allow efficient implementations of functions | ||
-- in particular vector-spaces, but should be used with care as it | ||
-- exposes too much information. | ||
_Dir :: Iso' (Direction v) v | ||
_Dir = iso (\(Direction v) -> v) Direction | ||
|
||
-- | @direction v@ is the direction in which @v@ points. Returns an | ||
-- unspecified value when given the zero vector as input. | ||
direction :: v -> Direction v | ||
direction = Direction | ||
|
||
-- | @fromDirection d@ is the unit vector in the direction @d@. | ||
fromDirection :: (InnerSpace v, Floating (Scalar v)) => Direction v -> v | ||
fromDirection (Direction v) = normalized v | ||
|
||
-- | compute the positive angle between the two directions in their common plane | ||
angleBetweenDirs :: (InnerSpace v, Scalar v ~ Double) => | ||
Direction v -> Direction v -> Angle | ||
angleBetweenDirs d1 d2 = angleBetween (fromDirection d1) (fromDirection d2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be Diagrams.Direction?