blob: ad315e7a66072bda2452b44b7a605b3dbf22881f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
-- Copyright 2014 by Ida Bruhns
--
-- This file may be distributed and/or modified
--
-- 1. under the LaTeX Project Public License and/or
-- 2. under the GNU Public License
--
-- See the file doc/generic/pgf/licenses/LICENSE for more information
--- This is the parent class for initial layout algorithms. It provides a
-- constructor and methods stubs to be overwritten in the subclasses as well
-- as placing vertices which are |desired at| a certain point.
-- Imports
local lib = require "pgf.gd.lib"
local InitialTemplate = lib.class {}
-- constructor
function InitialTemplate:constructor()
self.vertices = self.vertices
self.options = self.options
self.desired_vertices = self.desired_vertices
end
-- Method placing |desired at| vertices at the point they are desired
--
-- @params desired_vertices A table containing all the vertices where the
-- |desired at| option is set.
--
-- @return |placed| A boolean array stating if vertices have been placed yet
-- @return |centroid_x| The x-coordinate of the midpoint of all placed vertices
-- @return |centroid_y| The y-coordinate of the midpoint of all placed vertices
function InitialTemplate:desired(desired_vertices)
local placed = {}
local centroid_x, centroid_y = 0, 0
local size = 0
for v, da in pairs(desired_vertices) do
local p = v.pos
local x, y = da.x, da.y
p.x = x or 0
p.y = y or 0
centroid_x = centroid_x + x
centroid_y = centroid_y + y
placed[v] = true
size = size +1
end
if size>0 then
centroid_x = centroid_x / size
centroid_y = centroid_y / size
end
return placed, centroid_x, centroid_y
end
-- Method stub for running the layout algorithm
function InitialTemplate:run()
end
return InitialTemplate
|