Blender V4.3
scene/curves.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "scene/curves.h"
6#include "device/device.h"
7#include "scene/mesh.h"
8#include "scene/object.h"
9#include "scene/scene.h"
10
11#include "util/foreach.h"
12#include "util/map.h"
13#include "util/progress.h"
14#include "util/vector.h"
15
17
18/* Curve functions */
19
20void curvebounds(float *lower, float *upper, float3 *p, int dim)
21{
22 float *p0 = &p[0].x;
23 float *p1 = &p[1].x;
24 float *p2 = &p[2].x;
25 float *p3 = &p[3].x;
26
27 /* Catmull-Rom weights. */
28 float curve_coef[4];
29 curve_coef[0] = p1[dim];
30 curve_coef[1] = 0.5f * (-p0[dim] + p2[dim]);
31 curve_coef[2] = 0.5f * (2 * p0[dim] - 5 * p1[dim] + 4 * p2[dim] - p3[dim]);
32 curve_coef[3] = 0.5f * (-p0[dim] + 3 * p1[dim] - 3 * p2[dim] + p3[dim]);
33
34 float discroot = curve_coef[2] * curve_coef[2] - 3 * curve_coef[3] * curve_coef[1];
35 float ta = -1.0f;
36 float tb = -1.0f;
37
38 if (discroot >= 0 && curve_coef[3] != 0.0f) {
39 discroot = sqrtf(discroot);
40 ta = (-curve_coef[2] - discroot) / (3 * curve_coef[3]);
41 tb = (-curve_coef[2] + discroot) / (3 * curve_coef[3]);
42 ta = (ta > 1.0f || ta < 0.0f) ? -1.0f : ta;
43 tb = (tb > 1.0f || tb < 0.0f) ? -1.0f : tb;
44 }
45
46 *upper = max(p1[dim], p2[dim]);
47 *lower = min(p1[dim], p2[dim]);
48
49 float exa = p1[dim];
50 float exb = p2[dim];
51
52 if (ta >= 0.0f) {
53 float t2 = ta * ta;
54 float t3 = t2 * ta;
55 exa = curve_coef[3] * t3 + curve_coef[2] * t2 + curve_coef[1] * ta + curve_coef[0];
56 }
57 if (tb >= 0.0f) {
58 float t2 = tb * tb;
59 float t3 = t2 * tb;
60 exb = curve_coef[3] * t3 + curve_coef[2] * t2 + curve_coef[1] * tb + curve_coef[0];
61 }
62
63 *upper = max(*upper, max(exa, exb));
64 *lower = min(*lower, min(exa, exb));
65}
66
#define CCL_NAMESPACE_END
#define sqrtf(x)
CCL_NAMESPACE_BEGIN void curvebounds(float *lower, float *upper, float3 *p, int dim)
#define min(a, b)
Definition sort.c:32
float x
Definition sky_float3.h:27
float max