
    hH;                     ,   S r SrSSKJrJrJr  SSKJr  SrSr	Sr
S\" S	5      S
-
  -  rS	\" S	5      -
  S-  rSrSrSr " S S5      r " S S\5      rS rS r " S S\5      r\" 5       r\R,                  r\R0                  r\" 5       r\R0                  rg)a?  Noise functions for procedural generation of content

Contains native code implementations of Perlin improved noise (with
fBm capabilities) and Perlin simplex noise. Also contains a fast
"fake noise" implementation in GLSL for execution in shaders.

Copyright (c) 2008, Casey Duncan (casey dot duncan at gmail dot com)
z1.2.1    )floorfmodsqrt)randint)   r   r   r   r   )r   r
   r   )r
   r
   r   )r   r   r   )r
   r   r   )r   r   r
   )r
   r   r
   )r   r   r   r   r
   r   )r   r   r
   r   r
   r
   r   r   r	   r   ) )r   r   r   r   )r   r   r   r
   )r   r   r
   r   )r   r   r
   r
   )r   r
   r   r   )r   r
   r   r
   )r   r
   r
   r   )r   r
   r
   r
   )r   r   r   r   )r   r   r   r
   )r   r   r
   r   )r   r   r
   r
   )r
   r   r   r   )r
   r   r   r
   )r
   r   r
   r   )r
   r   r
   r
   )r   r   r   r   )r   r   r   r
   )r   r
   r   r   )r   r
   r   r
   )r
   r   r   r   )r
   r   r   r
   )r
   r
   r   r   )r
   r
   r   r
   )r   r   r   r   )r   r   r
   r   )r   r
   r   r   )r   r
   r
   r   )r
   r   r   r   )r
   r   r
   r   )r
   r
   r   r   )r
   r
   r
   r   )@)r   r         )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   r   )r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   r   )r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   r   r   )r   r   r   r   )r   r   r   r         ?      @      ?g      @gUUUUUU?gUUUUUU?(            [   Z               _   `   5                  $   g      E         c   %         
                  x      K   r         >   ^            u   #          9      !   X         8   W         }            D      J      G         0         M            S   o      z   <               i   \   )   7   .      (      f      6   A      ?      r      P   I      L            Y                     t         V      d   m            r   @   4            |   {         &      v   ~      R   U            ;      /      :               *               w         r   ,         F         e         +      	         '      r   b   l   n   O   q               p   h         a         "                                 Q   3                  k   1                  j         T         s   y   2   -                        ]      r   C         H               N   B      =         c                   F    \ rS rSrSr\" \5      r\S-  rSS jr	S	S jr
Srg)
	BaseNoiserE   zNoise abstract base classr   Nc                     Ub  Ub  [        S5      eUb  U R                  U5        gUb$  [        U5      S-  U l        [	        U5      U l        gg)a,  Initialize the noise generator. With no arguments, the default
period and permutation table are used (256). The default permutation
table generates the exact same noise pattern each time.

An integer period can be specified, to generate a random permutation
table with period elements. The period determines the (integer)
interval that the noise repeats, which is useful for creating tiled
textures.  period should be a power-of-two, though this is not
enforced. Note that the speed of the noise algorithm is independent of
the period size, though larger periods mean a larger table, which
consume more memory.

A permutation table consisting of an iterable sequence of whole
numbers can be specified directly. This should have a power-of-two
length. Typical permutation tables are a sequence of unique integers in
the range [0,period) in random order, though other arrangements could
prove useful, they will not be "pure" simplex noise. The largest
element in the sequence must be no larger than period-1.

period and permutation_table may not be specified together.
Nz8Can specify either period or permutation_table, not bothr   )
ValueError	randomizetuplepermutationlenperiod)selfr  permutation_tables      C/var/www/html/env/lib/python3.13/site-packages/ezdxf/math/perlin.py__init__BaseNoise.__init__^   s_    , "3"?J  NN6"*$%67!;D/0DK +    c                     Ub  Xl         [        [        U R                   5      5      nU R                   S-
  n[        U5       H  n[        SU5      nX%   X$   sX$'   X%'   M     [	        U5      S-  U l        g)zRandomize the permutation table used by the noise functions. This
makes them generate a different noise pattern for the same inputs.
Nr   r   r   )r  listranger   r  r  )r  r  perm
perm_rightijs         r  r  BaseNoise.randomize~   so      KE$++&'[[1_
dA:&A#wDGTW  !;?r  )r  r  )NNN)__name__
__module____qualname____firstlineno____doc__r  _permutationr  r  r  r  __static_attributes__ r  r  r  r  X   s$    #F"K1@+r  r  c                   $    \ rS rSrSrS rS rSrg)SimplexNoiser#   a  Perlin simplex noise generator

Adapted from Stefan Gustavson's Java implementation described here:

http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf

To summarize:

"In 2001, Ken Perlin presented 'simplex noise', a replacement for his classic
noise algorithm.  Classic 'Perlin noise' won him an academy award and has
become an ubiquitous procedural primitive for computer graphics over the
years, but in hindsight it has quite a few limitations.  Ken Perlin himself
designed simplex noise specifically to overcome those limitations, and he
spent a lot of good thinking on it. Therefore, it is a better idea than his
original algorithm. A few of the more prominent advantages are:

* Simplex noise has a lower computational complexity and requires fewer
  multiplications.
* Simplex noise scales to higher dimensions (4D, 5D and up) with much less
  computational cost, the complexity is O(N) for N dimensions instead of
  the O(2^N) of classic Noise.
* Simplex noise has no noticeable directional artifacts.  Simplex noise has
  a well-defined and continuous gradient everywhere that can be computed
  quite cheaply.
* Simplex noise is easy to implement in hardware."
c                 :   X-   [         -  n[        X-   5      n[        X#-   5      nXE-   [        -  nXU-
  -
  nX%U-
  -
  nXx:  a  Sn	Sn
OSn	Sn
Xy-
  [        -   nX-
  [        -   nU[        S-  -   S-
  nU[        S-  -   S-
  nU R                  n[	        U5      U R
                  -  n[	        U5      U R
                  -  nUUUU   -      S-  nUUU	-   UUU
-      -      S-  nUUS-   UUS-      -      S-  nSUS-  -
  US-  -
  nUS:  a!  [        U   nUS-  US   U-  US   U-  -   -  nOS	nSUS-  -
  US-  -
  nUS:  a#  [        U   nUUS-  US   U-  US   U-  -   -  -  nSUS-  -
  US-  -
  nUS:  a#  [        U   nUUS-  US   U-  US   U-  -   -  -  nUS
-  $ )z2D Perlin simplex noise.

Return a floating point value from -1 to 1 for the given x, y coordinate.
The same value is always returned for a given x, y pair unless the
permutation table changes (see randomize above).
r   r          @r   r   r   r   r           g     Q@)_F2r   _G2r  intr  _GRAD3)r  xysr"  r#  tx0y0i1j1x1y1x2y2r   iijjgi0gi1gi2ttgnoises                           r  noise2SimplexNoise.noise2   s    UcM!%L!%LUcMa%[a%[7BBBBWs]Ws]sNS  	 #)^c! Vdkk!Vdkk!2R=!B&27T"r']*+b026DaL()B. 27]R1W$6sA!Gqtby1Q4"945EE27]R1W$6sAR1W!r	AaD2I 566E27]R1W$6sAR1W!r	AaD2I 566Et|r  c                 .   X-   U-   [         -  n[        X-   5      n[        X$-   5      n[        X4-   5      nXV-   U-   [        -  nXU-
  -
  n	X&U-
  -
  n
X7U-
  -
  nX:  a1  X:  a  SnSnSnSnSnSnOOX:  a  SnSnSnSnSnSnO=SnSnSnSnSnSnO0X:  a  SnSnSnSnSnSnOX:  a  SnSnSnSnSnSnOSnSnSnSnSnSnX-
  [        -   nX-
  [        -   nX-
  [        -   nX-
  S[        -  -   nU
U-
  S[        -  -   nUU-
  S[        -  -   nU	S-
  S[        -  -   nU
S-
  S[        -  -   nUS-
  S[        -  -   nU R                  n[	        U5      U R
                  -  n[	        U5      U R
                  -  n[	        U5      U R
                  -  nUUUUUU   -      -      S-  nUUU-   UUU-   UUU-      -      -      S-  n UUU-   UUU-   UUU-      -      -      S-  n!UUS-   UUS-   UUS-      -      -      S-  n"Sn#SU	S	-  -
  U
S	-  -
  US	-  -
  n$U$S:  a*  [        U   n%U$S
-  U%S   U	-  U%S   U
-  -   U%S	   U-  -   -  n#OSn#SUS	-  -
  US	-  -
  US	-  -
  n$U$S:  a,  [        U    n%U#U$S
-  U%S   U-  U%S   U-  -   U%S	   U-  -   -  -  n#SUS	-  -
  US	-  -
  US	-  -
  n$U$S:  a,  [        U!   n%U#U$S
-  U%S   U-  U%S   U-  -   U%S	   U-  -   -  -  n#SUS	-  -
  US	-  -
  US	-  -
  n$U$S:  a,  [        U"   n%U#U$S
-  U%S   U-  U%S   U-  -   U%S	   U-  -   -  -  n#U#S-  $ )z3D Perlin simplex noise.

Return a floating point value from -1 to 1 for the given x, y, z coordinate.
The same value is always returned for a given x, y, z pair unless the
permutation table changes (see randomize above).
r   r   r1  r   r   r   r2  g333333?r   r   g      @@)_F3r   _G3r  r5  r  r6  )&r  r7  r8  zr9  r"  r#  kr:  r;  r<  z0r=  r>  k1i2j2k2r?  r@  z1rA  rB  z2x3y3z3r   rC  rD  kkrE  rF  rG  gi3rJ  rH  rI  s&                                         r  noise3SimplexNoise.noise3   sQ    UQY#!%L!%L!%LUQY#a%[a%[a%[ 8xw Ws]Ws]Ws]WsSy "WsSy "WsSy #Xc	!#Xc	!#Xc	! Vdkk!Vdkk!Vdkk!2R$r(]++,r127T"r'DbM"9::;b@27T"r'DbM"9::;b@26Da$rAv,!67782= 27]R1W$rQw.6sA!Gqtby1Q4"94qtby@AEE27]R1W$rQw.6sAR1W!r	AaD2I 5!r	 ABBE27]R1W$rQw.6sAR1W!r	AaD2I 5!r	 ABBE27]R1W$rQw.6sAR1W!r	AaD2I 5!r	 ABBEt|r  r-  N)r&  r'  r(  r)  r*  rK  r^  r,  r-  r  r  r/  r/     s    67rmr  r/  c                     XX!-
  -  -   $ r%  r-  )r:  abs      r  lerprc  Q  s    AE{?r  c                 H    [         U S-     nXS   -  X$S   -  -   X4S   -  -   $ )Nr   r   r   r   )r6  )hashr7  r8  rP  rI  s        r  grad3rf  U  s2    tbyAt8aA$hqT))r  c                   "    \ rS rSrSrSS jrSrg)TileableNoiseiZ  zTileable implementation of Perlin "improved" noise. This
is based on the reference implementation published here:

http://mrl.nyu.edu/~perlin/noise/
c                 L   [        [        [        U5      U5      5      n[        [        [        U5      U5      5      n[        [        [        U5      U5      5      nUS-   U-  n	US-   U-  n
US-   U-  nU(       a  Xe-  nXu-  nX-  nX-  n	X-  n
X-  nU[        U5      -  nU[        U5      -  nU[        U5      -  nUS-  XS-  S-
  -  S-   -  nUS-  X"S-  S-
  -  S-   -  nUS-  X3S-  S-
  -  S-   -  nU R                  nX   nUUU-      nUUU
-      nX   nUUU-      nUUU
-      n[	        U[	        U[	        U[        UUU-      XU5      [        UUU-      US-
  X#5      5      [	        U[        UUU-      XS-
  U5      [        UUU-      US-
  US-
  U5      5      5      [	        U[	        U[        UUU-      XUS-
  5      [        UUU-      US-
  X#S-
  5      5      [	        U[        UUU-      XS-
  US-
  5      [        UUU-      US-
  US-
  US-
  5      5      5      5      $ )zTileable 3D noise.

repeat specifies the integer interval in each dimension
when the noise pattern repeats.

base allows a different texture to be generated for
the same repeat interval.
r   r   r1   r   r.   )r5  r   r   r  rc  rf  )r  r7  r8  rP  repeatbaser"  r#  rQ  rC  rD  r\  fxfyfzr   AAAABBBABBs                         r  r^  TileableNoise.noise3a  s    U1Xv&'U1Xv&'U1Xv&'!ev!ev!evIAIAIAJBJBJB	U1X	U1X	U1X!VqEBJ'",-!VqEBJ'",-!VqEBJ'",-G!a%[!b&\H!a%[!b&\$rAv,a0$rAv,Aq4
 $rAv,q5!4$rAv,Aq1ua8 $rBw-q1u5$rBw-Qq59
 $rBw-E1q59$rBw-QAq1u=
 	
r  r-  N)r2  )r&  r'  r(  r)  r*  r^  r,  r-  r  r  rh  rh  Z  s    B
r  rh  N)r*  __version__mathr   r   r   randomr   r6  _GRAD4_SIMPLEXr3  r4  rN  rO  r+  r  r/  rc  rf  rh  _simplexrK  snoise2r^  snoise3	_tileabletnoise3r-  r  r  <module>r     s     " " 
	
" 
T#Y_
T#Y#,1+ 1+hB9 BJ*
I
I I
X >
//
//O	


r  