diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-08-23 18:37:22 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-08-23 18:37:22 +0400 |
commit | 09ff49755fc84a0dd4214099a0dd47facba83288 (patch) | |
tree | e317ad76b20daf06484a4e76004030cf0a5fc921 /source | |
parent | 01e22d1b9f3606d97f06c2d8a2bc969214322e9c (diff) |
math api edits - replace point-normal form for a plane with dist_to_plane_v3()
also correct python mathutils api, was missing vector checks.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/camera.c | 7 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 3 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 24 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_tools.c | 7 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_geometry.c | 24 |
5 files changed, 40 insertions, 25 deletions
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index f9444ca2cf9..d92a9220b4f 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -456,6 +456,7 @@ void BKE_camera_view_frame(Scene *scene, Camera *camera, float r_vec[4][3]) typedef struct CameraViewFrameData { + float plane_tx[4][4]; /* 4 planes (not 4x4 matrix)*/ float frame_tx[4][3]; float normal_tx[4][3]; float dist_vals[4]; @@ -468,7 +469,7 @@ static void camera_to_frame_view_cb(const float co[3], void *user_data) unsigned int i; for (i = 0; i < 4; i++) { - float nd = dist_to_plane_v3(co, data->frame_tx[i], data->normal_tx[i]); + float nd = dist_to_plane_v3(co, data->plane_tx[i]); if (nd < data->dist_vals[i]) { data->dist_vals[i] = nd; } @@ -514,8 +515,8 @@ int BKE_camera_view_frame_fit_to_scene(Scene *scene, struct View3D *v3d, Object } for (i = 0; i < 4; i++) { - normal_tri_v3(data_cb.normal_tx[i], - zero, data_cb.frame_tx[i], data_cb.frame_tx[(i + 1) % 4]); + normal_tri_v3(data_cb.normal_tx[i], zero, data_cb.frame_tx[i], data_cb.frame_tx[(i + 1) % 4]); + plane_from_point_normal_v3(data_cb.plane_tx[i], data_cb.frame_tx[i], data_cb.normal_tx[i]); } /* initialize callback data */ diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index 4a43873f070..383ab6b2533 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -81,8 +81,7 @@ float dist_squared_to_line_segment_v2(const float p[2], const float l1[2], const float dist_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2]); void closest_to_line_segment_v2(float closest[2], const float p[2], const float l1[2], const float l2[2]); -float dist_to_plane_normalized_v3(const float p[3], const float plane_co[3], const float plane_no_unit[3]); -float dist_to_plane_v3(const float p[3], const float plane_co[3], const float plane_no[3]); +float dist_to_plane_v3(const float p[3], const float plane[4]); float dist_squared_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3]); float dist_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3]); float dist_to_line_v3(const float p[3], const float l1[3], const float l2[3]); diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 2b5b0c5d0d2..1bf7b1f6a9a 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -321,25 +321,17 @@ void closest_to_plane_v3(float close_r[3], const float plane[4], const float pt[ madd_v3_v3v3fl(close_r, pt, plane, -side / length); } -/* signed distance from the point to the plane in 3D */ -float dist_to_plane_normalized_v3(const float p[3], const float plane_co[3], const float plane_no_unit[3]) +float dist_to_plane_v3(const float pt[3], const float plane[4]) { - float plane_co_other[3]; + float close[3]; - add_v3_v3v3(plane_co_other, plane_co, plane_no_unit); - - return line_point_factor_v3(p, plane_co, plane_co_other); -} - -float dist_to_plane_v3(const float p[3], const float plane_co[3], const float plane_no[3]) -{ - float plane_no_unit[3]; - float plane_co_other[3]; - - normalize_v3_v3(plane_no_unit, plane_no); - add_v3_v3v3(plane_co_other, plane_co, plane_no_unit); + /* same logic as closest_to_plane_v3() */ + const float length = len_squared_v3(plane); + const float side = plane_point_side_v3(plane, pt); + madd_v3_v3v3fl(close, pt, plane, -side / length); + /* end same logic */ - return line_point_factor_v3(p, plane_co, plane_co_other); + return copysign(len_v3v3(pt, close), side); } /* distance v1 to line-piece l1-l2 in 3D */ diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 978fac2604c..71d220153e3 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -4486,7 +4486,6 @@ static int mesh_bisect_exec(bContext *C, wmOperator *op) invert_m4_m4(imat, obedit->obmat); mul_m4_v3(imat, plane_co); mul_mat3_m4_v3(imat, plane_no); - normalize_v3(plane_no); EDBM_op_init(em, &bmop, op, "bisect_plane geom=%hvef plane_co=%v plane_no=%v dist=%f clear_inner=%b clear_outer=%b", @@ -4553,9 +4552,11 @@ void MESH_OT_bisect(struct wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - prop = RNA_def_float_vector(ot->srna, "plane_co", 3, NULL, -FLT_MAX, FLT_MAX, "Point", "", -FLT_MAX, FLT_MAX); + prop = RNA_def_float_vector(ot->srna, "plane_co", 3, NULL, -FLT_MAX, FLT_MAX, + "Plane Point", "A point on the plane", -FLT_MAX, FLT_MAX); RNA_def_property_flag(prop, PROP_SKIP_SAVE); - prop = RNA_def_float_vector(ot->srna, "plane_no", 3, NULL, -FLT_MAX, FLT_MAX, "Direction", "", -FLT_MAX, FLT_MAX); + prop = RNA_def_float_vector(ot->srna, "plane_no", 3, NULL, -FLT_MAX, FLT_MAX, + "Plane Normal", "The direction the plane points", -FLT_MAX, FLT_MAX); RNA_def_property_flag(prop, PROP_SKIP_SAVE); RNA_def_boolean(ot->srna, "use_fill", false, "Fill", "Fill in the cut"); diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c index 8509c46b395..2d4aa988db2 100644 --- a/source/blender/python/mathutils/mathutils_geometry.c +++ b/source/blender/python/mathutils/mathutils_geometry.c @@ -981,6 +981,7 @@ PyDoc_STRVAR(M_Geometry_distance_point_to_plane_doc, static PyObject *M_Geometry_distance_point_to_plane(PyObject *UNUSED(self), PyObject *args) { VectorObject *pt, *plene_co, *plane_no; + float plane[4]; if (!PyArg_ParseTuple(args, "O!O!O!:distance_point_to_plane", &vector_Type, &pt, @@ -990,6 +991,15 @@ static PyObject *M_Geometry_distance_point_to_plane(PyObject *UNUSED(self), PyOb return NULL; } + if (pt->size != 3 || + plene_co->size != 3 || + plane_no->size != 3) + { + PyErr_SetString(PyExc_ValueError, + "One of more of the vector arguments wasn't a 3D vector"); + return NULL; + } + if (BaseMath_ReadCallback(pt) == -1 || BaseMath_ReadCallback(plene_co) == -1 || BaseMath_ReadCallback(plane_no) == -1) @@ -997,7 +1007,8 @@ static PyObject *M_Geometry_distance_point_to_plane(PyObject *UNUSED(self), PyOb return NULL; } - return PyFloat_FromDouble(dist_to_plane_v3(pt->vec, plene_co->vec, plane_no->vec)); + plane_from_point_normal_v3(plane, plene_co->vec, plane_no->vec); + return PyFloat_FromDouble(dist_to_plane_v3(pt->vec, plane)); } PyDoc_STRVAR(M_Geometry_barycentric_transform_doc, @@ -1054,6 +1065,17 @@ static PyObject *M_Geometry_barycentric_transform(PyObject *UNUSED(self), PyObje return NULL; } + if (BaseMath_ReadCallback(vec_pt) == -1 || + BaseMath_ReadCallback(vec_t1_src) == -1 || + BaseMath_ReadCallback(vec_t2_src) == -1 || + BaseMath_ReadCallback(vec_t3_src) == -1 || + BaseMath_ReadCallback(vec_t1_tar) == -1 || + BaseMath_ReadCallback(vec_t2_tar) == -1 || + BaseMath_ReadCallback(vec_t3_tar) == -1) + { + return NULL; + } + barycentric_transform(vec, vec_pt->vec, vec_t1_tar->vec, vec_t2_tar->vec, vec_t3_tar->vec, vec_t1_src->vec, vec_t2_src->vec, vec_t3_src->vec); |