<commit_before>'''a pythonic Point, foundation of Euclidean space.

XXX missing doc string
'''

import random
import math
import hashlib

from .constants import *
from .exceptions import *

class Point(object):
    '''
    A three dimensional Point initialized with x,y,z values
    supplied or the origin if no ordinates are given.

    But wait! There's more.  This hashable point is designed to be
    flexible and easy to use with a comprehensive set of operators and
    functions:
    
    Operations
    ----------

     +,  -,  *,  /,  //,  %, ** +=, -=, *=, /=, //=, %=, **==, ==, !=

    Operands can be other Point subclasses or scalar numbers.
    
    Methods
    -------

                ccw: counter-clockwise function, also know as:
                     "The beating red heart of computational geometry."

              cross: cross product of two points.
           distance: euclidean distance to another point.
    distanceSquared: euclidean distance squared, useful for ordering points.
                dot: dot product of two points.
          isBetween: xyz bounds checking a point between two other points.
                     see also: isBetweenX, is BetweenY, isBetweenZ
              isCCW: is this angle a counter-clockwise rotation?
        isCollinear: are these three points on a line?
           midpoint: point between two points on the line between them.

    Class Methods
    -------------

                     gaussian: Random point with gaussian distribution
               randomLocation: Random point within a circular bound
    randomLocationInRectangle: Random point within a rectangular bound
    

    Random Usage Examples
    ---------------------

    >>> from Geometry import Point
    >>> a = Point(x)
    >>> b = Point(x,y)
    >>> c = Point(x,y,z)
    >>> d = Point([x])
    >>> e = Point([x,y])
    >>> f = Point([x,y,z])
    >>> g = Point((x))
    >>> h = Point((x,y))
    >>> i = Point((x,y,z))
    >>> j = Point({'x':x,'y':y,'z':z})
    >>> k = Point(Point(...))
    >>> l = Point(x=x,y=y,z=z)
    >>> m = Point(<any object that defines attributes x,y,z>)
    >>> Origins = [Point(),Point(None),Point([0]*3),
    ...            Point([]),Point(()),Point({})]

    Points are just buckets to hold x, y and z values right?

    Get them any way you want them!

    >>> p = Point(range(0,3))
    >>> p.x, p.y, p.z, p.w
    (0.0, 1.0, 2.0, 1.0)
    >>> p.xyz
    [0.0, 1.0, 2.0]
    >>> p.xy, p.yz, p.xz
    ([0.0, 1.0], [1.0, 2.0], [0.0, 2.0])
    >>> p.xyzw
    [0.0, 1.0, 2.0, 1.0]

    Also, assignment:

    >>> p.xyz = [4,5,6]
    >>> p.xyz = [11] * 2
    >>> p
    [11.0, 11.0, 6.0]

    If fact, any construct you can use to initialize a Point object can
    be used to set any of the coordinate attributes.

    Want to find the average point for a group of 1000 random points?

    >>> manyPoints = [Point.gaussian() for x in range(0,1000)]
    >>> center = sum(manyPoints) / len(manyPoints)
    >>> type(center)
    <class 'Geometry.point.Point'>

    Go forth and geometer!

    Subclassing Notes:

    0 Initialization:

      Subclasses should always return an object initialized with
      origin coordinates if called with no arguments.  If not, things
      will break.

    '''
    ordinateNamesAll = 'xyzw'
    ordinateNamesXYZ = ordinateNamesAll[:3]
    ordinateNameX = ordinateNamesAll[0]
    ordinateNameY = ordinateNamesAll[1]
    ordinateNameZ = ordinateNamesAll[2]
    ordinateNameW = ordinateNamesAll[3]
    ordinateNamesXY = ordinateNameX+ordinateNameY
    ordinateNamesYZ = ordinateNameY+ordinateNameZ
    ordinateNamesXZ = ordinateNameX+ordinateNameZ


    @classmethod
    def gaussian(cls,mu=0,sigma=1):
        '''
        :param: mu    - mean
        :param: sigma - standard deviation

        Returns a point whose coordinates were picked from a Gaussian
        distribution with mean 'mu' and standard deviation 'sigma'.
        See random.gauss for further information on these parameters.

        '''
        return cls(random.gauss(mu,sigma),
                   random.gauss(mu,sigma),
                   random.gauss(mu,sigma))
        
    @classmethod
    def randomLocationInRectangle(cls,origin=None,width=1,height=1):
        '''
        :param: origin - optional Point subclass or Point initializer
        :param: width  - optional integer
        :param: height - optional integer
        :return: Point subclass

        Returns a Point with random x,y coordinates which are bounded
        by the rectangle defined by (origin,width,height).  

        If a rectangle is not supplied, a unit square with vertex A
        on the origin is used by default.

        '''
        
        origin = cls(origin)   # handles conversion of point initializers

        x = random.randint(O.x,origin.x+width)
        y = random.randint(O.y,origin.y+height)
            
        return cls(x,y,O.z)
    
    @classmethod
    def randomLocation(cls,origin=None,radius=1):
        '''
        :param: origin - optional Point subclass or Point initializer
        :param: radius - float<commit_msg>bug in randomLocationInRectangle<commit_after>'''a pythonic Point, foundation of Euclidean space.

