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

return list of traces #145

Merged
merged 3 commits into from
Jan 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions src/Diagrams/ThreeD/Shapes.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{-# LANGUAGE TypeFamilies
, FlexibleContexts
, MultiParamTypeClasses
, ViewPatterns
#-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
-----------------------------------------------------------------------------
-- |
-- Module : Diagrams.ThreeD.Shapes
Expand All @@ -20,17 +18,16 @@ module Diagrams.ThreeD.Shapes
, sphere
) where

import Prelude hiding (minimum)
import Data.Semigroup
import Data.Semigroup
import Prelude

import Data.AffineSpace
import Data.Monoid.Inf (minimum)
import Data.VectorSpace
import Data.AffineSpace
import Data.VectorSpace

import Diagrams.Core
import Diagrams.Core

import Diagrams.ThreeD.Types
import Diagrams.Solve
import Diagrams.Solve
import Diagrams.ThreeD.Types

data Ellipsoid = Ellipsoid T3

Expand All @@ -51,7 +48,7 @@ sphere = mkQD (Prim $ Ellipsoid mempty)
mempty
(Query sphereQuery)
where sphereEnv v = 1 / magnitude v
sphereTrace p v = minimum (quadForm a b c)
sphereTrace p v = mkSortedList $ quadForm a b c
where a = v <.> v
b = 2 *^ p' <.> v
c = p' <.> p' - 1
Expand Down
13 changes: 7 additions & 6 deletions src/Diagrams/TwoD/Segment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ module Diagrams.TwoD.Segment where
import Control.Applicative (liftA2)

import Data.AffineSpace
import Data.Monoid.Inf hiding (minimum)
import Data.VectorSpace

import Diagrams.Core
Expand All @@ -38,6 +37,10 @@ import Diagrams.TwoD.Types
import Diagrams.TwoD.Vector
import Diagrams.Util

{- All instances of Traced should maintain the invariant that the list of
traces is sorted in increasing order.
-}

instance Traced (Segment Closed R2) where
getTrace = getTrace . mkFixedSeg . (`at` origin)

Expand Down Expand Up @@ -73,8 +76,8 @@ instance Traced (FixedSegment R2) where
t1 = (perp v0 <.> p) / det
in
if det == 0 || t0 < 0 || t0 > 1
then Infinity
else Finite t1
then mkSortedList []
else mkSortedList [t1]

{- To do intersection of a line with a cubic Bezier, we first rotate
and scale everything so that the line has parameters (origin, unitX);
Expand All @@ -100,7 +103,5 @@ instance Traced (FixedSegment R2) where
ts = filter (liftA2 (&&) (>= 0) (<= 1)) (cubForm a b c d)
xs = map (fst . unp2 . atParam bez') ts
in
case xs of
[] -> Infinity
_ -> Finite (minimum xs)
mkSortedList xs