12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- # -*- coding:utf-8 -*-
- ##
- # This file is part of connectSVG.
- #
- # connectSVG is free software: you can redistribute it and/or modify it
- # under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License,
- # or (at your option) any later version.
- #
- # connectSVG is distributed in the hope that it will be useful, but WITHOUT ANY
- # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- # details.
- #
- # You should have received a copy of the GNU General Public License along
- # with connectSVG. If not, see <https://www.gnu.org/licenses/>.
- ##
- import logging
- log = logging.getLogger("connectsvg")
- def orderPaths(paths, attributes) :
- orderedPaths = []
- orderedAttributes = []
- last = 0j
- while len(paths) > 0 :
- minDist = 1000000000000
- place = -1
- for i in range(len(paths)) :
- path = paths[i]
- dist = abs(path.start.real-last.real) + abs(path.start.imag-last.imag)
- if minDist > dist :
- minDist = dist
- place = i
- last = paths[place].start
- orderedPaths.append(paths.pop(place))
- orderedAttributes.append(attributes.pop(place))
- return orderedPaths, orderedAttributes
|