Module: TT::Bezier
- Defined in:
- cext/tt_lib2/tt_lib2/src/ruby/geom3d/bezier.cpp,
cext/tt_lib2/tt_lib2/src/ruby/geom3d/bezier.cpp
Overview
Methods to evaluate various bezier functions.
Constant Summary
- CEXT_VERSION =
Bezier kernel version.
GetVALUE("2.0.0")
Class Method Summary collapse
- .curve(skp_points, subdivs) ⇒ Array<Geom::Point3d>
- .eval(skp_points, position) ⇒ Geom::Point3d
- .patch(ruby_points, subdivs) ⇒ Array<Geom::Point3d>
Class Method Details
.curve(skp_points, subdivs) ⇒ Array<Geom::Point3d>
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'cext/tt_lib2/tt_lib2/src/ruby/geom3d/bezier.cpp', line 120
VALUE wrap_curve( VALUE self, VALUE skp_points, VALUE subdivs )
{
int nSubdivs;
long nPoints, nCurve;
Point3d *c_curve = NULL;
Point3d *c_points = NULL;
VALUE skp_curve;
Check_Type( skp_points, T_ARRAY );
nSubdivs = NUM2INT( subdivs );
nPoints = RARRAY_LEN( skp_points );
nCurve = nSubdivs + 1;
if ( nSubdivs < 1 )
rb_raise( rb_eArgError, "Subdivisions must be at least one." );
if ( nPoints < 2 )
rb_raise( rb_eArgError, "Must have at least two control points." );
c_points = ALLOC_N_UINT( Point3d, nPoints );
c_curve = ALLOC_N_UINT( Point3d, nCurve );
sketchup_to_points( skp_points, c_points, nPoints );
if ( bezier_curve( c_points, nPoints, c_curve, nCurve ) )
rb_raise( rb_eStandardError, "Could not create bezier curve." ); // (?)
skp_curve = points_to_sketchup( c_curve, nCurve );
xfree( c_curve );
c_curve = NULL;
xfree( c_points );
c_points = NULL;
return skp_curve;
}
|
.eval(skp_points, position) ⇒ Geom::Point3d
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 |
# File 'cext/tt_lib2/tt_lib2/src/ruby/geom3d/bezier.cpp', line 85
VALUE wrap_eval(VALUE self, VALUE skp_points, VALUE position)
{
long nPoints;
double t;
Point3d *c_points = NULL;
Point3d c_point;
Check_Type( skp_points, T_ARRAY );
nPoints = RARRAY_LEN( skp_points );
t = NUM2DBL( position );
if ( nPoints < 2 )
rb_raise( rb_eArgError, "Must have at least two control points." );
if ( t < 0.0 || t > 1.0 )
rb_raise( rb_eArgError, "Position must be between 0.0 and 1.0." );
c_points = ALLOC_N_UINT( Point3d, nPoints );
sketchup_to_points( skp_points, c_points, nPoints );
c_point = bezier_eval( c_points, nPoints, t );
xfree( c_points );
c_points = NULL;
return point_to_sketchup( c_point );
}
|
.patch(ruby_points, subdivs) ⇒ Array<Geom::Point3d>
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'cext/tt_lib2/tt_lib2/src/ruby/geom3d/bezier.cpp', line 163
VALUE wrap_patch(VALUE self, VALUE ruby_points, VALUE subdivs)
{
using namespace tt_lib2::ruby::api;
using namespace tt_lib2::geometry::bezier;
Check_Type(ruby_points, T_ARRAY);
auto segments = NUM2INT(subdivs);
auto num_points = RARRAY_LEN(ruby_points);
if (segments < 0)
rb_raise(rb_eArgError, "Subdivisions must be larger than zero.");
if (num_points < 4)
rb_raise(rb_eArgError, "Must have at least four control points.");
if (!is_integer_perfect_square(num_points))
rb_raise(rb_eArgError, "Number of points must be a perfect square.");
auto control_points = Geom::VALUE2Points(ruby_points);
auto bezier_patch_points = QuadPatch(control_points, segments);
return Geom::GetVALUE(bezier_patch_points);
}
|