Commit
…ore merge, plus review)
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,17 +20,22 @@ module Diagrams.Points | |
-- * Point-related utilities | ||
, centroid | ||
, pointDiagram | ||
|
||
, _pIso | ||
) where | ||
|
||
import Diagrams.Core (pointDiagram) | ||
import Diagrams.Core.Points | ||
|
||
import Control.Arrow ((&&&)) | ||
import Control.Lens (Iso', iso) | ||
|
||
import Data.AffineSpace.Point | ||
import Data.VectorSpace | ||
|
||
-- Point v <-> v | ||
_pIso :: Iso' (Point v) v | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Mathnerd314
Author
Contributor
|
||
_pIso = iso unPoint P | ||
|
||
-- | The centroid of a set of /n/ points is their sum divided by /n/. | ||
centroid :: (VectorSpace v, Fractional (Scalar v)) => [Point v] -> Point v | ||
centroid = P . uncurry (^/) . (sumV &&& (fromIntegral . length)) . map unPoint |
5 comments
on commit 06f0536
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.
Can you give me the readers digest version of what you are trying to achieve with these changes. This is an awful lot of code to read through, a paragraph or two of explanation would be a great help.
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.
@jeffreyrosenbluth There's prior discussion at #50; it's probably enough to read the first comment and the last two.
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.
thanks.
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.
Summary of changes, for changelog or reviewing help:
diagrams-lib.cabal: add Diagrams.{Two,Three}D.Double
global changes:
- Double changed to d, Scalar v, or Scalar (V .) depending on context (not in Colour or GradientStop though; grep to see remaining places)
- R2 changed to v with (R2Ish v) added to context; similarly for R3
- Types which hard-coded Double now use v or d; ones with an added type parameter are:
- Angle
- PerspectiveLens, OrthoLens
- PointLight, ParallelLight
- Ellipsoid, Box, Frustum
- ArrowOpts, ArrowHT
- LineWidth, Dashing, DashingA, LGradient, RGradient, Texture, LineTexture, FillTexture
- DImage
- OriginOpts, OffsetOpts, ExpandOpts
- Clip
- PolyType, PolyOrientation, PolygonOpts, RoundedRectOpts
- SizeSpec2D
- Text, FontSize
- Some utility (not exported) variables' types were commented out / tweaked
Coordinates.hs:
- Coordinates instance for :&, move stuff around
- instance (Has* v, v ~ V v) => Has* (Point v) for many Has*, based on _pIso; P2/P3 instances removed
Angle.hs:
- turn and friends need VectorSpace v, Floating (Scalar v)
- sinA and friends need Floating v (i.e., v scalar)
- angleBetween needs InnerSpace v
- HasPhi moved to Angle.hs, generic HasTheta and HasPhi instances for Point like in Coordinates
Direction.hs:
- instances for Read, Show, Eq, Ord, HasTheta, HasPhi added. Eq and Ord probably should get tweaked.
Points.hs:
- _pIso = iso unPoint P added
{Two,Three}D/Types.hs: R{2,3} moved to .Double, methods rewritten to take R{2,3}Ish and use Coords or HasBasis instance
TwoD/Vector.hs: ^& changed to mkR2 (not actually needed)
Arrow.hs:
- MeasureX was introduced into fromMeasure so widthOfJoint was simpler
- connectOutside' changed Num's unary (-) to negateV
Arrowheads.hs:
- parenthesis were added in arrowhead{Dart,Thorn} to avoid Num R2 instance
- arrowtailBlock uses ScopedTypeVariables
Attributes.hs
- LineWidth and DashingA Transformable instances use avgScale
Offset.hs
- Num's unary (-) to negateV in joinSegmentIntersect
TwoD/Transform.hs:
- shearing{X,Y} had sh, sh', swap moved out to top-level (not exported)
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.
Thanks, this is very helpful
We have
_relative
(in Core.Points) which does this in a more general way. I think_relative
implies a more geometric intuition, in which the origin of the affine space is only a convenience of representation, not actually a special point. There's a similar comment in the docs for unPoint