--- Decorate something given by its bounding box with a given deco
--- object, which needs to be a path.
-function decorate(model, bbox, deco)
- if (deco:type() ~= "path") then
- report_problem(model, "The decoration needs to be a path.")
- return
- end
-
- local shape = deco:shape()
- local m = deco:matrix()
- for _,path in pairs(shape) do
- for _,subpath in ipairs(path) do
- -- move all points
- for i,point in ipairs(subpath) do
- subpath[i] = translation(bbox, m*point) * m*point
- end
-
- -- for acs, the center must be translated separately
- if (subpath["type"] == "arc") then
- local arc = subpath["arc"]
- local arc_pos = arc:matrix():translation()
- subpath["arc"] = translation(bbox, m*arc_pos) * m * arc
- end
- end
- end
- -- update model
- deco:setShape(shape)
- deco:setMatrix(ipe.Matrix())
- model:creation("create", deco)
-end
-
--- The translation matrix that should be applied to a given point when
--- doing the decoration.
-function translation(bbox, point)
- local dx = 0
- local dy = 0
- if (point.x > 0) then
- dx = dx + bbox:width()
- end
- if (point.y > 0) then
- dy = dy + bbox:height()
- end
- dx = dx + bbox:left()
- dy = dy + bbox:bottom()
- return ipe.Translation(dx, dy)
-end
-