module Wumpus.Drawing.Shapes.InvTriangle
(
InvTriangle
, DInvTriangle
, invtriangle
) where
import Wumpus.Drawing.Shapes.Base
import Wumpus.Drawing.Shapes.Triangle
import Wumpus.Basic.Geometry.Base
import Wumpus.Basic.Kernel
import Wumpus.Core
newtype InvTriangle u = InvTriangle { getInvTriangle :: Triangle u }
type DInvTriangle = InvTriangle Double
type instance DUnit (InvTriangle u) = u
mapTriangle :: (Triangle u -> Triangle u) -> InvTriangle u -> InvTriangle u
mapTriangle f = InvTriangle . f . getInvTriangle
instance Num u => Scale (InvTriangle u) where
scale sx sy = mapTriangle (scale sx sy)
instance Rotate (InvTriangle u) where
rotate ang = mapTriangle (rotate ang)
instance (Real u, Floating u) => RotateAbout (InvTriangle u) where
rotateAbout ang pt = mapTriangle (rotateAbout ang pt)
instance Num u => Translate (InvTriangle u) where
translate dx dy = mapTriangle (translate dx dy)
runRotateAnchor :: (Real u, Floating u)
=> (Triangle u -> Point2 u) -> InvTriangle u -> Point2 u
runRotateAnchor f (InvTriangle a) = rotateAbout pi (center a) (f a)
instance (Real u, Floating u) => CenterAnchor (InvTriangle u) where
center = center . getInvTriangle
instance (Real u, Floating u) => ApexAnchor (InvTriangle u) where
apex = runRotateAnchor apex
instance (Real u, Floating u) => TopCornerAnchor (InvTriangle u) where
topLeftCorner = runRotateAnchor bottomRightCorner
topRightCorner = runRotateAnchor bottomLeftCorner
instance (Real u, Floating u) => SideMidpointAnchor (InvTriangle u) where
sideMidpoint n a = step (n `mod` 3)
where
step 1 = midpoint (topRightCorner a) (topLeftCorner a)
step 2 = midpoint (topLeftCorner a) (apex a)
step _ = midpoint (apex a) (topRightCorner a)
instance (Real u, Floating u) => CardinalAnchor (InvTriangle u) where
north = runRotateAnchor south
south = runRotateAnchor north
east = runRotateAnchor west
west = runRotateAnchor east
instance (Real u, Floating u) => CardinalAnchor2 (InvTriangle u) where
northeast = runRotateAnchor southwest
southeast = runRotateAnchor northwest
southwest = runRotateAnchor northeast
northwest = runRotateAnchor southeast
instance (Real u, Floating u) => RadialAnchor (InvTriangle u) where
radialAnchor theta = runRotateAnchor (radialAnchor $ circularModulo $ pi+theta)
invtriangle :: (Real u, Floating u, FromPtSize u)
=> u -> u -> Shape u (InvTriangle u)
invtriangle bw h = fmap InvTriangle $ updatePathAngle (+ pi) $ triangle bw h