{-# LANGUAGE CPP #-}
module Text.AsciiDiagram.Geometry( Point
, Vector
, Anchor( .. )
, Shape( .. )
, Element( .. )
, Segment( .. )
, SegmentDraw( .. )
, SegmentKind( .. )
, ShapeElement( .. )
, Diagram( .. )
, TextZone( .. )
) where
#if !MIN_VERSION_base(4,8,0)
import Data.Monoid( Monoid( mappend, mempty ))
#endif
import Data.Semigroup( Semigroup( .. ) )
import qualified Data.Set as S
import qualified Data.Text as T
import Linear( V2( .. ) )
type Point = V2 Int
type Vector = V2 Int
data Diagram = Diagram
{
_diagramElements :: S.Set Element
, _diagramCellWidth :: !Int
, _diagramCellHeight :: !Int
, _diagramStyles :: [T.Text]
}
deriving (Eq, Show)
data TextZone = TextZone
{ _textZoneOrigin :: Point
, _textZoneContent :: T.Text
}
deriving (Eq, Ord, Show)
data Anchor
= AnchorMulti
| AnchorFirstDiag
| AnchorSecondDiag
| AnchorPoint
| AnchorBullet
| AnchorArrowUp
| AnchorArrowDown
| AnchorArrowLeft
| AnchorArrowRight
deriving (Eq, Ord, Show)
data SegmentKind
= SegmentHorizontal
| SegmentVertical
deriving (Eq, Ord, Show)
data SegmentDraw
= SegmentSolid
| SegmentDashed
deriving (Eq, Ord, Show)
data Segment = Segment
{ _segStart :: {-# UNPACK #-} !Point
, _segEnd :: {-# UNPACK #-} !Point
, _segKind :: !SegmentKind
, _segDraw :: !SegmentDraw
}
deriving (Eq, Ord)
instance Show Segment where
showsPrec d (Segment s e k dr) =
showParen (d >= 10) $
showString "Segment " . start . end . kind . (' ':) . draw
where
start = showParen True $ shows s
end = showParen True $ shows e
kind = shows k
draw = shows dr
instance Semigroup Segment where
(<>) (Segment a _ _ _) (Segment _ b k d) =
Segment a b k d
instance Monoid Segment where
mempty = Segment 0 0 SegmentVertical SegmentSolid
mappend = (<>)
data ShapeElement
= ShapeAnchor !Point !Anchor
| ShapeSegment !Segment
deriving (Eq, Ord, Show)
data Shape = Shape
{
shapeElements :: ![ShapeElement]
, shapeIsClosed :: !Bool
, shapeTags :: !(S.Set T.Text)
, shapeChildren :: ![Element]
}
deriving (Eq, Ord, Show)
data Element
= ElemText !TextZone
| ElemShape !Shape
deriving (Eq, Show, Ord)