OOF2: The Manual


Point — Python point class

Python Synopsis

import oof2.common.primitives
class Point:
  def __init__(self, x, y)
  def __getitem__(self, i)
  def __setitem__(self, i, val)
  def __mul__(self, other)
  def __rmul__(self, other)
  def __div__(self, factor)
  def __add__(self, other)
  def __sub__(self, other)
  def cross(self, other)
  def __cmp__(self, other)
  def __lt__(self, other)
  def __gt__(self, other)
  def __eq__(self, other)
  def __ne__(self, other)
  def __hash__(self)

Source Files

  • SRC/common/primitives.py: Python source code


Point is a pure Python class for representing points on a plane. It is equivalent to the C++ Coord class. The reason for having two classes is that there are situations in which it's desirable to avoid the overhead of calling C++ functions from Python, and in which the extra memory required to store a Python object is not important.


__init__(x, y)

Points are created by specifying their x and y components.

__getitem__(i), __setitem__(i, val)

A single component can be extracted with __getitem__ and set with __setitem__. point[0] is the x component and point[1] is the y component.

__mul__, __add__, etc.

The standard arithmetic operators are defined for Points. They can be added or subtracted from one another, and multiplied or divided by integers or floating point numbers. Multiplying two Points produces their dot product.


cross returns the cross product of a point with another point. The cross product is a scalar because Points are two dimensional vectors.

__cmp__, __eq__, __lt__, etc

The standard comparision operators are defined for Points. The inequalities establish an arbitrary order for them. The __hash__ function is provided so that Points can be used as dictionary keys.