-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathICurveR.java
466 lines (365 loc) · 21.3 KB
/
ICurveR.java
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
/*---
iGeo - http://igeo.jp
Copyright (c) 2002-2013 Satoru Sugihara
This file is part of iGeo.
iGeo is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, version 3.
iGeo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with iGeo. If not, see <http://www.gnu.org/licenses/>.
---*/
package igeo;
import java.awt.Color;
import igeo.gui.*;
/**
Reference class of NURBS curve to contain any instance of ICurveI.
@author Satoru Sugihara
*/
public class ICurveR extends IObject implements ICurveI{ // not extends IGeometry?
public ICurveI curve; // public?
public ICurveR(){ }
public ICurveR(ICurveI crv){ curve = crv; initCurve(null); }
public ICurveR(IServerI s){ super(s); }
public ICurveR(IServerI s, ICurveI crv){ super(s); curve = crv; initCurve(s); }
public ICurveR(ICurveR crv){
super(crv);
curve = crv.curve.dup(); // deep copy?
initCurve(crv.server); //?
setColor(crv.getColor());
}
public ICurveR(IServerI s, ICurveR crv){
super(s,crv);
curve = crv.curve.dup(); // deep copy?
initCurve(s); //?
setColor(crv.getColor());
}
public void initCurve(IServerI s){
if(curve instanceof ICurveGeo){ parameter = (ICurveGeo)curve; }
if(graphics==null) initGraphic(s);
}
public IGraphicObject createGraphic(IGraphicMode m){
if(m.isGL()) return new ICurveGraphicGL(this);
return null;
}
public boolean isValid(){ if(curve==null){ return false; } return curve.isValid(); }
public ICurveGeo get(){ return curve.get(); } //?
public ICurveR dup(){ return new ICurveR(this); }
//public IVecI pt(IDoubleI u){ return curve.pt(u); }
public IVecR pt(IDoubleI u){ return new IVecR(new Pt(this,u)); }
//public IVecI pt(double u){ return curve.pt(u); }
public IVecR pt(double u){ return new IVecR(new Pt(this,new IDouble(u))); }
//public void pt(double u, IVec retval){ curve.pt(u,retval); }
//public IVecI tan(IDoubleI u){ return curve.tan(u); }
public IVecR tan(IDoubleI u){ return new IVecR(new Tan(this,u)); }
//public IVecI tan(double u){ return curve.tan(u); }
public IVecR tan(double u){ return new IVecR(new Tan(this,new IDouble(u))); }
//public void tan(double u, IVec retval){ curve.tan(u,retval); }
/** getting i-th control point */
public IVecI cp(int i){ return curve.cp(i); }
/** getting i-th control point */
public IVecI cp(IIntegerI i){ return curve.cp(i); }
public IVecI[] cps(){ return curve.cps(); }
/** getting i-th edit point */
//public IVecI ep(int i){ return curve.ep(i); }
public IVecR ep(int i){ return pt(knot(i+deg())); } // test this.
/** getting i-th edit point */
//public IVecI ep(IIntegerI i){ return curve.ep(i); }
public IVecR ep(IIntegerI i){ return pt(knot(i.cp(deg((Ir)null)))); } // test this.
//public IVecI start(){ return curve.start(); }
public IVecR start(){ return pt(new IDouble(0.)); }
//public IVecI end(){ return curve.end(); }
public IVecR end(){ return pt(new IDouble(1.)); }
public IVecI startCP(){ return curve.startCP(); }
public IVecI endCP(){ return curve.endCP(); }
/** parametrically mid point of a curve */
public IVecR mid(){ return pt(0.5); }
/** returns center of geometry object */
public IVecI center(){ return curve.center(); } // not parameterized yet
/** approximate invert projection from 3D location to interanl parameter U (closest point on curve) */
public double u(IVecI pt){ return curve.u(pt); }
public double u(ISwitchE r, IVecI pt){ return u(pt); }
public IDoubleR u(ISwitchR r, IVecI pt){ return new IDoubleR(new U(this,pt)); }
/** approximate invert projection from 2D location to interanl parameter U */
public double u(IVec2I pt){ return curve.u(pt); }
public double u(ISwitchE r, IVec2I pt){ return u(pt); }
public IDoubleR u(ISwitchR r, IVec2I pt){ return new IDoubleR(new U2(this,pt)); }
/** find approximately closest point on a curve */
public IVecR closePt(IVecI pt){ return pt(u(pt)); }
/** find approximately closest point on a curve on 2D*/
public IVecR closePt(IVec2I pt){ return pt(u(pt)); }
/** distance to the closest point on a curve */
public double dist(IVecI pt){ return curve.dist(pt); }
/** distance to the closest point on a curve on 2D*/
public double dist(IVec2I pt){ return curve.dist(pt); }
public double knot(int i){ return curve.knot(i); }
public IDoubleI knot(IIntegerI i){ return curve.knot(i); } // should it be new IDoubleR ... ?
public double[] knots(){ return curve.knots(); }
public double[] knots(ISwitchE e){ return knots(); }
public IDoubleI[] knots(ISwitchR r){ return curve.knots(r); } // should it be new IDoubleR ... ?
public int knotNum(){ return curve.knotNum(); }
//public IIntegerI knotNumR(){ return curve.knotNumR(); }
public int knotNum(ISwitchE e){ return knotNum(); }
public IIntegerI knotNum(ISwitchR r){ return curve.knotNum(r); } // should it be new IIntegerR ... ?
public boolean isRational(){ return curve.isRational(); }
public boolean isRational(ISwitchE e){ return isRational(); }
public IBoolI isRational(ISwitchR r){ return curve.isRational(r); } // should it be new IBoolR ... ?
public int deg(){ return curve.deg(); }
//public IIntegerI degR(){ return curve.degR(); }
public int deg(ISwitchE e){ return deg(); }
public IIntegerI deg(ISwitchR r){ return curve.deg(r); } // should it be new IIntegerR ... ?
public int num(){ return curve.num(); }
//public IIntegerI numR(){ return curve.numR(); }
public int num(ISwitchE e){ return num(); }
public IIntegerI num(ISwitchR r){ return curve.num(r); }
public int cpNum(){ return curve.cpNum(); }
//public IIntegerI cpNumR(){ return curve.cpNumR(); }
public int cpNum(ISwitchE e){ return cpNum(); }
public IIntegerI cpNum(ISwitchR r){ return curve.cpNum(r); }
public int epNum(){ return curve.epNum(); }
//public IIntegerI epNumR(){ return curve.epNumR(); }
public int epNum(ISwitchE e){ return epNum(); }
public IIntegerI epNum(ISwitchR r){ return curve.epNum(r); }
public double len(){ return curve.len(); }
//public IDouble lenR(){ return curve.lenR(); }
public double len(ISwitchE e){ return len(); }
public IDouble len(ISwitchR r){ return curve.len(r); }
public double u(int epIdx, double epFraction){
return curve.u(epIdx,epFraction);
}
public IDoubleI u(IInteger epIdx, IDouble epFraction){
return curve.u(epIdx,epFraction);
}
public double ustart(){ return curve.ustart(); }
public double uend(){ return curve.uend(); }
//public IDoubleI ustartR(){ return curve.ustartR(); }
//public IDoubleI uendR(){ return curve.uendR(); }
public double ustart(ISwitchE e){ return ustart(); }
public double uend(ISwitchE e){ return uend(); }
public IDoubleI ustart(ISwitchR r){ return curve.ustart(r); }
public IDoubleI uend(ISwitchR r){ return curve.uend(r); }
public boolean isClosed(){ return curve.isClosed(); }
//public IBoolI isClosedR(){ return curve.isClosedR(); }
public boolean isClosed(ISwitchE e){ return isClosed(); }
//public IBoolI isClosed(ISwitchR r){ return curve.isClosed(r); } // should be new IsClosd(curve) ?
public IBoolR isClosed(ISwitchR r){ return new IBoolR(new IsClosed(this)); }
public ICurveR rev(){ curve.rev(); return this; }
/** alias of rev() */
public ICurveR revU(){ return rev(); }
/** alias of rev() */
public ICurveR flipU(){ return rev(); }
/******************************************************************************
* transformation methods; API of ITransformable interface
******************************************************************************/
public ICurveR add(double x, double y, double z){
curve.add(x,y,z); return this;
}
public ICurveR add(IDoubleI x, IDoubleI y, IDoubleI z){
curve.add(x,y,z); return this;
}
public ICurveR add(IVecI v){ curve.add(v); return this; }
public ICurveR sub(double x, double y, double z){
curve.sub(x,y,z); return this;
}
public ICurveR sub(IDoubleI x, IDoubleI y, IDoubleI z){
curve.sub(x,y,z); return this;
}
public ICurveR sub(IVecI v){ curve.sub(v); return this; }
public ICurveR mul(IDoubleI v){ curve.mul(v); return this; }
public ICurveR mul(double v){ curve.mul(v); return this; }
public ICurveR div(IDoubleI v){ curve.div(v); return this; }
public ICurveR div(double v){ curve.div(v); return this; }
public ICurveR neg(){ curve.neg(); return this; }
public ICurveR flip(){ curve.neg(); return this; }
/** scale add */
public ICurveR add(IVecI v, double f){ curve.add(v,f); return this; }
public ICurveR add(IVecI v, IDoubleI f){ curve.add(v,f); return this; }
/** scale add alias */
public ICurveR add(double f, IVecI v){ return add(v,f); }
public ICurveR add(IDoubleI f, IVecI v){ return add(v,f); }
public ICurveR rot(IDoubleI angle){ curve.rot(angle); return this; }
public ICurveR rot(double angle){ curve.rot(angle); return this; }
public ICurveR rot(IVecI axis, IDoubleI angle){ curve.rot(axis,angle); return this; }
public ICurveR rot(IVecI axis, double angle){ curve.rot(axis,angle); return this; }
public ICurveR rot(IVecI center, IVecI axis, IDoubleI angle){
curve.rot(center,axis,angle); return this;
}
public ICurveR rot(IVecI center, IVecI axis, double angle){
curve.rot(center,axis,angle); return this;
}
/** rotate to destination direction vector */
public ICurveR rot(IVecI axis, IVecI destDir){ curve.rot(axis,destDir); return this; }
/** rotate to destination point location */
public ICurveR rot(IVecI center, IVecI axis, IVecI destPt){
curve.rot(center,axis,destPt); return this;
}
public ICurveR rot2(IDoubleI angle){ return rot(angle); }
public ICurveR rot2(double angle){ return rot(angle); }
public ICurveR rot2(IVecI center, IDoubleI angle){ curve.rot2(center,angle); return this; }
public ICurveR rot2(IVecI center, double angle){ curve.rot2(center,angle); return this; }
/** rotation on xy-plane to destination direction vector */
public ICurveR rot2(IVecI destDir){ curve.rot2(destDir); return this; }
/** rotation on xy-plane to destination point location */
public ICurveR rot2(IVecI center, IVecI destPt){ curve.rot2(center,destPt); return this; }
/** alias of mul */
public ICurveR scale(IDoubleI f){ return mul(f); }
public ICurveR scale(double f){ return mul(f); }
public ICurveR scale(IVecI center, IDoubleI f){ curve.scale(center,f); return this; }
public ICurveR scale(IVecI center, double f){ curve.scale(center,f); return this; }
/** scale only in 1 direction */
public ICurveR scale1d(IVecI axis, double f){ curve.scale1d(axis,f); return this; }
public ICurveR scale1d(IVecI axis, IDoubleI f){ curve.scale1d(axis,f); return this; }
public ICurveR scale1d(IVecI center, IVecI axis, double f){
curve.scale1d(center,axis,f); return this;
}
public ICurveR scale1d(IVecI center, IVecI axis, IDoubleI f){
curve.scale1d(center,axis,f); return this;
}
/** reflect(mirror) 3 dimensionally to the other side of the plane */
public ICurveR ref(IVecI planeDir){ curve.ref(planeDir); return this; }
public ICurveR ref(IVecI center, IVecI planeDir){ curve.ref(center,planeDir); return this; }
/** mirror is alias of ref */
public ICurveR mirror(IVecI planeDir){ return ref(planeDir); }
public ICurveR mirror(IVecI center, IVecI planeDir){ return ref(center,planeDir); }
/** shear operation */
public ICurveR shear(double sxy, double syx, double syz,
double szy, double szx, double sxz){
curve.shear(sxy, syx, syz, szy, szx, sxz); return this;
}
public ICurveR shear(IDoubleI sxy, IDoubleI syx, IDoubleI syz,
IDoubleI szy, IDoubleI szx, IDoubleI sxz){
curve.shear(sxy, syx, syz, szy, szx, sxz); return this;
}
public ICurveR shear(IVecI center, double sxy, double syx, double syz,
double szy, double szx, double sxz){
curve.shear(center, sxy, syx, syz, szy, szx, sxz); return this;
}
public ICurveR shear(IVecI center, IDoubleI sxy, IDoubleI syx, IDoubleI syz,
IDoubleI szy, IDoubleI szx, IDoubleI sxz){
curve.shear(center, sxy, syx, syz, szy, szx, sxz); return this;
}
public ICurveR shearXY(double sxy, double syx){ curve.shearXY(sxy,syx); return this; }
public ICurveR shearXY(IDoubleI sxy, IDoubleI syx){ curve.shearXY(sxy,syx); return this; }
public ICurveR shearXY(IVecI center, double sxy, double syx){ curve.shearXY(center,sxy,syx); return this; }
public ICurveR shearXY(IVecI center, IDoubleI sxy, IDoubleI syx){ curve.shearXY(center,sxy,syx); return this; }
public ICurveR shearYZ(double syz, double szy){ curve.shearYZ(syz,szy); return this; }
public ICurveR shearYZ(IDoubleI syz, IDoubleI szy){ curve.shearYZ(syz,szy); return this; }
public ICurveR shearYZ(IVecI center, double syz, double szy){ curve.shearYZ(center,syz,szy); return this; }
public ICurveR shearYZ(IVecI center, IDoubleI syz, IDoubleI szy){ curve.shearYZ(center,syz,szy); return this; }
public ICurveR shearZX(double szx, double sxz){ curve.shearZX(szx,sxz); return this; }
public ICurveR shearZX(IDoubleI szx, IDoubleI sxz){ curve.shearZX(szx,sxz); return this; }
public ICurveR shearZX(IVecI center, double szx, double sxz){ curve.shearZX(center,szx,sxz); return this; }
public ICurveR shearZX(IVecI center, IDoubleI szx, IDoubleI sxz){ curve.shearZX(center,szx,sxz); return this; }
/** translate is alias of add() */
public ICurveR translate(double x, double y, double z){ return add(x,y,z); }
public ICurveR translate(IDoubleI x, IDoubleI y, IDoubleI z){ return add(x,y,z); }
public ICurveR translate(IVecI v){ return add(v); }
/** mv() is alias of add() */
public ICurveR mv(double x, double y, double z){ return add(x,y,z); }
public ICurveR mv(IDoubleI x, IDoubleI y, IDoubleI z){ return add(x,y,z); }
public ICurveR mv(IVecI v){ return add(v); }
// method name cp() is used as getting control point method in curve and surface but here used also as copy because of the priority of variable fitting of diversed users' mind set over the clarity of the code organization
/** cp() is alias of dup() */
public ICurveR cp(){ return dup(); }
/** cp() is alias of dup().add() */
public ICurveR cp(double x, double y, double z){ return dup().add(x,y,z); }
/** cp() is alias of dup().add() */
public ICurveR cp(IDoubleI x, IDoubleI y, IDoubleI z){ return dup().add(x,y,z); }
/** cp() is alias of dup().add() */
public ICurveR cp(IVecI v){ return dup().add(v); }
public ICurveR transform(IMatrix3I mat){ curve.transform(mat); return this; }
public ICurveR transform(IMatrix4I mat){ curve.transform(mat); return this; }
public ICurveR transform(IVecI xvec, IVecI yvec, IVecI zvec){
curve.transform(xvec,yvec,zvec); return this;
}
public ICurveR transform(IVecI xvec, IVecI yvec, IVecI zvec, IVecI translate){
curve.transform(xvec,yvec,zvec,translate); return this;
}
/******************************************************************************
* IObject methods
******************************************************************************/
public ICurveR name(String nm){ super.name(nm); return this; }
public ICurveR layer(ILayer l){ super.layer(l); return this; }
public ICurveR hide(){ super.hide(); return this; }
public ICurveR show(){ super.show(); return this; }
public ICurveR clr(IColor c){ super.clr(c); return this; }
public ICurveR clr(IColor c, int alpha){ super.clr(c,alpha); return this; }
public ICurveR clr(IColor c, float alpha){ super.clr(c,alpha); return this; }
public ICurveR clr(IColor c, double alpha){ super.clr(c,alpha); return this; }
public ICurveR clr(IObject o){ super.clr(o); return this; }
public ICurveR clr(Color c){ super.clr(c); return this; }
public ICurveR clr(Color c, int alpha){ super.clr(c,alpha); return this; }
public ICurveR clr(Color c, float alpha){ super.clr(c,alpha); return this; }
public ICurveR clr(Color c, double alpha){ super.clr(c,alpha); return this; }
public ICurveR clr(int gray){ super.clr(gray); return this; }
public ICurveR clr(float fgray){ super.clr(fgray); return this; }
public ICurveR clr(double dgray){ super.clr(dgray); return this; }
public ICurveR clr(int gray, int alpha){ super.clr(gray,alpha); return this; }
public ICurveR clr(float fgray, float falpha){ super.clr(fgray,falpha); return this; }
public ICurveR clr(double dgray, double dalpha){ super.clr(dgray,dalpha); return this; }
public ICurveR clr(int r, int g, int b){ super.clr(r,g,b); return this; }
public ICurveR clr(float fr, float fg, float fb){ super.clr(fr,fg,fb); return this; }
public ICurveR clr(double dr, double dg, double db){ super.clr(dr,dg,db); return this; }
public ICurveR clr(int r, int g, int b, int a){ super.clr(r,g,b,a); return this; }
public ICurveR clr(float fr, float fg, float fb, float fa){ super.clr(fr,fg,fb,fa); return this; }
public ICurveR clr(double dr, double dg, double db, double da){ super.clr(dr,dg,db,da); return this; }
public ICurveR hsb(float h, float s, float b, float a){ super.hsb(h,s,b,a); return this; }
public ICurveR hsb(double h, double s, double b, double a){ super.hsb(h,s,b,a); return this; }
public ICurveR hsb(float h, float s, float b){ super.hsb(h,s,b); return this; }
public ICurveR hsb(double h, double s, double b){ super.hsb(h,s,b); return this; }
public ICurveR setColor(Color c){ super.setColor(c); return this; }
public ICurveR setColor(Color c, int alpha){ super.setColor(c,alpha); return this; }
public ICurveR setColor(int gray){ super.setColor(gray); return this; }
public ICurveR setColor(float fgray){ super.setColor(fgray); return this; }
public ICurveR setColor(double dgray){ super.setColor(dgray); return this; }
public ICurveR setColor(int gray, int alpha){ super.setColor(gray,alpha); return this; }
public ICurveR setColor(float fgray, float falpha){ super.setColor(fgray,falpha); return this; }
public ICurveR setColor(double dgray, double dalpha){ super.setColor(dgray,dalpha); return this; }
public ICurveR setColor(int r, int g, int b){ super.setColor(r,g,b); return this; }
public ICurveR setColor(float fr, float fg, float fb){ super.setColor(fr,fg,fb); return this; }
public ICurveR setColor(double dr, double dg, double db){ super.setColor(dr,dg,db); return this; }
public ICurveR setColor(int r, int g, int b, int a){ super.setColor(r,g,b,a); return this; }
public ICurveR setColor(float fr, float fg, float fb, float fa){ super.setColor(fr,fg,fb,fa); return this; }
public ICurveR setColor(double dr, double dg, double db, double da){ super.setColor(dr,dg,db,da); return this; }
public ICurveR setHSBColor(float h, float s, float b, float a){ super.setHSBColor(h,s,b,a); return this; }
public ICurveR setHSBColor(double h, double s, double b, double a){ super.setHSBColor(h,s,b,a); return this; }
public ICurveR setHSBColor(float h, float s, float b){ super.setHSBColor(h,s,b); return this; }
public ICurveR setHSBColor(double h, double s, double b){ super.setHSBColor(h,s,b); return this; }
public ICurveR weight(double w){ super.weight(w); return this; }
public ICurveR weight(float w){ super.weight(w); return this; }
static public class IsClosed extends IParameterObject implements IBoolOp{
public ICurveOp crv;
public IsClosed(ICurveOp c){ crv=c; }
public boolean x(){ return crv.get().isClosed(); }
public IBool get(){ return crv.get().isClosed((Ir)null); }
}
static public class U extends IParameterObject implements IDoubleOp{
public ICurveOp crv;
public IVecI pt;
public U(ICurveOp c, IVecI p){ crv=c; pt=p; }
public double x(){ return crv.get().u(pt); }
public IDouble get(){ return crv.get().u((Ir)null,pt); }
}
static public class U2 extends IParameterObject implements IDoubleOp{
public ICurveOp crv;
public IVec2I pt;
public U2(ICurveOp c, IVec2I p){ crv=c; pt=p; }
public double x(){ return crv.get().u(pt); }
public IDouble get(){ return crv.get().u((Ir)null,pt); }
}
static public class Pt extends IParameterObject implements IVecOp{
public ICurveOp crv;
public IDoubleOp u;
public Pt(ICurveOp c, IDoubleOp uval){ crv=c; u=uval; }
public IVec get(){ return crv.get().pt(u.x()); }
}
static public class Tan extends IParameterObject implements IVecOp{
public ICurveOp crv;
public IDoubleOp u;
public Tan(ICurveOp c, IDoubleOp uval){ crv=c; u=uval; }
public IVec get(){ return crv.get().tan(u.x()); }
}
}