public static void Restore(out IParametricCurve2d curve, BinaryReader reader) { curve = null; int nType = reader.ReadInt32(); if (nType == 1) { Segment2d segment = new Segment2d(); Restore(ref segment, reader); curve = segment; } else if (nType == 2) { Circle2d circle = new Circle2d(Vector2d.Zero, 1.0); Restore(ref circle, reader); curve = circle; } else if (nType == 3) { Arc2d arc = new Arc2d(Vector2d.Zero, 1.0, 0, 1); Restore(ref arc, reader); curve = arc; } else if (nType == 100) { ParametricCurveSequence2 seq = new ParametricCurveSequence2(); Restore(ref seq, reader); curve = seq; } else { throw new Exception("gSerialization.Restore: IParametricCurve2D : unknown curve type " + nType.ToString()); } }
void append(SmoothCurveElement cTo, SmoothCurveElement cAppend) { ParametricCurveSequence2 use = null; if (cTo.source is ParametricCurveSequence2) { use = cTo.source as ParametricCurveSequence2; } else { use = new ParametricCurveSequence2(); use.Append(cTo.source); } if (cAppend.source is ParametricCurveSequence2) { var cseq = cAppend.source as ParametricCurveSequence2; foreach (var c in cseq.Curves) { use.Append(c); } } else { use.Append(cAppend.source); } cTo.source = use; UpdateSampling(cTo); }
public static void Store(ParametricCurveSequence2 sequence, BinaryWriter writer) { writer.Write(sequence.IsClosed); writer.Write((int)sequence.Count); foreach (IParametricCurve2d c in sequence.Curves) { Store(c, writer); } }
public static IParametricCurve2d Convert(Polygon2d poly) { ParametricCurveSequence2 seq = new ParametricCurveSequence2(); int N = poly.VertexCount; for (int i = 0; i < N; ++i) { seq.Append(new Segment2d(poly[i], poly[(i + 1) % N])); } seq.IsClosed = true; return(seq); }
public static void Restore(ref ParametricCurveSequence2 sequence, BinaryReader reader) { sequence.IsClosed = reader.ReadBoolean(); int N = reader.ReadInt32(); for (int i = 0; i < N; ++i) { IParametricCurve2d c; Restore(out c, reader); sequence.Append(c); } }
public IParametricCurve2d Clone() { ParametricCurveSequence2 s2 = new ParametricCurveSequence2(); s2.closed = this.closed; s2.curves = new List <IParametricCurve2d>(); foreach (var c in this.curves) { s2.curves.Add(c.Clone()); } return(s2); }
public static VectorArray2d AutoSample(ParametricCurveSequence2 curves, double fSpacingLength, double fSpacingT) { int N = curves.Count; bool bClosed = curves.IsClosed; VectorArray2d[] vecs = new VectorArray2d[N]; int i = 0; int nTotal = 0; foreach (IParametricCurve2d c in curves.Curves) { vecs[i] = AutoSample(c, fSpacingLength, fSpacingT); nTotal += vecs[i].Count; i++; } int nDuplicates = (bClosed) ? N : N - 1; // handle closed here... nTotal -= nDuplicates; VectorArray2d final = new VectorArray2d(nTotal); int k = 0; for (int vi = 0; vi < N; ++vi) { VectorArray2d vv = vecs[vi]; // skip final vertex unless we are on last curve (because it is // the same as first vertex of next curve) int nStop = (bClosed || vi < N - 1) ? vv.Count - 1 : vv.Count; final.Set(k, nStop, vv); k += nStop; } return(final); }