File: noise.h

package info (click to toggle)
python-pyglm 2.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,008 kB
  • sloc: cpp: 53,029; python: 3,683; makefile: 7
file content (125 lines) | stat: -rw-r--r-- 4,019 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#pragma once

#include "../../compiler_setup.h"

#include "../../types/all.h"

#include "../../internal_functions/all.h"

static PyObject*
perlin_(PyObject*, PyObject* args) {
	PyObject *arg1, *arg2 = NULL;
	if (!PyArg_UnpackTuple(args, "perlin", 1, 2, &arg1, &arg2)) {
		PyErr_SetString(PyExc_TypeError, "invalid argument type(s) for perlin()");
		return NULL;
	}
	if (arg2 != NULL) {
		PyGLM_PTI_Init0(arg1, PyGLM_T_VEC | PyGLM_SHAPE_2 | PyGLM_SHAPE_3 | PyGLM_SHAPE_4 | PyGLM_DT_FD);
		PyGLM_PTI_Init1(arg2, PyGLM_T_VEC | PyGLM_SHAPE_2 | PyGLM_SHAPE_3 | PyGLM_SHAPE_4 | PyGLM_DT_FD);
		if (PyGLM_Vec_PTI_Check0(2, float, arg1) && PyGLM_Vec_PTI_Check1(2, float, arg2)) {
			PyGLM_Vec_PTI_Assign0(2, float);
			PyGLM_Vec_PTI_Assign1(2, float);
			return pack(glm::perlin(o, o2));
		}
		if (PyGLM_Vec_PTI_Check0(3, float, arg1) && PyGLM_Vec_PTI_Check1(3, float, arg2)) {
			PyGLM_Vec_PTI_Assign0(3, float);
			PyGLM_Vec_PTI_Assign1(3, float);
			return pack(glm::perlin(o, o2));
		}
		if (PyGLM_Vec_PTI_Check0(4, float, arg1) && PyGLM_Vec_PTI_Check1(4, float, arg2)) {
			PyGLM_Vec_PTI_Assign0(4, float);
			PyGLM_Vec_PTI_Assign1(4, float);
			return pack(glm::perlin(o, o2));
		}
		if (PyGLM_Vec_PTI_Check0(2, double, arg1) && PyGLM_Vec_PTI_Check1(2, double, arg2)) {
			PyGLM_Vec_PTI_Assign0(2, double);
			PyGLM_Vec_PTI_Assign1(2, double);
			return pack(glm::perlin(o, o2));
		}
		if (PyGLM_Vec_PTI_Check0(3, double, arg1) && PyGLM_Vec_PTI_Check1(3, double, arg2)) {
			PyGLM_Vec_PTI_Assign0(3, double);
			PyGLM_Vec_PTI_Assign1(3, double);
			return pack(glm::perlin(o, o2));
		}
		if (PyGLM_Vec_PTI_Check0(4, double, arg1) && PyGLM_Vec_PTI_Check1(4, double, arg2)) {
			PyGLM_Vec_PTI_Assign0(4, double);
			PyGLM_Vec_PTI_Assign1(4, double);
			return pack(glm::perlin(o, o2));
		}
	}
	else {
		PyGLM_PTI_Init0(arg1, PyGLM_T_VEC | PyGLM_SHAPE_2 | PyGLM_SHAPE_3 | PyGLM_SHAPE_4 | PyGLM_DT_FD);
		if (PyGLM_Vec_PTI_Check0(2, float, arg1)) {
			PyGLM_Vec_PTI_Assign0(2, float);
			return pack(glm::perlin(o));
		}
		if (PyGLM_Vec_PTI_Check0(3, float, arg1)) {
			PyGLM_Vec_PTI_Assign0(3, float);
			return pack(glm::perlin(o));
		}
		if (PyGLM_Vec_PTI_Check0(4, float, arg1)) {
			PyGLM_Vec_PTI_Assign0(4, float);
			return pack(glm::perlin(o));
		}
		if (PyGLM_Vec_PTI_Check0(2, double, arg1)) {
			PyGLM_Vec_PTI_Assign0(2, double);
			return pack(glm::perlin(o));
		}
		if (PyGLM_Vec_PTI_Check0(3, double, arg1)) {
			PyGLM_Vec_PTI_Assign0(3, double);
			return pack(glm::perlin(o));
		}
		if (PyGLM_Vec_PTI_Check0(4, double, arg1)) {
			PyGLM_Vec_PTI_Assign0(4, double);
			return pack(glm::perlin(o));
		}
	}
	PyErr_SetString(PyExc_TypeError, "invalid argument type(s) for perlin()");
	return NULL;
}

static PyObject*
simplex_(PyObject*, PyObject* arg) {
	PyGLM_PTI_Init0(arg, PyGLM_T_VEC | PyGLM_SHAPE_2 | PyGLM_SHAPE_3 | PyGLM_SHAPE_4 | PyGLM_DT_FD);
	if (PyGLM_Vec_PTI_Check0(2, float, arg)) {
		PyGLM_Vec_PTI_Assign(2, float);
		return pack(glm::simplex(o));
	}
	if (PyGLM_Vec_PTI_Check0(3, float, arg)) {
		PyGLM_Vec_PTI_Assign(3, float);
		return pack(glm::simplex(o));
	}
	if (PyGLM_Vec_PTI_Check0(4, float, arg)) {
		PyGLM_Vec_PTI_Assign(4, float);
		return pack(glm::simplex(o));
	}
	if (PyGLM_Vec_PTI_Check0(2, double, arg)) {
		PyGLM_Vec_PTI_Assign(2, double);
		return pack(glm::simplex(o));
	}
	if (PyGLM_Vec_PTI_Check0(3, double, arg)) {
		PyGLM_Vec_PTI_Assign(3, double);
		return pack(glm::simplex(o));
	}
	if (PyGLM_Vec_PTI_Check0(4, double, arg)) {
		PyGLM_Vec_PTI_Assign(4, double);
		return pack(glm::simplex(o));
	}
	PyGLM_TYPEERROR_O("invalid argument type for simplex(): ", arg);
	return NULL;
}

PyDoc_STRVAR(perlin_docstr, 
	"perlin(p: vecN) -> float\n"
	"	Classic perlin noise.\n"
	"perlin(p: vecN, rep: vecN) -> float\n"
	"	Periodic perlin noise."
);
PyDoc_STRVAR(simplex_docstr,
	"simplex(p: vecN) -> float\n"
	"	Simplex noise."
);

#define NOISE_METHODS \
{ "perlin", (PyCFunction)perlin_, METH_VARARGS, perlin_docstr }, \
{ "simplex", (PyCFunction)simplex_, METH_O, simplex_docstr }