private void ensureNoDefault() { if (_nonZero.Equals(default(NonZero))) { _nonZero = NonZero.One; } }
public static Crossings FindCrossings(PathIterator pi, double xlo, double ylo, double xhi, double yhi) { Crossings cross; if (pi.GetWindingRule() == PathIterator.WIND_EVEN_ODD) { cross = new EvenOdd(xlo, ylo, xhi, yhi); } else { cross = new NonZero(xlo, ylo, xhi, yhi); } // coords array is big enough for holding: // coordinates returned from currentSegment (6) // OR // two subdivided quadratic curves (2+4+4=10) // AND // 0-1 horizontal splitting parameters // OR // 2 parametric equation derivative coefficients // OR // three subdivided cubic curves (2+6+6+6=20) // AND // 0-2 horizontal splitting parameters // OR // 3 parametric equation derivative coefficients var coords = new int[23]; double movx = 0; double movy = 0; double curx = 0; double cury = 0; while (!pi.IsDone()) { int type = pi.CurrentSegment(coords); double newx; double newy; switch (type) { case PathIterator.SEG_MOVETO: if (movy != cury && cross.AccumulateLine(curx, cury, movx, movy)) { return(null); } movx = curx = coords[0]; movy = cury = coords[1]; break; case PathIterator.SEG_LINETO: newx = coords[0]; newy = coords[1]; if (cross.AccumulateLine(curx, cury, newx, newy)) { return(null); } curx = newx; cury = newy; break; case PathIterator.SEG_QUADTO: { newx = coords[2]; newy = coords[3]; var dblCoords = new double[coords.Length]; for (int i = 0; i < coords.Length; i++) { dblCoords[i] = coords[i]; } if (cross.AccumulateQuad(curx, cury, dblCoords)) { return(null); } curx = newx; cury = newy; } break; case PathIterator.SEG_CUBICTO: { newx = coords[4]; newy = coords[5]; var dblCoords = new double[coords.Length]; for (int i = 0; i < coords.Length; i++) { dblCoords[i] = coords[i]; } if (cross.AccumulateCubic(curx, cury, dblCoords)) { return(null); } curx = newx; cury = newy; break; } case PathIterator.SEG_CLOSE: if (movy != cury && cross.AccumulateLine(curx, cury, movx, movy)) { return(null); } curx = movx; cury = movy; break; } pi.Next(); } if (movy != cury) { if (cross.AccumulateLine(curx, cury, movx, movy)) { return(null); } } return(cross); }
public NonZero(NonZero nz) { this.i = nz.i; this.Mij = nz.Mij; }
public WithNullable(decimal number, NonZero nonZero) : this() { Number = number; NonZero = nonZero; }
public WithEnsure(decimal number, NonZero nonZero) : this() { Number = number; NonZero = nonZero; }
public static Crossings FindCrossings(PathIterator pi, double xlo, double ylo, double xhi, double yhi) { Crossings cross; if (pi.GetWindingRule() == PathIterator.WIND_EVEN_ODD) { cross = new EvenOdd(xlo, ylo, xhi, yhi); } else { cross = new NonZero(xlo, ylo, xhi, yhi); } // coords array is big enough for holding: // coordinates returned from currentSegment (6) // OR // two subdivided quadratic curves (2+4+4=10) // AND // 0-1 horizontal splitting parameters // OR // 2 parametric equation derivative coefficients // OR // three subdivided cubic curves (2+6+6+6=20) // AND // 0-2 horizontal splitting parameters // OR // 3 parametric equation derivative coefficients var coords = new int[23]; double movx = 0; double movy = 0; double curx = 0; double cury = 0; while (!pi.IsDone()) { int type = pi.CurrentSegment(coords); double newx; double newy; switch (type) { case PathIterator.SEG_MOVETO: if (movy != cury && cross.AccumulateLine(curx, cury, movx, movy)) { return null; } movx = curx = coords[0]; movy = cury = coords[1]; break; case PathIterator.SEG_LINETO: newx = coords[0]; newy = coords[1]; if (cross.AccumulateLine(curx, cury, newx, newy)) { return null; } curx = newx; cury = newy; break; case PathIterator.SEG_QUADTO: { newx = coords[2]; newy = coords[3]; var dblCoords = new double[coords.Length]; for (int i = 0; i < coords.Length; i++) { dblCoords[i] = coords[i]; } if (cross.AccumulateQuad(curx, cury, dblCoords)) { return null; } curx = newx; cury = newy; } break; case PathIterator.SEG_CUBICTO: { newx = coords[4]; newy = coords[5]; var dblCoords = new double[coords.Length]; for (int i = 0; i < coords.Length; i++) { dblCoords[i] = coords[i]; } if (cross.AccumulateCubic(curx, cury, dblCoords)) { return null; } curx = newx; cury = newy; break; } case PathIterator.SEG_CLOSE: if (movy != cury && cross.AccumulateLine(curx, cury, movx, movy)) { return null; } curx = movx; cury = movy; break; } pi.Next(); } if (movy != cury) { if (cross.AccumulateLine(curx, cury, movx, movy)) { return null; } } return cross; }
Test_NonZero() { RType t = new NonZero(); RType u = new NonZero(); Print( ".Equals() and GetHashCode()" ); Assert( t.Equals( t ) ); Assert( t.Equals( u ) ); Assert( t.GetHashCode() == u.GetHashCode() ); Print( "Null passes" ); NonZero.Check( null ); Print( "Negative passes" ); NonZero.Check( Real.Create( -5m ) ); Print( "Positive passes" ); NonZero.Check( Real.Create( 5m ) ); Print( "Zero fails" ); Expect( e => RTypeException.Match( e, (vr,f) => vr.Equals( f.Down().Parameter( "item" ) ), rt => rt.Equals( new NonZero() ) ), () => NonZero.Check( Real.Create( 0m ) ) ); Print( "CheckParameter()" ); Expect( e => RTypeException.Match( e, (vr,f) => vr.Equals( f.Parameter( "param" ) ), rt => rt.Equals( new NonZero() ) ), () => NonZero.CheckParameter( Real.Create( 0m ), "param" ) ); }