Center the heart.

Former-commit-id: d81911ead26da403e7aa9fc0f3d56fc2cadae299
This commit is contained in:
David 2019-02-19 10:18:17 +01:00
commit 9e2cd55329
2 changed files with 36 additions and 2 deletions

View file

@ -474,7 +474,7 @@ mkBoundingBox svg = withStrokeColor "red" $ withFillOpacity 0 $
(x, y, w, h) = boundingBox svg
heartShape =
rotate 225 $ center $ mkPathString
center $ rotateAroundCenter 225 $ mkPathString
"M0.0,40.0 v-40.0 h40.0\
\a20.0 20.0 90.0 0 1 0.0,40.0\
\a20.0 20.0 90.0 0 1 -40.0,0.0 Z"

View file

@ -326,7 +326,6 @@ svgBoundingPoints t = map (Transform.transformPoint m) $
EllipseTree{} -> error "EllipseTree"
LineTree{} -> error "LineTree"
RectangleTree rect ->
-- toUserUnit defaultDPI x
case mapTuple (toUserUnit defaultDPI) (rect^.rectUpperLeftCorner) of
(Num x, Num y) -> [V2 x y] ++
case mapTuple (toUserUnit defaultDPI) (rect^.rectWidth, rect^.rectHeight) of
@ -359,12 +358,47 @@ rotate a = withTransformations [Rotate a Nothing]
rotateAround :: Double -> RPoint -> Tree -> Tree
rotateAround a (V2 x y) = withTransformations [Rotate a (Just (x,y))]
rotateAroundCenter :: Double -> Tree -> Tree
rotateAroundCenter a t =
rotateAround a (V2 (x+w/h) (y+h/2)) t
where
(x,y,w,h) = boundingBox t
scale :: Double -> Tree -> Tree
scale a = withTransformations [Scale a Nothing]
scaleXY :: Double -> Double -> Tree -> Tree
scaleXY x y = withTransformations [Scale x (Just y)]
-- scalePoints :: Double -> Tree -> Tree
-- scalePoints a = scalePointsXY a a
--
-- scalePointsXY :: Double -> Double -> Tree -> Tree
-- scalePointsXY x y = mapTree worker
-- where
-- worker t =
-- case t of
-- None -> t
-- UseTree{} -> t
-- GroupTree{} -> t
-- SymbolTree{} -> t
-- PathTree p -> PathTree $ p
-- & pathDefinition %~ lineToPath . map scaleCmd . toLineCommands
-- CircleTree{} -> error "scalePointsXY CircleTree"
-- PolyLineTree{} -> error "scalePointsXY PolyLineTree"
-- EllipseTree{} -> error "scalePointsXY EllipseTree"
-- LineTree{} -> error "scalePointsXY LineTree"
-- RectangleTree rect -> RectangleTree $ rect
-- & rectUpperLeftCorner %~ (mapNumber (*x) *** mapNumber (*y))
-- & rectWidth %~ mapNumber (*x)
-- & rectHeight %~ mapNumber (*y)
-- TextTree{} -> t
-- ImageTree{} -> t
-- MeshGradientTree{} -> t
-- scaleCmd (LineMove to) = LineMove (to * V2 x y)
-- scaleCmd (LineDraw to) = LineDraw (to * V2 x y)
-- scaleCmd (LineBezier points) = LineBezier (map (*V2 x y) points)
center :: Tree -> Tree
center t = translate (-x-w/2) (-y-h/2) t
where