pycrossword  0.3
Pure-Python implementation of a crossword puzzle generator and editor
Public Member Functions | Public Attributes | List of all members
pycross.crossword.Coords Class Reference

This is a base class for word objects, basically consisting of a pair of (x, y) coordinates: the start coordinate given by Coords::start and the end coordinate given by Coords::end. More...

Inheritance diagram for pycross.crossword.Coords:
pycross.crossword.Word

Public Member Functions

def __init__ (self, coord_start, coord_end)
 The Coords constructor: initializes and validates Coords::start and Coords::end. More...
 
def validate (self)
 Validates the start and end coordinates passed to init(). More...
 
def coord_array (self)
 Outputs a list of (x,y) coordinates (2-tuples) between Coords::start and Coords::end. More...
 
def does_cross (self, coord)
 Checks if a coordinate lies anywhere between Coords::start and Coords::end. More...
 
def __len__ (self)
 Python len() overload: the distance between Coords::start and Coords::end. More...
 
def __repr__ (self)
 Python repr() overload: human-readable representation of Coords. More...
 

Public Attributes

 start
 2-tuple the start coordinate (x, y) More...
 
 end
 2-tuple the end coordinate (x, y) More...
 
 dir
 str direction of the start-to-end vector: 'h' = 'horizontal', 'v' = 'vertical' More...
 

Detailed Description

This is a base class for word objects, basically consisting of a pair of (x, y) coordinates: the start coordinate given by Coords::start and the end coordinate given by Coords::end.

All coordinates are given as 2-tuples (x, y): x = row, y = column (0-based)

Constructor & Destructor Documentation

◆ __init__()

def pycross.crossword.Coords.__init__ (   self,
  coord_start,
  coord_end 
)

The Coords constructor: initializes and validates Coords::start and Coords::end.

Parameters
coord_start2-tuple the start coordinate (x, y)
coord_end2-tuple the end coordinate (x, y)

Member Function Documentation

◆ __len__()

def pycross.crossword.Coords.__len__ (   self)

Python len() overload: the distance between Coords::start and Coords::end.

◆ __repr__()

def pycross.crossword.Coords.__repr__ (   self)

Python repr() overload: human-readable representation of Coords.

Reimplemented in pycross.crossword.Word.

◆ coord_array()

def pycross.crossword.Coords.coord_array (   self)

Outputs a list of (x,y) coordinates (2-tuples) between Coords::start and Coords::end.

Returns
list a list of coordinate 2-tuples beginning with Coords::start and ending with Coords::end

◆ does_cross()

def pycross.crossword.Coords.does_cross (   self,
  coord 
)

Checks if a coordinate lies anywhere between Coords::start and Coords::end.

Parameters
coord[tuple] the coordinate to check
Returns
bool True if coord crosses (lies between Coords::start and Coords::end), False otherwise

◆ validate()

def pycross.crossword.Coords.validate (   self)

Validates the start and end coordinates passed to init().

Exceptions
crossword::CWErrorat least one coordinate is incorrect (relevant to the other)

Member Data Documentation

◆ dir

pycross.crossword.Coords.dir

str direction of the start-to-end vector: 'h' = 'horizontal', 'v' = 'vertical'

◆ end

pycross.crossword.Coords.end

2-tuple the end coordinate (x, y)

◆ start

pycross.crossword.Coords.start

2-tuple the start coordinate (x, y)


The documentation for this class was generated from the following file: