rishiag
rishiag

Reputation: 2274

How do I create list of point objects?

I want to use the following function in my program:

def computeVoronoiDiagram(points):
    """ Takes a list of point objects (which must have x and y fields).
Returns a 3-tuple of:

(1) a list of 2-tuples, which are the x,y coordinates of the
Voronoi diagram vertices
(2) a list of 3-tuples (a,b,c) which are the equations of the
lines in the Voronoi diagram: a*x + b*y = c
(3) a list of 3-tuples, (l, v1, v2) representing edges of the
Voronoi diagram. l is the index of the line, v1 and v2 are
the indices of the vetices at the end of the edge. If
v1 or v2 is -1, the line extends to infinity.
"""
    siteList = SiteList(points)
    context = Context()
    voronoi(siteList,context)
    return (context.vertices,context.lines,context.edges)

It says take a list of point objects (which have x & y field). Is it different than Python Lists data structures? How do I create such a object? Edit: I should mention list would contain about million random points.

Upvotes: 0

Views: 598

Answers (2)

theodox
theodox

Reputation: 12218

Does the library you're using contain a Point class?

If not:

 from collections import namedtuple
 Point = namedtuple('Point', ['x','y'])

Upvotes: 2

Crowman
Crowman

Reputation: 25926

Something like this:

#!/usr/bin/python

class Point:
    def __init__(self, x, y):
        self.x = x;
        self.y = y;

def main():
    pointslist = [Point(0, 0)] * 10
    mytuple = computeVoronoiDiagram(pointslist)

if __name__ == "__main__":
    main()

Obviously you'd need the rest of the code for computeVoronoiDiagram() and supporting code, and sounds like you'd want to randomize the x and y coords of each point, instead of setting them all to 0.

Upvotes: 1

Related Questions