XXX missing doc string
'''

import random
import math
import hashlib

from .constants import *
from .exceptions import *

class Point(object):
    '''
    A three dimensional Point initialized with x,y,z values
    supplied or the origin if no ordinates are given.

    But wait! There's more.  This hashable point is designed to be
    flexible and easy to use with a comprehensive set of operators and
    functions:
    
    Operations
    ----------

     +,  -,  *,  /,  //,  %, ** +=, -=, *=, /=, //=, %=, **==, ==, !=

    Operands can be other Point subclasses or scalar numbers.
    
    Methods
    -------

                ccw: counter-clockwise function, also know as:
                     "The beating red heart of computational geometry."

              cross: cross product of two points.
           distance: euclidean distance to another point.
    distanceSquared: euclidean distance squared, useful for ordering points.
                dot: dot product of two points.
          isBetween: xyz bounds checking a point between two other points.
                     see also: isBetweenX, is BetweenY, isBetweenZ
              isCCW: is this angle a counter-clockwise rotation?
        isCollinear: are these three points on a line?
           midpoint: point between two points on the line between them.

    Class Methods
    -------------

                     gaussian: Random point with gaussian distribution
               randomLocation: Random point within a circular bound
    randomLocationInRectangle: Random point within a rectangular bound
    

    Random Usage Examples
    ---------------------

    >>> from Geometry import Point
    >>> a = Point(x)
    >>> b = Point(x,y)
    >>> c = Point(x,y,z)
    >>> d = Point([x])
    >>> e = Point([x,y])
    >>> f = Point([x,y,z])
    >>> g = Point((x))
    >>> h = Point((x,y))
    >>> i = Point((x,y,z))
    >>> j = Point({'x':x,'y':y,'z':z})
    >>> k = Point(Point(...))
    >>> l = Point(x=x,y=y,z=z)
    >>> m = Point(<any object that defines attributes x,y,z>)
    >>> Origins = [Point(),Point(None),Point([0]*3),
    ...            Point([]),Point(()),Point({})]

    Points are just buckets to hold x, y and z values right?

    Get them any way you want them!

    >>> p = Point(range(0,3))
    >>> p.x, p.y, p.z, p.w
    (0.0, 1.0, 2.0, 1.0)
    >>> p.xyz
    [0.0, 1.0, 2.0]
    >>> p.xy, p.yz, p.xz
    ([0.0, 1.0], [1.0, 2.0], [0.0, 2.0])
    >>> p.xyzw
    [0.0, 1.0, 2.0, 1.0]

    Also, assignment:

    >>> p.xyz = [4,5,6]
    >>> p.xyz = [11] * 2
    >>> p
    [11.0, 11.0, 6.0]

    If fact, any construct you can use to initialize a Point object can
    be used to set any of the coordinate attributes.

    Want to find the average point for a group of 1000 random points?

    >>> manyPoints = [Point.gaussian() for x in range(0,1000)]
    >>> center = sum(manyPoints) / len(manyPoints)
    >>> type(center)
    <class 'Geometry.point.Point'>

    Go forth and geometer!

    Subclassing Notes:

    0 Initialization:

      Subclasses should always return an object initialized with
      origin coordinates if called with no arguments.  If not, things
      will break.

    '''
    ordinateNamesAll = 'xyzw'
    ordinateNamesXYZ = ordinateNamesAll[:3]
    ordinateNameX = ordinateNamesAll[0]
    ordinateNameY = ordinateNamesAll[1]
    ordinateNameZ = ordinateNamesAll[2]
    ordinateNameW = ordinateNamesAll[3]
    ordinateNamesXY = ordinateNameX+ordinateNameY
    ordinateNamesYZ = ordinateNameY+ordinateNameZ
    ordinateNamesXZ = ordinateNameX+ordinateNameZ


    @classmethod
    def gaussian(cls,mu=0,sigma=1):
        '''
        :param: mu    - mean
        :param: sigma - standard deviation

        Returns a point whose coordinates were picked from a Gaussian
        distribution with mean 'mu' and standard deviation 'sigma'.
        See random.gauss for further information on these parameters.

        '''
        return cls(random.gauss(mu,sigma),
                   random.gauss(mu,sigma),
                   random.gauss(mu,sigma))
        
    @classmethod
    def randomLocationInRectangle(cls,origin=None,width=1,height=1):
        '''
        :param: origin - optional Point subclass or Point initializer
        :param: width  - optional integer
        :param: height - optional integer
        :return: Point subclass

        Returns a Point with random x,y coordinates which are bounded
        by the rectangle defined by (origin,width,height).  

        If a rectangle is not supplied, a unit square with vertex A
        on the origin is used by default.

        '''
        
        origin = cls(origin)   # handles conversion of point initializers

        x = random.randint(origin.x,origin.x+width)
        y = random.randint(origin.y,origin.y+height)
            
        return cls(x,y,origin.z)
    
    @classmethod
    def randomLocation(cls,origin=None,radius=1):
        '''
        :param: origin - optional Point subclass or Point initializer
        :param: radius - float
{'fraction_non_alphanumeric': 0.12127742946708464, 'fraction_numerical': 0.014106583072100314, 'mean_word_length': 2.2235554152194505, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 163, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2529077', 'n_tokens_mistral': 3157, 'n_tokens_neox': 2946, 'n_words': 991}