File: pg_geometry.py

package info (click to toggle)
py-postgresql 1.2.1%2Bgit20180803.ef7b9a9-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,620 kB
  • sloc: python: 18,317; ansic: 2,024; sql: 282; sh: 26; makefile: 22
file content (43 lines) | stat: -rw-r--r-- 1,284 bytes parent folder | download | duplicates (4)
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
from .. import POINTOID, BOXOID, LSEGOID, CIRCLEOID
from ..geometry import Point, Box, Lseg, Circle
from ...python.functools import Composition as compose
from . import lib

oid_to_type = {
	POINTOID: Point,
	BOXOID: Box,
	LSEGOID: Lseg,
	CIRCLEOID: Circle,
}

# Make a pair of pairs out of a sequence of four objects
def two_pair(x):
	return ((x[0], x[1]), (x[2], x[3]))

point_pack = lib.point_pack
point_unpack = compose((lib.point_unpack, Point))

def box_pack(x):
	return lib.box_pack((x[0][0], x[0][1], x[1][0], x[1][1]))
box_unpack = compose((lib.box_unpack, two_pair, Box,))

def lseg_pack(x, pack = lib.lseg_pack):
	return pack((x[0][0], x[0][1], x[1][0], x[1][1]))
lseg_unpack = compose((lib.lseg_unpack, two_pair, Lseg))

def circle_pack(x):
	return lib.circle_pack((x[0][0], x[0][1], x[1]))
def circle_unpack(x, unpack = lib.circle_unpack, Circle = Circle):
	x = unpack(x)
	return Circle(((x[0], x[1]), x[2]))

# Map type oids to a (pack, unpack) pair.
oid_to_io = {
	POINTOID : (point_pack, point_unpack, Point),
	BOXOID : (box_pack, box_unpack, Box),
	LSEGOID : (lseg_pack, lseg_unpack, Lseg),
	CIRCLEOID : (circle_pack, circle_unpack, Circle),
	#PATHOID : (path_pack, path_unpack),
	#POLYGONOID : (polygon_pack, polygon_unpack),
	#LINEOID : (line_pack, line_unpack),
}