forked from mcneel/opennurbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopennurbs_math.h
2571 lines (2344 loc) · 73.6 KB
/
opennurbs_math.h
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>.
//
////////////////////////////////////////////////////////////////
#if !defined(ON_MATH_INC_)
#define ON_MATH_INC_
/*
Returns:
True (1) if nan compares and arithmetic agree with IEEE-754.
(nan != nan) is true.
(nan op x) and (x op nan) is false for op ==, <, >, <=, and >=.
(nan op x) and (x op nan) is nan for op == +, -, *, and /.
False (0) otherwise.
*/
ON_DECL
bool ON_PassesNanTest();
class ON_3dVector;
class ON_Interval;
class ON_Line;
class ON_Arc;
class ON_Plane;
/*
Description:
Class for carefully adding long list of numbers.
*/
class ON_CLASS ON_Sum
{
public:
/*
Description:
Calls ON_Sum::Begin(x)
*/
void operator=(double x);
/*
Description:
Calls ON_Sum::Plus(x);
*/
void operator+=(double x);
/*
Description:
Calls ON_Sum::Plus(-x);
*/
void operator-=(double x);
/*
Description:
Creates a sum that is ready to be used.
*/
ON_Sum();
/*
Description:
If a sum is being used more than once, call Begin()
before starting each sum.
Parameters:
starting_value - [in] Initial value of sum.
*/
void Begin( double starting_value = 0.0 );
/*
Description:
Add x to the current sum.
Parameters:
x - [in] value to add to the current sum.
*/
void Plus( double x );
/*
Description:
Add x to the current sum.
Parameters:
x - [in] value to add to the current sum.
dx - [in] symmetric uncertainty in x.
(true value is in the range x-dx to x+dx
*/
void Plus( double x, double dx );
/*
Description:
Calculates the total sum.
Parameters:
error_estimate - [out] if not nullptr, the returned value of
*error_estimate is an estimate of the error in the sum.
Returns:
Total of the sum.
Remarks:
You can get subtotals by mixing calls to Plus() and Total().
In delicate sums, some precision may be lost in the final
total if you call Total() to calculate subtotals.
*/
double Total( double* error_estimate = nullptr );
/*
Returns:
Number of summands.
*/
int SummandCount() const;
private:
enum {
sum1_max_count=256,
sum2_max_count=512,
sum3_max_count=1024
};
double m_sum_err;
double m_pos_sum;
double m_neg_sum;
int m_zero_count; // number of zeros added
int m_pos_count; // number of positive numbers added
int m_neg_count; // number of negative numbers added
int m_pos_sum1_count;
int m_pos_sum2_count;
int m_pos_sum3_count;
double m_pos_sum1[sum1_max_count];
double m_pos_sum2[sum2_max_count];
double m_pos_sum3[sum3_max_count];
int m_neg_sum1_count;
int m_neg_sum2_count;
int m_neg_sum3_count;
double m_neg_sum1[sum1_max_count];
double m_neg_sum2[sum2_max_count];
double m_neg_sum3[sum3_max_count];
double SortAndSum( int, double* );
};
/*
Description:
Abstract function with an arbitrary number of parameters
and values. ON_Evaluator is used to pass functions to
local solvers.
*/
class ON_CLASS ON_Evaluator
{
public:
/*
Description:
Construction of the class for a function that takes
parameter_count input functions and returns
value_count values. If the domain is infinite, pass
a nullptr for the domain[] and periodic[] arrays. If
the domain is finite, pass a domain[] array with
parameter_count increasing intervals. If one or more of
the parameters is periodic, pass the fundamental domain
in the domain[] array and a true in the periodic[] array.
Parameters:
parameter_count - [in] >= 1. Number of input parameters
value_count - [in] >= 1. Number of output values.
domain - [in] If not nullptr, then this is an array
of parameter_count increasing intervals
that defines the domain of the function.
periodic - [in] if not nullptr, then this is an array of
parameter_count bools where b[i] is true if
the i-th parameter is periodic. Valid
increasing finite domains must be specified
when this parameter is not nullptr.
*/
ON_Evaluator(
int parameter_count,
int value_count,
const ON_Interval* domain,
const bool* periodic
);
virtual ~ON_Evaluator();
/*
Description:
Evaluate the function that takes m_parameter_count parameters
and returns a m_value_count dimensional point.
Parameters:
parameters - [in] array of m_parameter_count evaluation parameters
values - [out] array of m_value_count function values
jacobian - [out] If nullptr, simply evaluate the value of the function.
If not nullptr, this is the jacobian of the function.
jacobian[i][j] = j-th partial of the i-th value
0 <= i < m_value_count,
0 <= j < m_parameter_count
If not nullptr, then all the memory for the
jacobian is allocated, you just need to fill
in the answers.
Example:
If f(u,v) = square of the distance from a fixed point P to a
surface evaluated at (u,v), then
values[0] = (S-P)o(S-P)
jacobian[0] = ( 2*(Du o (S-P)), 2*(Dv o (S-P)) )
where S, Du, Dv = surface point and first partials evaluated
at u=parameters[0], v = parameters[1].
If the function takes 3 parameters, say (x,y,z), and returns
two values, say f(x,y,z) and g(z,y,z), then
values[0] = f(x,y,z)
values[1] = g(x,y,z)
jacobian[0] = (DfDx, DfDy, DfDz)
jacobian[1] = (DgDx, DgDy, DgDz)
where dfx denotes the first partial of f with respect to x.
Returns:
0 = unable to evaluate
1 = successful evaluation
2 = found answer, terminate search
*/
virtual int Evaluate(
const double* parameters,
double* values,
double** jacobian
) = 0;
/*
Description:
OPTIONAL ability to evaluate the hessian in the case when
m_value_count is one. If your function has more that
one value or it is not feasible to evaluate the hessian,
then do not override this function. The default implementation
returns -1.
Parameters:
parameters - [in] array of m_parameter_count evaluation parameters
value - [out] value of the function (one double)
gradient - [out] The gradient of the function. This is a vector
of length m_parameter_count; gradient[i] is
the first partial of the function with respect to
the i-th parameter.
hessian - [out] The hessian of the function. This is an
m_parameter_count x m_parameter_count
symmetric matrix: hessian[i][j] is the
second partial of the function with respect
to the i-th and j-th parameters. The evaluator
is responsible for filling in both the upper
and lower triangles. Since the matrix is
symmetrix, you should do something like evaluate
the upper triangle and copy the values to the
lower triangle.
Returns:
-1 = Hessian evaluation not available.
0 = unable to evaluate
1 = successful evaluation
2 = found answer, terminate search
*/
virtual int EvaluateHessian(
const double* parameters,
double* value,
double* gradient,
double** hessian
);
// Number of the function's input parameters. This number
// is >= 1 and is specified in the constructor.
const int m_parameter_count;
// Number of the function's output values. This number
// is >= 1 and is specified in the constructor.
const int m_value_count;
/*
Description:
Functions can have finite or infinite domains. Finite domains
are specified by passing the domain[] array to the constructor
or filling in the m_domain[] member variable. If
m_domain.Count() == m_parameter_count > 0, then the function
has finite domains.
Returns:
True if the domain of the function is finite.
*/
bool FiniteDomain() const;
/*
Description:
If a function has a periodic parameter, then the m_domain
interval for that parameter is the fundamental domain and
the m_bPeriodicParameter bool for that parameter is true.
A parameter is periodic if, and only if,
m_domain.Count() == m_parameter_count, and
m_bPeriodicParameter.Count() == m_parameter_count, and
m_bPeriodicParameter[parameter_index] is true.
Returns:
True if the function parameter is periodic.
*/
bool Periodic(
int parameter_index
) const;
/*
Description:
If a function has a periodic parameter, then the m_domain
interval for that parameter is the fundamental domain and
the m_bPeriodicParameter bool for that parameter is true.
A parameter is periodic if, and only if,
m_domain.Count() == m_parameter_count, and
m_bPeriodicParameter.Count() == m_parameter_count, and
m_bPeriodicParameter[parameter_index] is true.
Returns:
The domain of the parameter. If the domain is infinite,
the (-1.0e300, +1.0e300) is returned.
*/
ON_Interval Domain(
int parameter_index
) const;
// If the function has a finite domain or periodic
// parameters, then m_domain[] is an array of
// m_parameter_count finite increasing intervals.
ON_SimpleArray<ON_Interval> m_domain;
// If the function has periodic parameters, then
// m_bPeriodicParameter[] is an array of m_parameter_count
// bools. If m_bPeriodicParameter[i] is true, then
// the i-th parameter is periodic and m_domain[i] is
// the fundamental domain for that parameter.
ON_SimpleArray<bool> m_bPeriodicParameter;
private:
ON_Evaluator(); // prohibit default constructor
ON_Evaluator& operator=(const ON_Evaluator&); // prohibit operator= (can't copy const members)
};
/*
Description:
Test a double to make sure it is a valid number.
Returns:
(x > ON_UNSET_VALUE && x < ON_UNSET_POSITIVE_VALUE)
*/
ON_DECL
bool ON_IsValid( double x );
/*
Returns:
(x > 0.0 && x < ON_UNSET_POSITIVE_VALUE);
*/
ON_DECL
bool ON_IsValidPositiveNumber(double x);
/*
Returns:
(x > ON_UNSET_VALUE && x < 0.0));
*/
ON_DECL
bool ON_IsValidNegativeNumber(double x);
/*
Returns:
-1: a < b or a is not a nan and b is a nan
+1: a > b or a is a nan and b is a not nan
0: a == b or both a and b are nans
*/
ON_DECL
int ON_CompareDouble(
double a,
double b
);
ON_DECL
int ON_CompareDoubleArray(
size_t count,
const double* a,
const double* b
);
/*
Returns:
-1: a < b or a is not a nan and b is a nan
+1: a > b or a is a nan and b is a not nan
0: a == b or both a and b are nans
*/
ON_DECL
int ON_CompareFloat(
float a,
float b
);
ON_DECL
bool ON_IsValidFloat( float x );
ON_DECL
bool ON_IsNaNd(double x);
ON_DECL
bool ON_IsQNaNd(double x);
ON_DECL
bool ON_IsSNaNd(double x);
ON_DECL
bool ON_IsNaNf(float x);
ON_DECL
bool ON_IsQNaNf(float x);
ON_DECL
bool ON_IsSNaNf(float x);
/*
class ON_CLASS ON_TimeLimit
{
ON_TimeLimit();
ON_TimeLimit(ON__UINT64 time_limit_seconds);
void SetTimeLimit(ON__UINT64 time_limit_seconds);
bool Continue() const;
bool IsSet() const;
private:
ON__UINT64 m_time_limit[2];
};
*/
// The ON_IS_FINITE and ON_IS_VALID defines are much faster
// than calling ON_IsValid(), but need to be used when
// the macro expansion works.
#if defined(ON_LITTLE_ENDIAN)
// works on little endian CPUs with IEEE doubles
#define ON_IS_FINITE(x) (0x7FF0 != (*((unsigned short*)(&x) + 3) & 0x7FF0))
#define ON_IS_INFINITE(x) (0x7FF0 == (*((unsigned short*)(&x) + 3) & 0x7FF0))
#elif defined(ON_BIG_ENDIAN)
// works on big endian CPUs with IEEE doubles
#define ON_IS_FINITE(x) (0x7FF0 != (*((unsigned short*)(&x)) & 0x7FF0))
#define ON_IS_INFINITE(x) (0x7FF0 == (*((unsigned short*)(&x)) & 0x7FF0))
#else
// Returns true if x is a finite double. Specifically,
// _finite returns a nonzero value (true) if its argument x
// is not infinite, that is, if -INF < x < +INF.
// It returns 0 (false) if the argument is infinite or a NaN.
//
// If you are trying to compile opennurbs on a platform
// that does not support finite(), then see if you can
// use _fpclass(), fpclass(), _isnan(), or isnan(). If
// you can't find anything, then just set this
// function to return true.
#if defined(_GNU_SOURCE)
// if you are using an older version of gcc, use finite()
//#define ON_IS_FINITE(x) (finite(x)?true:false)
#define ON_IS_FINITE(x) (isfinite(x)?true:false)
#else
#define ON_IS_FINITE(x) (_finite(x)?true:false)
#endif
#endif
#define ON_IS_FINITE_FLOAT(x) ((x) <= 3.402823466e+38F && (x) >= -3.402823466e+38F)
#define ON_IS_INFINITE_FLOAT(x) ((x) > 3.402823466e+38F || (x) < -3.402823466e+38F)
#define ON_IS_VALID(x) ((x) > ON_UNSET_VALUE && (x) < ON_UNSET_POSITIVE_VALUE)
// March 27, 2024 - Tim
// Fix for https://mcneel.myjetbrains.com/youtrack/issue/RH-81184
// The vertexes were crap just not quite ON_UNSET_VALUE crap
#define ON_CV_COORDINATE_IS_VALID(x) (-1.0e307 < x && x < 1.0e307)
#define ON_IS_VALID_FLOAT(x) ((x) > ON_UNSET_FLOAT && (x) < ON_UNSET_POSITIVE_FLOAT)
#define ON_IS_UNSET_DOUBLE(x) (ON_UNSET_VALUE == (x) || ON_UNSET_POSITIVE_VALUE == (x))
#define ON_IS_UNSET_FLOAT(x) (ON_UNSET_FLOAT == (x) || ON_UNSET_POSITIVE_FLOAT == (x))
#define ON_IS_NAN(x) (!((x)==(x)))
ON_DECL
float ON_ArrayDotProduct( // returns AoB
int, // size of arrays (can be zero)
const float*, // A[]
const float* // B[]
);
ON_DECL
void ON_ArrayScale(
int, // size of arrays (can be zero)
float, // a
const float*, // A[]
float* // returns a*A[]
);
ON_DECL
void ON_Array_aA_plus_B(
int, // size of arrays (can be zero)
float, // a
const float*, // A[]
const float*, // B[]
float* // returns a*A[] + B[]
);
ON_DECL
double ON_ArrayDotProduct( // returns AoB
int, // size of arrays (can be zero)
const double*, // A[]
const double* // B[]
);
ON_DECL
double ON_ArrayDotDifference( // returns A o ( B - C )
int, // size of arrays (can be zero)
const double*, // A[]
const double*, // B[]
const double* // C[]
);
ON_DECL
double ON_ArrayMagnitude( // returns sqrt(AoA)
int, // size of arrays (can be zero)
const double* // A[]
);
ON_DECL
double ON_ArrayMagnitudeSquared( // returns AoA
int, // size of arrays (can be zero)
const double* // A[]
);
ON_DECL
double ON_ArrayDistance( // returns sqrt((A-B)o(A-B))
int, // size of arrays (can be zero)
const double*, // A[]
const double* // B[]
);
ON_DECL
double ON_ArrayDistanceSquared( // returns (A-B)o(A-B)
int, // size of arrays (can be zero)
const double*, // A[]
const double* // B[]
);
ON_DECL
void ON_ArrayScale(
int, // size of arrays (can be zero)
double, // a
const double*, // A[]
double* // returns a*A[]
);
ON_DECL
void ON_Array_aA_plus_B(
int, // size of arrays (can be zero)
double, // a
const double*, // A[]
const double*, // B[]
double* // returns a*A[] + B[]
);
ON_DECL
int ON_SearchMonotoneArray( // find a value in an increasing array
// returns -1: t < array[0]
// i: array[i] <= t < array[i+1] ( 0 <= i < length-1 )
// length-1: t == array[length-1]
// length: t >= array[length-1]
const double*, // array[]
int, // length of array
double // t = value to search for
);
/*
Description:
Compute a binomial coefficient.
Parameters:
i - [in]
j - [in]
Returns:
(i+j)!/(i!j!), if 0 <= i and 0 <= j, and 0 otherwise.
See Also:
ON_TrinomialCoefficient()
Remarks:
If (i+j) <= 52, this function is fast and returns the exact
value of the binomial coefficient.
For (i+j) > 52, the coefficient is computed recursively using
the formula bc(i,j) = bc(i-1,j) + bc(i,j-1).
For (i+j) much larger than 60, this is inefficient.
If you need binomial coefficients for large i and j, then you
should probably be using something like Stirling's Formula.
(Look up "Stirling" or "Gamma function" in a calculus book.)
*/
ON_DECL
double ON_BinomialCoefficient(
int i,
int j
);
/*
Description:
Compute a trinomial coefficient.
Parameters:
i - [in]
j - [in]
k - [in]
Returns:
(i+j+k)!/(i!j!k!), if 0 <= i, 0 <= j and 0<= k, and 0 otherwise.
See Also:
ON_BinomialCoefficient()
Remarks:
The trinomial coefficient is computed using the formula
(i+j+k)! (i+j+k)! (j+k)!
-------- = -------- * -------
i! j! k! i! (j+k)! j! k!
= ON_BinomialCoefficient(i,j+k)*ON_BinomialCoefficient(j,k)
*/
ON_DECL
double ON_TrinomialCoefficient(
int i,
int j,
int k
);
ON_DECL
bool ON_GetParameterTolerance(
double, double, // domain
double, // parameter in domain
double*, double* // parameter tolerance (tminus, tplus) returned here
);
ON_DECL
bool ON_IsValidPointList(
int, // dim
bool, // true for homogeneous rational points
int, // count
int, // stride
const float*
);
ON_DECL
bool ON_IsValidPointList(
int, // dim
bool, // true for homogeneous rational points
int, // count
int, // stride
const double*
);
/*
Description:
Determine if a list of points is planar.
Parameters:
bRational - [in]
false if the points are euclidean (x,y,z)
true if the points are homogeneous rational (x,y,z,w)
point_count - [in]
number of points
point_stride - [in]
number of doubles between point x coordinates
first point's x coordinate = points[0],
second point's x coordinate = points[point_stride],...
points - [in]
point coordinates (3d or 4d homogeneous rational)
boxMin - [in]
boxMax - [in]
optional 3d bounding box - pass nulls if not readily available
tolerance - [in] >= 0.0
plane_equation0 - [in]
If you want to test for planarity in a specific plane,
pass the plane equation in here. If you want to find
a plane containing the points, pass null here.
plane_equation - [out]
If this point is not null, then the equation of the plane
containing the points is returned here.
Returns:
0 - points are not coplanar to the specified tolerance
1 - points are coplanar to the specified tolerance
2 - points are collinear to the specified tolerance
(in this case, plane_equation is not a unique answer)
3 - points are coincident to the specified tolerance
(in this case, plane_equation is not a unique answer)
*/
ON_DECL
int ON_IsPointListPlanar(
bool bRational,
int count,
int stride,
const double* points,
const double* boxMin,
const double* boxMax,
double tolerance,
ON_PlaneEquation* plane_equation
);
ON_DECL
bool ON_IsValidPointGrid(
int, // dim
bool, // true for homogeneous rational points
int, int, // point_count0, point_count1,
int, int, // point_stride0, point_stride1,
const double*
);
ON_DECL
bool ON_ReversePointList(
int, // dim
bool, // true for homogeneous rational points
int, // count
int, // stride
double*
);
ON_DECL
bool ON_ReversePointGrid(
int, // dim
bool, // true for homogeneous rational points
int, int, // point_count0, point_count1,
int, int, // point_stride0, point_stride1,
double*,
int // dir = 0 or 1
);
ON_DECL
bool ON_SwapPointListCoordinates(
int, // count
int, // stride
float*,
int, int // coordinates to swap
);
ON_DECL
bool ON_SwapPointListCoordinates(
int, // count
int, // stride
double*,
int, int // coordinates to swap
);
ON_DECL
bool ON_SwapPointGridCoordinates(
int, int, // point_count0, point_count1,
int, int, // point_stride0, point_stride1,
double*,
int, int // coordinates to swap
);
ON_DECL
bool ON_TransformPointList(
int, // dim
bool, // true for homogeneous rational points
int, // count
int, // stride
float*,
const ON_Xform&
);
ON_DECL
bool ON_TransformPointList(
int, // dim
bool, // true for homogeneous rational points
int, // count
int, // stride
double*,
const ON_Xform&
);
ON_DECL
bool ON_TransformPointGrid(
int, // dim
bool, // true for homogeneous rational points
int, int, // point_count0, point_count1,
int, int, // point_stride0, point_stride1,
double*,
const ON_Xform&
);
ON_DECL
bool ON_TransformVectorList(
int, // dim
int, // count
int, // stride
float*,
const ON_Xform&
);
ON_DECL
bool ON_TransformVectorList(
int, // dim
int, // count
int, // stride
double*,
const ON_Xform&
);
/*
Parameters:
dim - [in]
>= 1
is_rat - [in]
true if the points are rational and points[dim] is the "weight"
pointA - [in]
pointB - [in]
point coordinates
Returns:
True if the input is valid and for each coordinate pair,
|a-b| <= ON_ZERO_TOLERANCE
or |a-b| <= (fabs(a)+fabs(b))*ON_RELATIVE_TOLERANCE.
False otherwise.
*/
ON_DECL
bool ON_PointsAreCoincident(
int dim,
bool is_rat,
const double* pointA,
const double* pointB
);
/*
Description
See ON_PointsAreCoincident() for a description of when opennurbs
considers two points to be coincident.
Parameters:
dim - [in]
>= 1
is_rat - [in]
true if the points are rational and points[dim] is the "weight"
point_count - [in]
number of points >= 2
point_stride - [in]
>= (0 != is_rat) ? (dim+1) : dim
points - [in]
point coordinates
Returns:
True if the first and last points are coincident and all other
points in the list are coincident with the previous point.
False if there are points that are not coincident or
point_count < 2 or other input parameters are invalid.
*/
ON_DECL
bool ON_PointsAreCoincident(
int dim,
bool is_rat,
int point_count,
int point_stride,
const double* points
);
ON_DECL
int ON_ComparePoint( // returns
// -1: first < second
// 0: first == second
// +1: first > second
int dim, // dim (>=0)
bool israt, // true for rational CVs
const double* cv0, // first CV
const double* cv1 // second CV
);
ON_DECL
int ON_ComparePointList( // returns
// -1: first < second
// 0: first == second
// +1: first > second
int, // dim (>=0)
bool, // true for rational CVs
int, // count
// first point list
int, // stride
const double*, // point
// second point list
int, // stride
const double* // point
);
ON_DECL
bool ON_IsPointListClosed(
int, // dim
bool, // true for homogeneous rational points
int, // count
int, // stride
const double*
);
ON_DECL
bool ON_IsPointGridClosed(
int, // dim
bool, // true for homogeneous rational points
int, int, // point_count0, point_count1,
int, int, // point_stride0, point_stride1,
const double*,
int // dir = 0 or 1
);
/*
Description:
Assign a unique id to each point location. Coincident points
get the same id.
Parameters:
point_dim - [in]
2 or 3
point_count - [in]
>= 1
point_stride - [in]
number of coordinates to skip between points
>= point_dim
points - [in]
The first coordinate of the i-th point is points[i*point_stride]
first_point_id - [in]
Initial point id. Typically 1 or 0.
point_ids - [out]
If not null, then point_ids[] must be an array of length point_count
and the ids are returned in this array. point_ids[0] = first_point_id.
point_id_map - [out]
If point_id_index is not null, then it must have length point_count.
The returned values are a permutation of (0,1,...,point_count-1) such that
(point_ids[point_id_map[0]], ..., point_ids[point_id_map[point_count-1]])
is an increasing list of values and point_id_map[0] = 0.
Returns:
If input is valid, then an array of point_count point location
ids is returned. The i-th and j-th values in the returned array are
equal if and only if the i-th and j-th points have the same location.
If the input point_ids pointer was null, then the array memory is
allocated on the heap by calling onmalloc(). If input is not valid,
nullptr is returned.
Remarks:
The ids are invariant under invertable transformations.
Specifically, if one point point set is a rotation of another, then
the assigned ids will be the same.
*/
ON_DECL
unsigned int* ON_GetPointLocationIds(
size_t point_dim,
size_t point_count,
size_t point_stride,
const float* points,
unsigned int first_point_id,
unsigned int* point_ids,
unsigned int* point_id_map
);
ON_DECL
unsigned int* ON_GetPointLocationIds(
size_t point_dim,
size_t point_count,
size_t point_stride,
const double* points,
unsigned int first_point_id,
unsigned int* point_ids,
unsigned int* point_id_map
);
ON_DECL
unsigned int* ON_GetPointLocationIds(
size_t point_count,
const class ON_2fPoint* points,
unsigned int first_point_id,
unsigned int* point_ids,
unsigned int* point_id_map
);
ON_DECL
unsigned int* ON_GetPointLocationIds(
size_t point_count,
const class ON_3fPoint* points,
unsigned int first_point_id,
unsigned int* point_ids,
unsigned int* point_id_map
);
ON_DECL
unsigned int* ON_GetPointLocationIds(
size_t point_count,
const class ON_2dPoint* points,
unsigned int first_point_id,
unsigned int* point_ids,
unsigned int* point_id_map
);
ON_DECL
unsigned int* ON_GetPointLocationIds(
size_t point_count,
const class ON_3dPoint* points,
unsigned int first_point_id,
unsigned int* point_ids,
unsigned int* point_id_map
);
ON_DECL
int ON_SolveQuadraticEquation( // solve a*X^2 + b*X + c = 0