Skip to content

Commit

Permalink
Merge pull request #167 from diagrams/avg-scale
Browse files Browse the repository at this point in the history
move avgScale to core
  • Loading branch information
byorgey committed Mar 12, 2014
2 parents f86249c + c76595e commit b9a3a2d
Showing 1 changed file with 1 addition and 40 deletions.
41 changes: 1 addition & 40 deletions src/Diagrams/TwoD/Transform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ module Diagrams.TwoD.Transform

-- * Utilities
, onBasis
, avgScale
) where

import Diagrams.Core
Expand Down Expand Up @@ -248,42 +247,4 @@ shearY = transform . shearingY
-- is mostly useful for implementing backends.
onBasis :: Transformation R2 -> ((R2, R2), R2)
onBasis t = ((x, y), v)
where ((x:y:[]), v) = T.onBasis t

-- | Compute the \"average\" amount of scaling performed by a
-- transformation. Satisfies the properties
--
-- @
-- avgScale (scaling k) == k
-- avgScale (t1 <> t2) == avgScale t1 * avgScale t2
-- @
--
-- Backends which do not support stroking in the context of an
-- arbitrary transformation may instead call 'avgScale' on
-- \"frozen\" transformations and multiply the line width by the
-- resulting value.
avgScale :: T2 -> Double
avgScale t = sqrt (abs (x1*y2 - y1*x2))
where ((unr2 -> (x1,y1), unr2 -> (x2,y2)), _) = onBasis t

{-
avgScale is computed as the square root of the positive
determinant. Proofs for the specified properties:
1. sqrt (|det (scaling k)|) = sqrt (k^2) = k
2. sqrt (|det t1|) * sqrt (|det t2|)
= sqrt (|det t1| * |det t2|)
= sqrt (|det t1 * det t2|)
= sqrt (|det (t1 * t2)|)
From wikipedia:
A geometric interpretation can be given to the value of the
determinant of a square matrix with real entries: the absolute
value of the determinant gives the scale factor by which area or
volume (or a higher dimensional analogue) is multiplied under the
associated linear transformation, while its sign indicates whether
the transformation preserves orientation.
-}
where ((x:y:[]), v) = T.onBasis t

0 comments on commit b9a3a2d

Please sign in to comment.