Revision: 55917
http://sourceforge.net/p/brlcad/code/55917
Author: starseeker
Date: 2013-07-01 20:10:21 +0000 (Mon, 01 Jul 2013)
Log Message:
-----------
Pull curve tangent calculations into a function.
Modified Paths:
--------------
brlcad/trunk/include/brep.h
brlcad/trunk/src/libbrep/libbrep_brep_tools.cpp
brlcad/trunk/src/libbrep/libbrep_brep_tools.h
brlcad/trunk/src/libbrep/opennurbs_ext.cpp
Modified: brlcad/trunk/include/brep.h
===================================================================
--- brlcad/trunk/include/brep.h 2013-07-01 19:36:46 UTC (rev 55916)
+++ brlcad/trunk/include/brep.h 2013-07-01 20:10:21 UTC (rev 55917)
@@ -861,8 +861,6 @@
int depth();
private:
- fastf_t getVerticalTangent(const ON_Curve *curve, fastf_t min, fastf_t
max);
- fastf_t getHorizontalTangent(const ON_Curve *curve, fastf_t min, fastf_t
max);
bool getHVTangents(const ON_Curve* curve, ON_Interval& t,
std::list<fastf_t>& list);
bool isLinear(const ON_Curve* curve, double min, double max);
BRNode* subdivideCurve(const ON_Curve* curve, int adj_face_index, double
min, double max, bool innerTrim, int depth);
Modified: brlcad/trunk/src/libbrep/libbrep_brep_tools.cpp
===================================================================
--- brlcad/trunk/src/libbrep/libbrep_brep_tools.cpp 2013-07-01 19:36:46 UTC
(rev 55916)
+++ brlcad/trunk/src/libbrep/libbrep_brep_tools.cpp 2013-07-01 20:10:21 UTC
(rev 55917)
@@ -33,6 +33,43 @@
return (val > -epsilon) && (val < epsilon);
}
+double ON_Curve_Get_Tangent(int direction, const ON_Curve* curve, double min,
double max, double zero_tol) {
+ double mid;
+ bool tanmin;
+ ON_3dVector tangent;
+
+ // first check end points
+ tangent = curve->TangentAt(max);
+ if (direction == 1 && ON_NearZero(tangent.y, zero_tol)) return max;
+ if (direction == 0 && ON_NearZero(tangent.x, zero_tol)) return max;
+ tangent = curve->TangentAt(min);
+ if (direction == 1 && ON_NearZero(tangent.y, zero_tol)) return min;
+ if (direction == 0 && ON_NearZero(tangent.y, zero_tol)) return min;
+
+ tanmin = (tangent[direction] < 0.0);
+ while ((max-min) > zero_tol) {
+ mid = (max + min)/2.0;
+ tangent = curve->TangentAt(mid);
+ if (ON_NearZero(tangent[direction], zero_tol)) {
+ return mid;
+ }
+ if ((tangent[direction] < 0.0) == tanmin) {
+ min = mid;
+ } else {
+ max = mid;
+ }
+ }
+ return min;
+}
+
+double ON_Curve_Get_Horizontal_Tangent(const ON_Curve* curve, double min,
double max, double zero_tol) {
+ return ON_Curve_Get_Tangent(1, curve, min, max, zero_tol);
+}
+
+double ON_Curve_Get_Vertical_Tangent(const ON_Curve* curve, double min, double
max, double zero_tol) {
+ return ON_Curve_Get_Tangent(0, curve, min, max, zero_tol);
+}
+
int ON_Curve_Has_Tangent(const ON_Curve* curve, double ct_min, double ct_max,
double t_tol) {
bool tanx1, tanx2, x_changed;
Modified: brlcad/trunk/src/libbrep/libbrep_brep_tools.h
===================================================================
--- brlcad/trunk/src/libbrep/libbrep_brep_tools.h 2013-07-01 19:36:46 UTC
(rev 55916)
+++ brlcad/trunk/src/libbrep/libbrep_brep_tools.h 2013-07-01 20:10:21 UTC
(rev 55917)
@@ -62,7 +62,6 @@
/**
\brief Return truthfully whether a value is within a specified epsilon
distance from zero.
-
@param val value to be tested
@param epsilon distance from zero defining the interval to be treated as
"near" zero for the test
@@ -71,8 +70,34 @@
BREP_EXPORT
bool ON_NearZero(double val, double epsilon);
+/**
+ \brief Search for a horizontal tangent on the curve between two curve
parameters.
+ @param curve curve to be tested
+ @param min minimum curve parameter value
+ @param max maximum curve parameter value
+ @param zero_tol tolerance to use when testing for near-zero values
+
+ @return t parameter corresponding to the point on the curve with the
horizontal tangent.
+*/
+BREP_EXPORT
+double ON_Curve_Get_Horizontal_Tangent(const ON_Curve* curve, double min,
double max, double zero_tol);
+
/**
+ \brief Search for a vertical tangent on the curve between two curve
parameters.
+
+ @param curve curve to be tested
+ @param min minimum curve parameter value
+ @param max maximum curve parameter value
+ @param zero_tol tolerance to use when testing for near-zero values
+
+ @return t parameter corresponding to the point on the curve with the
vertical tangent.
+*/
+BREP_EXPORT
+double ON_Curve_Get_Vertical_Tangent(const ON_Curve* curve, double min, double
max, double zero_tol);
+
+
+/**
\brief Test whether a curve interval contains one or more horizontal or
vertical tangents
@param curve ON_Curve to be tested
Modified: brlcad/trunk/src/libbrep/opennurbs_ext.cpp
===================================================================
--- brlcad/trunk/src/libbrep/opennurbs_ext.cpp 2013-07-01 19:36:46 UTC (rev
55916)
+++ brlcad/trunk/src/libbrep/opennurbs_ext.cpp 2013-07-01 20:10:21 UTC (rev
55917)
@@ -389,71 +389,6 @@
}
}
-
- fastf_t
- CurveTree::getVerticalTangent(const ON_Curve *curve, fastf_t min,
fastf_t max)
- {
- fastf_t mid;
- ON_3dVector tangent;
- bool tanmin;
-
- // first lets check end points
- tangent = curve->TangentAt(max);
- if (NEAR_ZERO(tangent.x, TOL2))
- return max;
- tangent = curve->TangentAt(min);
- if (NEAR_ZERO(tangent.x, TOL2))
- return min;
-
- tanmin = (tangent[X] < 0.0);
- while ((max-min) > TOL2) {
- mid = (max + min)/2.0;
- tangent = curve->TangentAt(mid);
- if (NEAR_ZERO(tangent[X], TOL2)) {
- return mid;
- }
- if ((tangent[X] < 0.0) == tanmin) {
- min = mid;
- } else {
- max = mid;
- }
- }
- return min;
- }
-
-
- fastf_t
- CurveTree::getHorizontalTangent(const ON_Curve *curve, fastf_t min,
fastf_t max)
- {
- fastf_t mid;
- ON_3dVector tangent;
- bool tanmin;
-
- // first lets check end points
- tangent = curve->TangentAt(max);
- if (NEAR_ZERO(tangent.y, TOL2))
- return max;
- tangent = curve->TangentAt(min);
- if (NEAR_ZERO(tangent.y, TOL2))
- return min;
-
- tanmin = (tangent[Y] < 0.0);
- while ((max-min) > TOL2) {
- mid = (max + min)/2.0;
- tangent = curve->TangentAt(mid);
- if (NEAR_ZERO(tangent[Y], TOL2)) {
- return mid;
- }
- if ((tangent[Y] < 0.0) == tanmin) {
- min = mid;
- } else {
- max = mid;
- }
- }
- return min;
- }
-
-
bool
CurveTree::getHVTangents(const ON_Curve* curve, ON_Interval& t,
std::list<fastf_t>& list)
{
@@ -466,12 +401,12 @@
switch (status) {
case 1: /* 1 Vertical tangent */
- x = getVerticalTangent(curve, t[0], t[1]);
+ x = ON_Curve_Get_Vertical_Tangent(curve, t[0], t[1], TOL2);
list.push_back(x);
return true;
case 2: /* 1 Horizontal tangent */
- x = getHorizontalTangent(curve, t[0], t[1]);
+ x = ON_Curve_Get_Horizontal_Tangent(curve, t[0], t[1],
TOL2);
list.push_back(x);
return true;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits