forked from mcneel/opennurbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opennurbs_curveproxy.cpp
1270 lines (1144 loc) · 34.1 KB
/
opennurbs_curveproxy.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
//
// Copyright (c) 1993-2022 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_OBJECT_IMPLEMENT(ON_CurveProxy,ON_Curve,"4ED7D4D9-E947-11d3-BFE5-0010830122F0");
ON_CurveProxy::ON_CurveProxy() ON_NOEXCEPT
: m_real_curve(0)
, m_bReversed(false)
{}
ON_CurveProxy::~ON_CurveProxy()
{
m_real_curve = 0;
}
ON_CurveProxy::ON_CurveProxy( const ON_CurveProxy& src )
: ON_Curve(src)
, m_real_curve(src.m_real_curve)
, m_bReversed(src.m_bReversed)
, m_real_curve_domain(src.m_real_curve_domain)
, m_this_domain(src.m_this_domain)
{}
ON_CurveProxy& ON_CurveProxy::operator=( const ON_CurveProxy& src )
{
if ( this != &src )
{
ON_Curve::operator=(src);
m_real_curve = src.m_real_curve;
m_bReversed = src.m_bReversed;
m_real_curve_domain = src.m_real_curve_domain;
m_this_domain = src.m_this_domain;
}
return *this;
}
#if defined(ON_HAS_RVALUEREF)
ON_CurveProxy::ON_CurveProxy( ON_CurveProxy&& src) ON_NOEXCEPT
: ON_Curve(std::move(src))
, m_real_curve(src.m_real_curve)
, m_bReversed(src.m_bReversed)
, m_real_curve_domain(src.m_real_curve_domain)
, m_this_domain(src.m_this_domain)
{
src.m_real_curve = 0;
}
ON_CurveProxy& ON_CurveProxy::operator=( ON_CurveProxy&& src)
{
if ( this != &src )
{
ON_Curve::operator=(std::move(src));
m_real_curve = src.m_real_curve;
m_bReversed = src.m_bReversed;
m_real_curve_domain = src.m_real_curve_domain;
m_this_domain = src.m_this_domain;
src.m_real_curve = 0;
}
return *this;
}
#endif
ON_CurveProxy::ON_CurveProxy( const ON_Curve* c )
: m_real_curve(c), m_bReversed(0)
{
if ( m_real_curve )
m_real_curve_domain =m_this_domain = m_real_curve->Domain();
}
ON_CurveProxy::ON_CurveProxy( const ON_Curve* c, ON_Interval domain )
: m_real_curve(c),
m_bReversed(0),
m_real_curve_domain(domain),
m_this_domain(domain)
{
}
unsigned int ON_CurveProxy::SizeOf() const
{
unsigned int sz = ON_Curve::SizeOf();
sz += (sizeof(*this) - sizeof(ON_Curve));
// Do not add in size of m_real_curve - its memory is not
// managed by this class.
return sz;
}
ON__UINT32 ON_CurveProxy::DataCRC(ON__UINT32 current_remainder) const
{
if ( m_real_curve )
current_remainder = m_real_curve->DataCRC(current_remainder);
current_remainder = ON_CRC32(current_remainder,sizeof(m_bReversed),&m_bReversed);
current_remainder = ON_CRC32(current_remainder,sizeof(m_real_curve_domain),&m_real_curve_domain);
current_remainder = ON_CRC32(current_remainder,sizeof(m_this_domain),&m_this_domain);
return current_remainder;
}
double ON_CurveProxy::RealCurveParameter( double t ) const
{
// change a "this" curve parameter into an m_real_curve parameter
double s;
if ( m_bReversed || m_real_curve_domain != m_this_domain )
{
s = m_this_domain.NormalizedParameterAt(t);
if (m_bReversed)
s = 1.0 - s;
t = m_real_curve_domain.ParameterAt(s);
}
return t;
}
double ON_CurveProxy::ThisCurveParameter( double real_curve_parameter ) const
{
// change an m_real_curve curve parameter into a "this" parameter
double s;
double t = real_curve_parameter;
if ( m_bReversed || m_real_curve_domain != m_this_domain )
{
s = m_real_curve_domain.NormalizedParameterAt(real_curve_parameter);
if (m_bReversed)
s = 1.0 - s;
t = m_this_domain.ParameterAt(s);
}
return t;
}
ON_Interval ON_CurveProxy::RealCurveInterval( const ON_Interval* sub_domain ) const
{
if ( !sub_domain )
return m_real_curve_domain;
ON_Interval d = m_this_domain;
d.Intersection(*sub_domain);
double t0 = RealCurveParameter( d[m_bReversed?1:0] );
double t1 = RealCurveParameter( d[m_bReversed?0:1] );
return ON_Interval(t0,t1);
}
bool ON_CurveProxy::ProxyCurveIsReversed() const
{
return m_bReversed;
}
void ON_CurveProxy::SetProxyCurveIsReversed(bool bReversed)
{
m_bReversed = bReversed;
}
void ON_CurveProxy::SetProxyCurve( const ON_Curve* real_curve )
{
// setting m_real_curve=0 prevents crashes if user has deleted
// the "real" curve before calling SetProxyCurve().
m_real_curve = 0;
if ( real_curve )
SetProxyCurve( real_curve, real_curve->Domain() );
else
{
DestroyCurveTree();
m_real_curve_domain = ON_Interval::EmptyInterval;
m_this_domain = ON_Interval::EmptyInterval;
m_bReversed = false;
}
}
void ON_CurveProxy::SetProxyCurve( const ON_Curve* real_curve,
ON_Interval real_curve_subdomain)
{
if ( real_curve != this )
{
// setting m_real_curve=0 prevents crashes if user has deleted
// the "real" curve before calling SetProxyCurve().
m_real_curve = 0;
DestroyCurveTree();
m_real_curve_domain = ON_Interval::EmptyInterval;
m_this_domain = ON_Interval::EmptyInterval;
m_bReversed = false;
}
else
{
// If you are debugging and end up here, there is a 99% chance
// that you passed the wrong pointer to SetProxyCurve().
// However, I will assume you really meant to use a fancy self
// reference to adjust domains.
if ( IsValid() && m_this_domain.Includes(real_curve_subdomain) )
{
real_curve = m_real_curve;
// because input real_curve_subdomain was with respect to "this".
double r0 = RealCurveParameter(real_curve_subdomain[0]);
double r1 = RealCurveParameter(real_curve_subdomain[1]);
real_curve_subdomain.Set(r0,r1);
}
else
{
real_curve = 0;
}
// setting m_real_curve=0 prevents crashes if user has deleted
// the "real" curve before calling SetProxyCurve().
m_real_curve = 0;
DestroyCurveTree();
}
m_real_curve = real_curve;
if ( m_real_curve )
{
SetProxyCurveDomain( real_curve_subdomain );
}
else
{
m_real_curve_domain = real_curve_subdomain;
}
m_this_domain = m_real_curve_domain;
}
const ON_Curve* ON_CurveProxy::ProxyCurve() const
{
return m_real_curve;
}
bool ON_CurveProxy::SetProxyCurveDomain( ON_Interval proxy_curve_subdomain )
{
DestroyCurveTree();
bool rc = proxy_curve_subdomain.IsIncreasing();
if ( rc )
{
if ( m_real_curve )
{
ON_Interval cdom = m_real_curve->Domain();
cdom.Intersection( proxy_curve_subdomain );
rc = cdom.IsIncreasing();
if (rc )
m_real_curve_domain = cdom;
}
else
{
m_real_curve_domain = proxy_curve_subdomain;
}
}
return rc;
}
ON_Interval ON_CurveProxy::ProxyCurveDomain() const
{
return m_real_curve_domain;
}
ON_Curve* ON_CurveProxy::DuplicateCurve() const
{
// duplicate underlying curve
ON_Curve* dup_crv = 0;
if ( m_real_curve && m_real_curve != this )
{
dup_crv = m_real_curve->DuplicateCurve();
if ( dup_crv )
{
dup_crv->Trim(m_real_curve_domain);
if( m_bReversed )
dup_crv->Reverse();
dup_crv->SetDomain( m_this_domain );
}
}
return dup_crv;
}
bool ON_CurveProxy::IsValid( ON_TextLog* text_log ) const
{
bool rc = ( m_real_curve ) ? m_real_curve->IsValid(text_log) : false;
if ( rc && !m_real_curve_domain.IsIncreasing() )
{
rc = false;
if ( text_log)
text_log->Print("ON_CurveProxy.m_real_curve_domain is not increasing.\n");
}
if ( rc && !m_real_curve->Domain().Includes( m_real_curve_domain ) )
{
rc = false;
if ( text_log)
text_log->Print("ON_CurveProxy.m_real_curve_domain is not included m_real_curve->Domain().\n");
}
if ( rc && !m_this_domain.IsIncreasing() )
{
rc = false;
if ( text_log)
text_log->Print("ON_CurveProxy.m_this_domain is not increasing.\n");
}
return rc;
}
void
ON_CurveProxy::Dump( ON_TextLog& dump ) const
{
dump.Print("ON_CurveProxy uses %x on [%g,%g]\n",m_real_curve,m_real_curve_domain[0],m_real_curve_domain[1]);
}
bool
ON_CurveProxy::Write(
ON_BinaryArchive& // open binary file
) const
{
return false;
}
bool
ON_CurveProxy::Read(
ON_BinaryArchive& // open binary file
)
{
return false;
}
int
ON_CurveProxy::Dimension() const
{
return ( m_real_curve ) ? m_real_curve->Dimension() : 0;
}
bool ON_CurveProxy::GetBBox( // returns true if successful
double* boxmin, // minimum
double* boxmax, // maximum
bool bGrowBox
) const
{
return ( m_real_curve ) ? m_real_curve->GetBBox(boxmin,boxmax,bGrowBox) : false;
}
bool
ON_CurveProxy::Transform( const ON_Xform& )
{
return false; // cannot modify proxy objects
}
ON_Interval ON_CurveProxy::Domain() const
{
return m_this_domain;
}
bool ON_CurveProxy::SetDomain( double t0, double t1 )
{
bool rc = false;
if (t0 < t1)
{
DestroyCurveTree();
m_this_domain.Set(t0, t1);
rc = true;
}
return rc;
}
bool ON_CurveProxy::SetDomain( ON_Interval domain )
{
return SetDomain( domain[0], domain[1] ) ? true : false;
}
//Do not change SpanCount() without making sure it gives the correct result for use in GetSpanVector()
int ON_CurveProxy::SpanCount() const
{
if (!m_real_curve) return 0;
int rsc = m_real_curve->SpanCount();
ON_Interval domain = m_real_curve->Domain();
if (m_real_curve_domain == domain)
return rsc;
double* rsv = (double*)onmalloc((rsc+1)*sizeof(double));
if (!rsv) return 0;
if (!m_real_curve->GetSpanVector(rsv)){
onfree((void*)rsv);
return 0;
}
int i=0;
int sc = 0;
while (i <= rsc && rsv[i] <= m_real_curve_domain[0]) i++;
while (i <= rsc && rsv[i] < m_real_curve_domain[1]){
sc++;
i++;
}
sc++;
onfree((void*)rsv);
return sc;
}
//Do not change GetSpanVector() without making sure it is consistent with SpanCount()
bool ON_CurveProxy::GetSpanVector( double* d ) const
{
#if 0
bool rc = m_real_curve ? m_real_curve->GetSpanVector(d) : false;
if (rc && (m_bReversed || m_this_domain != m_real_curve_domain) )
{
double x;
int i, j, count = SpanCount();
for ( i = 0; i <= count; i++ )
{
x = m_real_curve_domain.NormalizedParameterAt(d[i]);
d[i] = x;
}
if ( m_bReversed )
{
for ( i = 0, j = count; i <= j; i++, j-- )
{
x = d[i];
d[i] = 1.0-d[j];
d[j] = 1.0-x;
}
}
for ( i = 0; i <= count; i++ )
{
d[i] = m_this_domain.ParameterAt(d[i]);
}
}
return rc;
#endif
if (!m_real_curve) return false;
int rsc = m_real_curve->SpanCount();
if (rsc < 1) return false;
double* rsv = (double*)onmalloc((rsc+1)*sizeof(double));
if (!rsv || !m_real_curve->GetSpanVector(rsv)) return false;
ON_Interval domain = m_real_curve->Domain();
if (m_real_curve_domain == m_this_domain && m_real_curve_domain == domain){
int i;
for (i=0; i <= rsc; i++) d[i] = rsv[i];
onfree((void*)rsv);
return true;
}
if (m_real_curve_domain[1] <= domain[0] || m_real_curve_domain[0] >= domain[1]){
onfree((void*)rsv);
return false;
}
int i=0;
int sc = 0;
d[0] = m_real_curve_domain[0];
while (i<= rsc && rsv[i] <= d[0]) i++;
while (i <= rsc && rsv[i] < m_real_curve_domain[1]){
sc++;
d[sc] = rsv[i];
i++;
}
sc++;
d[sc] = m_real_curve_domain[1];
onfree((void*)rsv);
if (m_bReversed || m_real_curve_domain != m_this_domain){
double x;
int j;
for ( i = 0; i <= sc; i++ )
{
x = m_real_curve_domain.NormalizedParameterAt(d[i]);
d[i] = x;
}
if ( m_bReversed )
{
for ( i = 0, j = sc; i <= j; i++, j-- )
{
x = d[i];
d[i] = 1.0-d[j];
d[j] = 1.0-x;
}
}
for ( i = 0; i <= sc; i++ )
{
d[i] = m_this_domain.ParameterAt(d[i]);
}
}
return true;
}
int ON_CurveProxy::Degree() const
{
return m_real_curve ? m_real_curve->Degree() : 0;
}
bool
ON_CurveProxy::GetParameterTolerance(
double t, // t = parameter in domain
double* tminus, // tminus
double* tplus // tplus
) const
{
bool rc = ( m_real_curve )
? m_real_curve->GetParameterTolerance( RealCurveParameter(t),tminus,tplus)
: false;
if (rc)
{
if ( tminus )
*tminus = ThisCurveParameter(*tminus);
if ( tplus )
*tplus = ThisCurveParameter(*tplus);
}
return rc;
}
bool
ON_CurveProxy::IsLinear( // true if curve locus is a line segment
double tolerance // tolerance to use when checking linearity
) const
{
// 12 December 2003 Dale Lear - fixed bug so this works
// when a proxy is restricted to using a linear portion
// of a non-linear real curve.
bool rc = false;
if ( 0 != m_real_curve )
{
ON_Interval cdom = m_real_curve->Domain();
if ( cdom == m_real_curve_domain )
{
rc = m_real_curve->IsLinear(tolerance) ? true : false;
}
else
{
// The ON_CurveProxy::DuplicateCurve() scope is critical
// because there are situation where people derive a
// class from ON_CurveProxy, and override the virtual
// DuplicateCurve(). In this situation I rely on getting
// the result returned by ON_CurveProxy::DuplicateCurve().
ON_Curve* temp_curve = ON_CurveProxy::DuplicateCurve();
if ( 0 != temp_curve )
{
rc = temp_curve->IsLinear(tolerance) ? true : false;
delete temp_curve;
}
}
}
return rc;
}
int ON_CurveProxy::IsPolyline(
ON_SimpleArray<ON_3dPoint>* pline_points,
ON_SimpleArray<double>* pline_t
) const
{
ON_SimpleArray<double> tmp_t;
if ( pline_points )
pline_points->SetCount(0);
if ( pline_t )
pline_t->SetCount(0);
if ( !m_real_curve_domain.IsIncreasing() )
return 0;
if ( !m_real_curve )
return 0;
const ON_Interval cdom = m_real_curve->Domain();
if ( !cdom.Includes(m_real_curve_domain) )
return 0;
// See if the "real" curve is a polyline
int rc = 0;
if ( m_real_curve_domain == cdom )
{
// proxy uses entire curve
rc = m_real_curve->IsPolyline(pline_points,pline_t);
if ( rc < 2 )
rc = 0;
if ( pline_points && pline_points->Count() != rc)
{
// The pline_points info is bogus, clear everything and
// return 0.
pline_points->SetCount(0);
if ( pline_t )
pline_t->SetCount(0);
rc = 0;
}
if ( pline_t && pline_t->Count() != rc)
{
// The pline_t info is bogus, clear everything and
// return 0.
pline_t->SetCount(0);
if ( pline_points )
pline_points->SetCount(0);
rc = 0;
}
if ( rc )
{
if ( m_bReversed )
{
if ( pline_points )
pline_points->Reverse();
if ( pline_t )
pline_t->Reverse();
}
if ( pline_points && IsClosed() && pline_points->Count() > 3 )
{
// 27 February 2003 Dale Lear
// If proxy curve says it's closed, then
// make sure end point of returned polyline
// is exactly equal to start point.
*pline_points->Last() = *pline_points->First();
}
if ( pline_t && (m_bReversed || m_real_curve_domain != m_this_domain) )
{
int i;
for ( i = 0; i < rc; i++ )
{
(*pline_t)[i] = ThisCurveParameter( (*pline_t)[i] );
}
}
}
}
else
{
// 12 December 2003 Dale Lear
// We have to extract a sub curve for the test, because
// the region in question may be a polyline and the unused
// portion may not be a polyline. This tends to happen
// when the "real" curve is a polycurve that contains
// a polyline and the polycurve has been parametrically
// trimmed during a brep operation (like a boolean).
//
// The ON_CurveProxy::DuplicateCurve() scope is critical
// because there are situation where people derive a
// class from ON_CurveProxy, and override the virtual
// DuplicateCurve(). In this situation I rely on getting
// the result returned by ON_CurveProxy::DuplicateCurve().
ON_Curve* temp_curve = ON_CurveProxy::DuplicateCurve();
if ( temp_curve )
{
rc = temp_curve->IsPolyline(pline_points,pline_t);
delete temp_curve;
}
}
return rc;
}
bool
ON_CurveProxy::IsArc( // true if curve locus in an arc or circle
const ON_Plane* plane, // if not nullptr, test is performed in this plane
ON_Arc* arc, // if not nullptr and true is returned, then arc
// arc parameters are filled in
double tolerance // tolerance to use when checking linearity
) const
{
bool rc = false;
const ON_Interval cdom = m_real_curve->Domain();
if ( cdom == m_real_curve_domain )
{
rc = m_real_curve->IsArc(plane,arc,tolerance) ? true : false;
if ( rc && arc && m_bReversed )
arc->Reverse();
}
else
{
// The ON_CurveProxy::DuplicateCurve() scope is critical
// because there are situation where people derive a
// class from ON_CurveProxy, and override the virtual
// DuplicateCurve(). In this situation I rely on getting
// the result returned by ON_CurveProxy::DuplicateCurve().
ON_Curve* temp_curve = ON_CurveProxy::DuplicateCurve();
if ( 0 != temp_curve )
{
rc = temp_curve->IsArc(plane,arc,tolerance) ? true : false;
delete temp_curve;
}
}
return rc;
}
bool
ON_CurveProxy::IsPlanar(
ON_Plane* plane, // if not nullptr and true is returned, then plane parameters
// are filled in
double tolerance // tolerance to use when checking linearity
) const
{
// RH-75060 GBA 9-June-23 Changed to consider only the m_real_curve_domain if need be.
// return (m_real_curve) ? m_real_curve->IsPlanar(plane, tolerance) : false;
bool rc = false;
if(m_real_curve)
{
rc = m_real_curve->IsPlanar(plane, tolerance);
if (!rc)
{
rc = ON_Curve::IsPlanar(plane, tolerance);
}
}
return rc;
}
bool
ON_CurveProxy::IsInPlane(
const ON_Plane& plane, // plane to test
double tolerance // tolerance to use when checking linearity
) const
{
return ( m_real_curve ) ? m_real_curve->IsInPlane(plane,tolerance) : false;
}
bool
ON_CurveProxy::IsClosed() const
{
bool rc = false;
if ( m_real_curve && m_real_curve->Domain() == m_real_curve_domain )
{
rc = m_real_curve->IsClosed();
}
return rc;
}
bool
ON_CurveProxy::IsPeriodic() const
{
bool rc = false;
if ( m_real_curve && m_real_curve->Domain() == m_real_curve_domain )
{
rc = m_real_curve->IsPeriodic();
}
return rc;
}
bool ON_CurveProxy::GetNextDiscontinuity(
ON::continuity c,
double t0,
double t1,
double* t,
int* hint,
int* dtype,
double cos_angle_tolerance,
double curvature_tolerance
) const
{
bool rc = false;
if ( 0 != dtype )
*dtype = 0;
if ( 0 != m_real_curve )
{
double s;
// convert to "real" curve parameters
double s0 = RealCurveParameter( t0 );
double s1 = RealCurveParameter( t1 );
// 21 October 2005 Dale Lear:
//
// NOTE: If m_bReversed is true, then RealCurveParameter
// will reverse the direction of the search.
// The commented out code below just messed things up.
//
//if ( m_bReversed )
//{
// // NOTE: GetNextDiscontinuity search begins at
// // "t0" and goes towards "t1" so it is ok if s0 > s1.
// s = s0; s0 = s1; s1 = s;
//}
ON::continuity parametric_c = ON::ParametricContinuity((int)c);
int realcrv_dtype = 0;
bool realcrv_rc = m_real_curve->GetNextDiscontinuity(parametric_c,s0,s1,&s,hint,&realcrv_dtype,cos_angle_tolerance,curvature_tolerance);
if ( realcrv_rc )
{
double thiscrv_t = ThisCurveParameter(s);
if ( !(t0 < thiscrv_t && thiscrv_t < t1) && !(t1 < thiscrv_t && thiscrv_t < t0) )
{
realcrv_rc = false;
realcrv_dtype = 0;
// Sometimes proxy domain adjustments kill all the precision.
// To avoid infinite loops, it is critical that *t != t0
double s2 = ON_SQRT_EPSILON*s1 + (1.0 - ON_SQRT_EPSILON)*s0;
if ( (s0 < s2 && s2 < s1) || (s1 < s2 && s2 < s0) )
{
realcrv_rc = m_real_curve->GetNextDiscontinuity(parametric_c,s2,s1,&s,hint,&realcrv_dtype,cos_angle_tolerance,curvature_tolerance);
if ( realcrv_rc )
thiscrv_t = ThisCurveParameter(s);
}
}
if ( realcrv_rc )
{
if ( (t0 < thiscrv_t && thiscrv_t < t1) || (t1 < thiscrv_t && thiscrv_t < t0) )
{
*t = thiscrv_t;
if ( dtype )
*dtype = realcrv_dtype;
rc = true;
}
}
}
if ( !rc && parametric_c != c )
{
// 20 March 2003 Dale Lear:
// Let base class test decide locus continuity questions at ends
rc = ON_Curve::GetNextDiscontinuity( c, t0, t1, t, hint, dtype, cos_angle_tolerance, curvature_tolerance );
}
}
return rc;
}
bool ON_CurveProxy::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
{
bool rc = true;
if ( m_real_curve )
{
if ( m_real_curve_domain != m_real_curve->Domain() )
{
// 20 March 2003 Dale Lear
// Added this code to correctly handle the new locus
// flavors of ON::continuity.
switch(desired_continuity)
{
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:
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:
if ( t >= Domain()[1] )
{
// Since the proxy curve is using a subset of the real curve,
// the proxy can't be closed. So if the query parameter
// is >= domain max, the curve cannot be locus continuous.
rc = false;
}
else
{
// otherwise we want the answer for a non-locus test
desired_continuity = ON::ParametricContinuity((int)desired_continuity);
}
break;
}
}
if (rc)
rc = m_real_curve->IsContinuous( desired_continuity,
RealCurveParameter(t), hint,
point_tolerance, d1_tolerance, d2_tolerance,
cos_angle_tolerance, curvature_tolerance );
}
return rc;
}
bool
ON_CurveProxy::Reverse()
{
if ( m_this_domain.IsIncreasing() )
{
m_bReversed = (m_bReversed) ? false : true;
DestroyCurveTree();
m_this_domain.Reverse();
}
return true;
}
bool
ON_CurveProxy::Evaluate( // returns false if unable to evaluate
double t, // evaluation parameter
int der_count, // number of derivatives (>=0)
int v_stride, // v[] array stride (>=Dimension())
double* v, // v[] array of length stride*(ndir+1)
int side, // optional - determines which side to evaluate from
// 0 = default
// < 0 to evaluate from below,
// > 0 to evaluate from above
int* hint // optional - evaluation hint (int) used to speed
// repeated evaluations
) const
{
// When the proxy domain is a proper subdomain of the
// real curve and we are evaluating at the end, we
// need to be certain we are getting the values
// from the active part of the curve.
double normt = m_this_domain.NormalizedParameterAt(t);
if( fabs( normt )<ON_ZERO_TOLERANCE)
side = ( std::abs(side) <= 1) ? 1 : 2;
else if( fabs(1.0 - normt)<ON_ZERO_TOLERANCE)
side = ( std::abs(side) <= 1) ? -1 : -2;
if ( 0 != side )
{
if ( m_bReversed )
{
side = -side;
}
if (m_bReversed || m_real_curve_domain != m_this_domain )
{
// 9 November 2010 Dale Lear - ON_TuneupEvaluationParameter fix
// If we have to adjust the evaluation parameter for the
// real curve and the evaluation side was specified, then
// set side to +2 or -2 to trigger the use of
// ON_TuneupEvaluationParameter() when it matters.
if ( -1 == side )
side = -2;
else if ( 1 == side )
side = 2;
}
}
double r = RealCurveParameter(t);
bool rc = ( m_real_curve )
? m_real_curve->Evaluate( r,der_count,v_stride,v,side,hint)
: false;
if ( rc && m_bReversed )
{
// negate odd derivatives
const int dim = m_real_curve->Dimension();
int di, i;
for ( di = 1; di <= der_count; di+=2 )
{
v += v_stride;
for ( i = 0; i < dim; i++ )
{
v[i] = -v[i];
}
v += v_stride;
}
}
return rc;
}
bool ON_CurveProxy::Trim(
const ON_Interval& domain
)
{
bool rc = false;
if ( m_this_domain.IsIncreasing() && m_real_curve_domain.IsIncreasing() )
{
ON_Interval trim_dom = m_this_domain;
trim_dom.Intersection(domain);
if ( trim_dom.IsIncreasing() )
{
ON_Interval real_dom = RealCurveInterval( &trim_dom );
if ( real_dom.IsIncreasing() )
{
DestroyCurveTree();
m_real_curve_domain = real_dom;
m_this_domain = trim_dom;
rc = true;
}
}
}
return rc;
}