forked from mcneel/opennurbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opennurbs_curve.cpp
3796 lines (3406 loc) · 99.4 KB
/
opennurbs_curve.cpp
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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
#if !defined(ON_COMPILING_OPENNURBS)
// This check is included in all opennurbs source .c and .cpp files to insure
// ON_COMPILING_OPENNURBS is defined when opennurbs source is compiled.
// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined
// and the opennurbs .h files alter what is declared and how it is declared.
#error ON_COMPILING_OPENNURBS must be defined when compiling opennurbs
#endif
ON_VIRTUAL_OBJECT_IMPLEMENT(ON_Curve,ON_Geometry,"4ED7D4D7-E947-11d3-BFE5-0010830122F0");
ON_Curve::ON_Curve() ON_NOEXCEPT
: ON_Geometry()
{}
ON_Curve::ON_Curve(const ON_Curve& src)
: ON_Geometry(src)
{}
ON_Curve& ON_Curve::operator=(const ON_Curve& src)
{
if ( this != &src )
{
this->DestroyCurveTree();
ON_Geometry::operator=(src);
}
return *this;
}
#if defined(ON_HAS_RVALUEREF)
ON_Curve::ON_Curve( ON_Curve&& src ) ON_NOEXCEPT
: ON_Geometry(std::move(src))
{
}
ON_Curve& ON_Curve::operator=( ON_Curve&& src )
{
if ( this != &src )
{
this->DestroyCurveTree();
ON_Geometry::operator=(std::move(src));
}
return *this;
}
#endif
ON_Curve::~ON_Curve()
{
// Do not call the (virtual) DestroyRuntimeCache or
// DestroyCurveTree (which calls DestroyRuntimeCache()
// because it opens the potential for crashes in a
// "dirty" destructors of classes derived from ON_Curve
// that to not use DestroyRuntimeCache() in their
// destructors and to not set deleted pointers to zero.
}
unsigned int ON_Curve::SizeOf() const
{
unsigned int sz = ON_Geometry::SizeOf();
sz += (sizeof(*this) - sizeof(ON_Geometry));
// Currently, the size of m_ctree is not included
// because this is cached runtime information.
// Applications that care about object size are
// typically storing "inactive" objects for potential
// future use and should call DestroyRuntimeCache(true)
// to remove any runtime cache information.
return sz;
}
ON_Curve* ON_Curve::DuplicateCurve() const
{
// ON_CurveProxy overrides this virtual function.
return Duplicate();
}
ON::object_type ON_Curve::ObjectType() const
{
return ON::curve_object;
}
bool ON_Curve::GetDomain(double* s0,double* s1) const
{
bool rc = false;
ON_Interval d = Domain();
if ( d.IsIncreasing() ) {
if(s0) *s0 = d.Min();
if (s1) *s1 = d.Max();
rc = true;
}
return rc;
}
void ON_Curve::DestroyCurveTree()
{
DestroyRuntimeCache(true);
}
bool ON_Curve::GetTightBoundingBox(
ON_BoundingBox& tight_bbox,
bool bGrowBox,
const ON_Xform* xform
) const
{
if ( bGrowBox && !tight_bbox.IsValid() )
{
bGrowBox = false;
}
if ( !bGrowBox )
{
tight_bbox.Destroy();
}
// In general, putting start and end point in the box lets me avoid
// testing lots of nodes.
ON_3dPoint P = PointAtStart();
if ( xform )
P = (*xform)*P;
tight_bbox.Set( P, bGrowBox );
bGrowBox = true;
P = PointAtEnd();
if ( xform )
P = (*xform)*P;
tight_bbox.Set( P, bGrowBox );
ON_BoundingBox curve_bbox = BoundingBox();
if ( ON_WorldBBoxIsInTightBBox( tight_bbox, curve_bbox, xform ) )
{
// Curve is inside tight_bbox
return true;
}
ON_NurbsCurve N;
if ( 0 == GetNurbForm(N) )
return false;
if ( N.m_order < 2 || N.m_cv_count < N.m_order )
return false;
ON_BezierCurve B;
for ( int span_index = 0; span_index <= N.m_cv_count - N.m_order; span_index++ )
{
if ( !(N.m_knot[span_index + N.m_order-2] < N.m_knot[span_index + N.m_order-1]) )
continue;
if ( !N.ConvertSpanToBezier( span_index, B ) )
continue;
if ( !B.GetTightBoundingBox(tight_bbox,bGrowBox,xform) )
continue;
bGrowBox = true;
}
return (0!=bGrowBox);
}
// overrides virtual ON_Geometry::Transform()
bool ON_Curve::Transform(
const ON_Xform& xform
)
{
if ( !this->ON_Geometry::Transform(xform) )
return false;
this->DestroyCurveTree();
return true;
}
bool ON_Curve::SetDomain( ON_Interval domain )
{
return ( domain.IsIncreasing() && SetDomain( domain[0], domain[1] )) ? true : false;
}
bool ON_Curve::SetDomain( double, double )
{
// this virtual function is overridden by curves that can change their domain.
return false;
}
bool ON_Curve::ChangeClosedCurveSeam( double t, double min_dist)
{
ON_3dPoint P = PointAt(t);
if (min_dist <= 0.0 || P.DistanceTo(PointAtStart()) >= min_dist)
return ChangeClosedCurveSeam(t);
return false;
}
bool ON_Curve::ChangeClosedCurveSeam( double t )
{
// this virtual function is overridden by curves that can be closed
return false;
}
//virtual
bool ON_Curve::ChangeDimension( int desired_dimension )
{
return (desired_dimension > 0 && desired_dimension == Dimension() );
}
//virtual
bool ON_Curve::GetSpanVectorIndex(
double t, // [IN] t = evaluation parameter
int side, // [IN] side 0 = default, -1 = from below, +1 = from above
int* span_vector_i, // [OUT] span vector index
ON_Interval* span_domain // [OUT] domain of the span containing "t"
) const
{
bool rc = false;
int i;
int span_count = SpanCount();
if ( span_count > 0 ) {
double* span_vector = (double*)onmalloc((span_count+1)*sizeof(span_vector[0]));
rc = GetSpanVector( span_vector );
if (rc) {
i = ON_NurbsSpanIndex( 2, span_count+1, span_vector, t, side, 0 );
if ( i >= 0 && i < span_count ) {
if ( span_vector_i )
*span_vector_i = i;
if ( span_domain )
span_domain->Set( span_vector[i], span_vector[i+1] );
}
else
rc = false;
}
onfree(span_vector);
}
return rc;
}
bool ON_Curve::GetParameterTolerance( // returns tminus < tplus: parameters tminus <= s <= tplus
double t, // t = parameter in domain
double* tminus, // tminus
double* tplus // tplus
) const
{
bool rc = false;
ON_Interval d = Domain();
if ( d.IsIncreasing() )
rc = ON_GetParameterTolerance( d[0], d[1], t, tminus, tplus );
return rc;
}
int ON_Curve::IsPolyline(
ON_SimpleArray<ON_3dPoint>* pline_points, // default = nullptr
ON_SimpleArray<double>* pline_t // default = nullptr
) const
{
// virtual function that is overridden
return 0;
}
bool ON_Curve::IsLinear( double tolerance ) const
{
bool rc = false;
if ( Dimension() == 2 || Dimension() == 3 ) {
const int span_count = SpanCount();
const int span_degree = Degree();
if ( span_count > 0 ) {
ON_SimpleArray<double> s(span_count+1);
s.SetCount(span_count+1);
if ( GetSpanVector( s.Array() ) ) {
if ( tolerance == 0.0 )
tolerance = ON_ZERO_TOLERANCE;
ON_Line line( PointAtStart(), PointAtEnd() );
if ( line.Length() > tolerance ) {
double t, t0, d, delta;
ON_Interval sp;
int n, i, span_index;
rc = true;
t0 = 0; // Domain()[0];
ON_3dPoint P;
for ( span_index = 0; span_index < span_count; span_index++ ) {
sp.Set( s[span_index], s[span_index+1] );
n = 2*span_degree+1;
delta = 1.0/n;
for ( i = (span_index)?0:1; i < n; i++ ) {
P = PointAt( sp.ParameterAt(i*delta) );
if ( !line.ClosestPointTo( P, &t ) )
rc = false;
else if ( t < t0 )
rc = false;
else if (t > 1.0 + ON_SQRT_EPSILON)
rc = false;
d = P.DistanceTo( line.PointAt(t) );
if ( d > tolerance )
rc = false;
t0 = t;
}
}
}
}
}
}
return rc;
}
bool ON_Curve::IsEllipse(
const ON_Plane* plane,
ON_Ellipse* ellipse,
double tolerance
) const
{
// virtual function
ON_Arc arc;
bool rc = IsArc(plane,&arc,tolerance)?true:false;
if (rc && ellipse)
{
ellipse->plane = arc.plane;
ellipse->radius[0] = arc.radius;
ellipse->radius[1] = arc.radius;
}
return rc;
}
bool ON_Curve::IsArcAt(
double t,
const ON_Plane* plane,
ON_Arc* arc,
double tolerance,
double* t0,
double* t1
) const
{
double k, k0, k1;
int hint;
if ( !GetDomain(&k0,&k1) )
return false;
if ( 0 != t0 )
*t0 = k0;
if ( 0 != t1 )
*t1 = k1;
if ( !ON_IsValid(t) )
return false;
if ( ! (t <= k1) )
return false;
if ( IsArc(plane,arc,tolerance) )
return true; // entire curve is an arc
// check sub-segments
hint = 0;
for ( k = k0; k0 <= t && GetNextDiscontinuity(ON::continuity::G2_locus_continuous, k0, k1, &k, &hint); k0 = k )
{
if ( !(k > k0) )
break; // sanity check to prevent infinite loops
if( t <= k )
{
if ( 0 != t0 )
*t0 = k0;
if ( 0 != t1 )
*t1 = k1;
ON_CurveProxy subcrv(this,ON_Interval(k0,k));
if ( subcrv.IsArc(plane,arc,tolerance) )
return true;
// NOTE WELL:
// When t == k, we need to check the next segment as well
// (happens when t is the parameter between a line and arc segment.)
// The "k0 <= t" test is in the for() condition will
// terminate the loop when t < k
}
}
return false;
}
bool ON_Curve::IsArc( const ON_Plane* plane, ON_Arc* arc, double tolerance ) const
{
bool rc = false;
double c0, c, t, delta;
int n, i, span_index;
ON_Plane pln;
ON_Arc a;
ON_3dPoint P, C;
if ( !plane ) {
if ( !IsPlanar(&pln,tolerance) )
return false;
plane = &pln;
}
if ( !arc )
arc = &a;
const int span_count = SpanCount();
const int span_degree = Degree();
if ( span_count < 1 )
return false;
ON_SimpleArray<double> d(span_count+1);
d.SetCount(span_count+1);
if ( !GetSpanVector(d.Array()) )
return false;
const bool bIsClosed = IsClosed();
ON_3dPoint P0 = PointAt( d[0] );
t = bIsClosed ? 0.5*d[0] + 0.5*d[span_count] : d[span_count];
ON_3dPoint P1 = PointAt( 0.5*d[0] + 0.5*t );
ON_3dPoint P2 = PointAt( t );
if ( !arc->Create(P0,P1,P2) )
return false;
if ( bIsClosed )
arc->SetAngleRadians(2.0*ON_PI);
ON_Interval arc_domain = arc->Domain();
ON_3dPoint A0 = arc->PointAt(arc_domain[0]);
ON_3dPoint A1 = arc->PointAt(arc_domain[1]);
ON_3dPoint C0 = PointAtStart();
ON_3dPoint C1 = PointAtEnd();
if ( false == ON_PointsAreCoincident(3,0,&A0.x,&C0.x)
|| false == ON_PointsAreCoincident(3,0,&A1.x,&C1.x)
)
{
return false;
}
if ( tolerance == 0.0 )
tolerance = ON_ZERO_TOLERANCE;
rc = true;
c0 = 0.0;
for ( span_index = 0; rc && span_index < span_count; span_index++ ) {
n = 2*span_degree+1;
if ( n < 4 )
n = 4;
delta = 1.0/n;
for ( i = 0; i < n; i++ ) {
t = i*delta;
P = PointAt( (1.0-t)*d[span_index] + t*d[span_index+1] );
if ( !arc->ClosestPointTo(P,&c) ) {
rc = false;
break;
}
if ( c < c0 ) {
rc = false;
break;
}
C = arc->PointAt(c);
if ( C.DistanceTo(P) > tolerance ) {
rc = 0;
break;
}
c0 = c;
}
}
return rc;
}
bool ON_Curve::IsPlanar( ON_Plane* plane, double tolerance ) const
{
bool rc = false;
const int dim = Dimension();
if ( dim == 2 )
{
// all 2d curves use this code to set the plane
// so that there is consistent behavior.
rc = true;
if ( plane )
{
*plane = ON_xy_plane;
//plane->CreateFromFrame( PointAtStart(), ON_3dVector::XAxis, ON_3dVector::YAxis );
}
}
else if ( IsLinear(tolerance) )
{
rc = true;
if ( plane )
{
ON_Line line( PointAtStart(), PointAtEnd() );
if ( !line.InPlane( *plane, tolerance ) )
line.InPlane( *plane, 0.0 );
}
}
else if ( dim == 3 )
{
const int span_count = SpanCount();
if ( span_count < 1 )
return false;
const int span_degree = Degree();
if ( span_degree < 1 )
return false;
ON_SimpleArray<double> s(span_count+1);
s.SetCount(span_count+1);
if ( !GetSpanVector(s.Array()) )
return false;
ON_Interval d = Domain();
// use initial point, tangent, and evaluated spans to guess a plane
ON_3dPoint pt = PointAt(d.ParameterAt(0.0));
ON_3dVector x = TangentAt(d.ParameterAt(0.0));
if ( x.Length() < 0.95 ) {
return false;
}
int n = (span_degree > 1) ? span_degree+1 : span_degree;
double delta = 1.0/n;
int i, span_index, hint = 0;
ON_3dPoint q;
ON_3dVector y;
bool bNeedY = true;
for ( span_index = 0; span_index < span_count && bNeedY; span_index++ ) {
d.Set(s[span_index],s[span_index+1]);
for ( i = span_index ? 0 : 1; i < n && bNeedY; i++ ) {
if ( !EvPoint( d.ParameterAt(i*delta), q, 0, &hint ) )
return false;
y = q-pt;
y = y - (y*x)*x;
bNeedY = ( y.Length() <= 1.0e-6 );
}
}
if ( bNeedY )
y.PerpendicularTo(x);
ON_Plane pln( pt, x, y );
if ( plane )
*plane = pln;
// test
rc = true;
n = 2*span_degree + 1;
delta = 1.0/n;
double h = pln.plane_equation.ValueAt(PointAtEnd());
if ( fabs(h) > tolerance )
rc = false;
hint = 0;
for ( span_index = 0; rc && span_index < span_count; span_index++ ) {
d.Set(s[span_index],s[span_index+1]);
for ( i = 0; rc && i < n; i++ ) {
if ( !EvPoint( d.ParameterAt(i*delta), q, 0, &hint ) )
rc = false;
else {
h = pln.plane_equation.ValueAt(q);
if ( fabs(h) > tolerance )
rc = false;
}
}
}
}
return rc;
}
bool ON_Curve::IsClosed() const
{
bool rc = false;
double *a, *b, *c, *p, w[12];
const int dim = Dimension();
a = 0;
if ( dim > 1 )
{
ON_Interval d = Domain();
a = (dim>3) ? (double*)onmalloc(dim*4*sizeof(*a)) : w;
b = a+dim;
c = b+dim;
p = c+dim;
if ( Evaluate( d.ParameterAt(0.0), 0, dim, a, 1 )
&& Evaluate( d.ParameterAt(1.0), 0, dim, p,-1 )
)
{
// Note: The point compare test should be the same
// as the one used in ON_PolyCurve::HasGap().
// June 2019 - sometime in the past decade ON_PolyCurve::HasGap()
// changed and the test there is different from this test.
// The initial "Note" no longer applies becaue it's no longer
// clear why the current ON_PolyCurve::HasGap() was changed.
if ( ON_PointsAreCoincident( dim, false, a, p ) )
{
if ( Evaluate( d.ParameterAt(1.0/3.0), 0, dim, b, 0 )
&& Evaluate( d.ParameterAt(2.0/3.0), 0, dim, c, 0 )
)
{
if ( false == ON_PointsAreCoincident( dim, false, a, b )
&& false == ON_PointsAreCoincident( dim, false, a, c )
&& false == ON_PointsAreCoincident( dim, false, p, b )
&& false == ON_PointsAreCoincident( dim, false, p, c )
)
{
rc = true;
}
}
}
}
if ( dim > 3 && 0 != a )
onfree(a);
}
return rc;
}
bool ON_Curve::IsPeriodic() const
{
// curve types that may be periodic override this virtual function
return false;
}
bool ON_Curve::GetNextDiscontinuity(
ON::continuity c,
double t0,
double t1,
double* t,
int* hint,
int* dtype,
double cos_angle_tolerance,
double curvature_tolerance
) const
{
// this function must be overridden by curve objects that
// can have parametric discontinuities on the interior of the curve.
bool rc = false;
if ( dtype )
*dtype = 0;
if ( t0 != t1 )
{
bool bTestC0 = false;
bool bTestD1 = false;
bool bTestD2 = false;
bool bTestT = false;
bool bTestK = false;
switch(c)
{
case ON::continuity::C0_locus_continuous:
bTestC0 = true;
break;
case ON::continuity::C1_locus_continuous:
bTestC0 = true;
bTestD1 = true;
break;
case ON::continuity::C2_locus_continuous:
bTestC0 = true;
bTestD1 = true;
bTestD2 = true;
break;
case ON::continuity::G1_locus_continuous:
bTestC0 = true;
bTestT = true;
break;
case ON::continuity::G2_locus_continuous:
bTestC0 = true;
bTestT = true;
bTestK = true;
break;
default:
// other values ignored on purpose.
break;
}
if ( bTestC0 )
{
// 20 March 2003 Dale Lear:
// Have to look for locus discontinuities at ends.
// Must test both ends becuase t0 > t1 is valid input.
// In particular, for ON_CurveProxy::GetNextDiscontinuity()
// to work correctly on reversed "real" curves, the
// t0 > t1 must work right.
ON_Interval domain = Domain();
if ( t0 < domain[1] && t1 >= domain[1] )
t1 = domain[1];
else if ( t0 > domain[0] && t1 <= domain[0] )
t1 = domain[0];
if ( (t0 < domain[1] && t1 >= domain[1]) || (t0 > domain[0] && t1 <= domain[0]) )
{
if ( IsClosed() )
{
if ( bTestD1 || bTestT )
{
// need to check locus continuity at start/end of closed curve.
ON_3dPoint Pa, Pb;
ON_3dVector D1a, D1b, D2a, D2b;
if ( Ev2Der(domain[0],Pa,D1a,D2a,1,nullptr)
&& Ev2Der(domain[1],Pb,D1b,D2b,-1,nullptr) )
{
Pb = Pa; // IsClosed() = true means assume Pa=Pb;
if ( bTestD1 )
{
if ( !(D1a-D1b).IsTiny(D1b.MaximumCoordinate()*ON_SQRT_EPSILON ) )
{
if ( dtype )
*dtype = 1;
*t = t1;
rc = true;
}
else if ( bTestD2 && !(D2a-D2b).IsTiny(D2b.MaximumCoordinate()*ON_SQRT_EPSILON) )
{
if ( dtype )
*dtype = 2;
*t = t1;
rc = true;
}
}
else if ( bTestT )
{
ON_3dVector Ta, Tb, Ka, Kb;
ON_EvCurvature( D1a, D2a, Ta, Ka );
ON_EvCurvature( D1b, D2b, Tb, Kb );
if ( Ta*Tb < cos_angle_tolerance )
{
if ( dtype )
*dtype = 1;
*t = t1;
rc = true;
}
else if ( bTestK )
{
// NOTE:
// This test must exactly match the one
// used in ON_NurbsCurve::GetNextDiscontinuity()
if ( !ON_IsG2CurvatureContinuous( Ka, Kb,
cos_angle_tolerance,
curvature_tolerance
)
)
{
if ( dtype )
*dtype = 2;
*t = t1;
rc = true;
}
}
}
}
}
}
else
{
// open curves are not locus continuous at ends.
if (dtype )
*dtype = 0; // locus C0 discontinuity
*t = t1;
rc = true;
}
}
}
}
return rc;
}
bool ON_Curve::IsContinuous(
ON::continuity desired_continuity,
double t,
int* hint, // default = nullptr,
double point_tolerance, // default=ON_ZERO_TOLERANCE
double d1_tolerance, // default==ON_ZERO_TOLERANCE
double d2_tolerance, // default==ON_ZERO_TOLERANCE
double cos_angle_tolerance, // default==ON_DEFAULT_ANGLE_TOLERANCE_COSINE
double curvature_tolerance // default==ON_SQRT_EPSILON
) const
{
ON_Interval domain = Domain();
if ( !domain.IsIncreasing() )
{
return true;
}
ON_3dPoint Pm, Pp;
ON_3dVector D1m, D1p, D2m, D2p, Tm, Tp, Km, Kp;
bool bIsClosed = false;
// 20 March 2003 Dale Lear
// I added this preable to handle the new
// locus continuity values.
double t0 = t;
double t1 = t;
switch(desired_continuity)
{
case ON::continuity::C0_locus_continuous:
case ON::continuity::C1_locus_continuous:
case ON::continuity::C2_locus_continuous:
case ON::continuity::G1_locus_continuous:
case ON::continuity::G2_locus_continuous:
if ( t <= domain[0] )
{
// By convention - see comments by ON::continuity enum.
return true;
}
if ( t == domain[1] )
{
if ( !IsClosed() )
{
// open curves are not locus continuous at the end parameter
// see comments by ON::continuity enum
return false;
}
else
{
if ( ON::continuity::C0_locus_continuous == desired_continuity )
{
return true;
}
bIsClosed = true;
}
t0 = domain[0];
t1 = domain[1];
}
break;
case ON::continuity::unknown_continuity:
case ON::continuity::C0_continuous:
case ON::continuity::C1_continuous:
case ON::continuity::C2_continuous:
case ON::continuity::G1_continuous:
case ON::continuity::G2_continuous:
case ON::continuity::Cinfinity_continuous:
case ON::continuity::Gsmooth_continuous:
default:
// does not change pre 20 March behavior - just skips the out
// of domain evaluation on parametric queries.
if ( t <= domain[0] || t >= domain[1] )
return true;
break;
}
// at this point, no difference between parametric and locus tests.
desired_continuity = ON::ParametricContinuity((int)desired_continuity);
// this is slow and uses evaluation
// virtual overrides on curve classes that can have multiple spans
// are much faster because the avoid evaluation
switch ( desired_continuity )
{
case ON::continuity::unknown_continuity:
break;
case ON::continuity::C0_continuous:
if ( !EvPoint( t1, Pm, -1, hint ) )
return false;
if ( !EvPoint( t0, Pp, 1, hint ) )
return false;
if ( bIsClosed )
Pm = Pp;
if ( !(Pm-Pp).IsTiny(point_tolerance) )
return false;
break;
case ON::continuity::C1_continuous:
if ( !Ev1Der( t1, Pm, D1m, -1, hint ) )
return false;
if ( !Ev1Der( t0, Pp, D1p, 1, hint ) )
return false;
if ( bIsClosed )
Pm = Pp;
if ( !(Pm-Pp).IsTiny(point_tolerance) || !(D1m-D1p).IsTiny(d1_tolerance) )
return false;
break;
case ON::continuity::G1_continuous:
if ( !EvTangent( t1, Pm, Tm, -1, hint ) )
return false;
if ( !EvTangent( t0, Pp, Tp, 1, hint ) )
return false;
if ( bIsClosed )
Pm = Pp;
if ( !(Pm-Pp).IsTiny(point_tolerance) || Tm*Tp < cos_angle_tolerance )
return false;
break;
case ON::continuity::C2_continuous:
if ( !Ev2Der( t1, Pm, D1m, D2m, -1, hint ) )
return false;
if ( !Ev2Der( t0, Pp, D1p, D2p, 1, hint ) )
return false;
if ( bIsClosed )
Pm = Pp;
if ( !(Pm-Pp).IsTiny(point_tolerance) || !(D1m-D1p).IsTiny(d1_tolerance) || !(D2m-D2p).IsTiny(d2_tolerance) )
return false;
break;
case ON::continuity::G2_continuous:
case ON::continuity::Gsmooth_continuous:
if ( !EvCurvature( t1, Pm, Tm, Km, -1, hint ) )
return false;
if ( !EvCurvature( t0, Pp, Tp, Kp, 1, hint ) )
return false;
if ( !bIsClosed && !(Pm-Pp).IsTiny(point_tolerance) )
return false;
if ( Tm*Tp < cos_angle_tolerance )
return false; // tangent discontinuity
if ( desired_continuity == ON::continuity::Gsmooth_continuous )
{
if ( !ON_IsGsmoothCurvatureContinuous(Km,Kp,cos_angle_tolerance,curvature_tolerance) )
return false;
}
else
{
if ( !ON_IsG2CurvatureContinuous(Km,Kp,cos_angle_tolerance,curvature_tolerance) )
return false;
}
break;
case ON::continuity::C0_locus_continuous:
case ON::continuity::C1_locus_continuous:
case ON::continuity::C2_locus_continuous:
case ON::continuity::G1_locus_continuous:
case ON::continuity::G2_locus_continuous:
case ON::continuity::Cinfinity_continuous:
break;
}
return true;
}
ON_3dPoint ON_Curve::PointAt( double t ) const
{
ON_3dPoint p(0.0,0.0,0.0);
if ( !EvPoint(t,p) )
p = ON_3dPoint::UnsetPoint;
return p;
}
ON_3dPoint ON_Curve::PointAtStart() const
{
return PointAt(Domain().Min());
}
ON_3dPoint ON_Curve::PointAtEnd() const
{
return PointAt(Domain().Max());
}
bool ON_Curve::SetStartPoint(ON_3dPoint start_point)
{
ON_3dPoint S = PointAtStart();
return (S == start_point) ? true : false;
}
bool ON_Curve::SetEndPoint(ON_3dPoint end_point)
{
ON_3dPoint E = PointAtEnd();
return (E == end_point) ? true : false;
}
ON_3dVector ON_Curve::DerivativeAt( double t ) const
{
ON_3dPoint p(0.0,0.0,0.0);
ON_3dVector d(0.0,0.0,0.0);
Ev1Der(t,p,d);
return d;
}
ON_3dVector ON_Curve::TangentAt( double t ) const
{
ON_3dPoint point;
ON_3dVector tangent;
EvTangent( t, point, tangent );
return tangent;
}
ON_3dVector ON_Curve::CurvatureAt( double t ) const
{
ON_3dPoint point;
ON_3dVector tangent, kappa;
EvCurvature( t, point, tangent, kappa );
return kappa;
}
bool ON_Curve::EvTangent(
double t,
ON_3dPoint& point,
ON_3dVector& tangent,