static void Main(string[] args) { TwoD myNum = new TwoD(); for (int i = 0; i < 10; i++) { Console.WriteLine(myNum.GetNext()); } myNum.SetStart(100); for (int i = 0; i < 10; i++) { Console.WriteLine(myNum.GetNext()); } myNum.Reset(); for (int i = 0; i < 10; i++) { Console.WriteLine(myNum.GetNext()); } ISeria obj = myNum; Console.WriteLine(obj.GetNext()); Console.ReadKey(); }
/// <summary> /// Return the <see cref="TransformGesture.TransformType"/> indicated by the both fingers' movement. /// </summary> /// <param name="oldScreenPos1"> Finger one old screen position. </param> /// <param name="oldScreenPos2"> Finger two old screen position. </param> /// <param name="newScreenPos1"> Finger one new screen position. </param> /// <param name="newScreenPos2"> Finger two new screen position. </param> /// <param name="projectionParams"> Layer projection parameters. </param> /// <returns> TransformType indicated by the movement of both fingers. </returns> protected virtual TransformGesture.TransformType getIndicatedType(Vector2 oldScreenPos1, Vector2 oldScreenPos2, Vector2 newScreenPos1, Vector2 newScreenPos2, ProjectionParams projectionParams) { var pointerDelta1 = newScreenPos1 - oldScreenPos1; var pointerDelta2 = newScreenPos2 - oldScreenPos2; var deg = Vector2.Angle(pointerDelta1, pointerDelta2); if (deg < 90) { // pointers moved in same direction return(TransformGesture.TransformType.Translation); } else { // pointers moved in opposite directions var oldScreenDelta = oldScreenPos2 - oldScreenPos1; if (TwoD.IsPerpendicular(pointerDelta1, oldScreenDelta) && TwoD.IsPerpendicular(pointerDelta2, oldScreenDelta)) { return(TransformGesture.TransformType.Rotation); } else { return(TransformGesture.TransformType.Scaling); } } }
private Vector2 scaleAndRotate(Vector2 point, Vector2 center, float dR, float dS) { var delta = point - center; if (dR != 0) { delta = TwoD.Rotate(delta, dR); } if (dS != 0) { delta = delta * dS; } return(center + delta); }
/// <summary> /// Return the <see cref="TransformGesture.TransformType"/> indicated by the finger's movement. /// </summary> /// <param name="center"> Center screen position. </param> /// <param name="oldScreenPos"> Pointer old screen position. </param> /// <param name="newScreenPos"> Pointer new screen position. </param> /// <param name="projectionParams"> Layer projection parameters. </param> /// <returns> TransformType indicated by the movement of the pointer. </returns> protected virtual TransformGesture.TransformType getIndicatedType(Vector2 screenCenter, Vector2 oldScreenPos, Vector2 newScreenPos, ProjectionParams projectionParams) { var centerLine = oldScreenPos - screenCenter; var pointerDelta = newScreenPos - oldScreenPos; if (TwoD.IsPerpendicular(centerLine, pointerDelta)) { return(TransformGesture.TransformType.Rotation); } else { return(TransformGesture.TransformType.Scaling); } }
/// <inheritdoc /> protected override void pointersUpdated(IList <Pointer> pointers) { base.pointersUpdated(pointers); var projectionParams = activePointers[0].ProjectionParams; var dP = deltaPosition = Vector3.zero; var dR = deltaRotation = 0; var dS = deltaScale = 1f; #if TOUCHSCRIPT_DEBUG drawDebugDelayed(getNumPoints()); #endif if (pointersNumState != PointersNumState.InRange) { return; } var translationEnabled = (Type & TransformGesture.TransformType.Translation) == TransformGesture.TransformType.Translation; var rotationEnabled = (Type & TransformGesture.TransformType.Rotation) == TransformGesture.TransformType.Rotation; var scalingEnabled = (Type & TransformGesture.TransformType.Scaling) == TransformGesture.TransformType.Scaling; // one pointer or one cluster (points might be too close to each other for 2 clusters) if (getNumPoints() == 1 || (!rotationEnabled && !scalingEnabled)) { if (!translationEnabled) { return; // don't look for translates } if (!relevantPointers1(pointers)) { return; } // translate using one point dP = doOnePointTranslation(getPointPreviousScreenPosition(0), getPointScreenPosition(0), projectionParams); if (!simultaneousTransforms && isTransforming) { transformLock.TrySetValue(TransformGesture.TransformType.Translation); } } else { // Make sure that we actually care about the pointers moved. if (!relevantPointers2(pointers)) { return; } var newScreenPos1 = getPointScreenPosition(0); var newScreenPos2 = getPointScreenPosition(1); // Here we can't reuse last frame screen positions because points 0 and 1 can change. // For example if the first of 3 fingers is lifted off. var oldScreenPos1 = getPointPreviousScreenPosition(0); var oldScreenPos2 = getPointPreviousScreenPosition(1); var newScreenDelta = newScreenPos2 - newScreenPos1; if (newScreenDelta.sqrMagnitude > minScreenPointsPixelDistanceSquared) { if (rotationEnabled) { if (isTransforming) { dR = doRotation(oldScreenPos1, oldScreenPos2, newScreenPos1, newScreenPos2, projectionParams); } else { float d1, d2; // Find how much we moved perpendicular to the line (oldScreenPos1, oldScreenPos2) TwoD.PointToLineDistance2(oldScreenPos1, oldScreenPos2, newScreenPos1, newScreenPos2, out d1, out d2); screenPixelRotationBuffer += (d1 - d2); angleBuffer += doRotation(oldScreenPos1, oldScreenPos2, newScreenPos1, newScreenPos2, projectionParams); if (screenPixelRotationBuffer * screenPixelRotationBuffer >= screenTransformPixelThresholdSquared) { isTransforming = true; dR = angleBuffer; } } } if (scalingEnabled) { if (isTransforming) { dS *= doScaling(oldScreenPos1, oldScreenPos2, newScreenPos1, newScreenPos2, projectionParams); } else { var oldScreenDelta = oldScreenPos2 - oldScreenPos1; var newDistance = newScreenDelta.magnitude; var oldDistance = oldScreenDelta.magnitude; screenPixelScalingBuffer += newDistance - oldDistance; scaleBuffer *= doScaling(oldScreenPos1, oldScreenPos2, newScreenPos1, newScreenPos2, projectionParams); if (screenPixelScalingBuffer * screenPixelScalingBuffer >= screenTransformPixelThresholdSquared) { isTransforming = true; dS = scaleBuffer; } } } if (translationEnabled) { if (dR == 0 && dS == 1) { dP = doOnePointTranslation(oldScreenPos1, newScreenPos1, projectionParams); } else { dP = doTwoPointTranslation(oldScreenPos1, oldScreenPos2, newScreenPos1, newScreenPos2, dR, dS, projectionParams); } } if (!simultaneousTransforms && isTransforming) { var fixedType = getIndicatedType(oldScreenPos1, oldScreenPos2, newScreenPos1, newScreenPos2, projectionParams); transformLock.TrySetValue(fixedType); } } else if (translationEnabled) { // points are too close, translate using one point dP = doOnePointTranslation(oldScreenPos1, newScreenPos1, projectionParams); if (!simultaneousTransforms && isTransforming) { transformLock.TrySetValue(TransformGesture.TransformType.Translation); } } } if (!simultaneousTransforms && isTransforming) { var singleType = transformLock.Value; if (singleType != TransformGesture.TransformType.Translation) { dP = Vector3.zero; } if (singleType != TransformGesture.TransformType.Rotation) { dR = 0; } if (singleType != TransformGesture.TransformType.Scaling) { dS = 1; } if (singleType != 0 && type.HasFlag(singleType)) { transformLock.SetLock(); } } if (dP != Vector3.zero) { transformMask |= TransformGesture.TransformType.Translation; } if (dR != 0) { transformMask |= TransformGesture.TransformType.Rotation; } if (dS != 1) { transformMask |= TransformGesture.TransformType.Scaling; } if (transformMask != 0) { if (State == GestureState.Possible) { setState(GestureState.Began); } switch (State) { case GestureState.Began: case GestureState.Changed: deltaPosition = dP; deltaRotation = dR; deltaScale = dS; setState(GestureState.Changed); resetValues(); break; } } }
/// <inheritdoc /> protected override void touchesMoved(IList <TouchPoint> touches) { base.touchesMoved(touches); var projectionParams = ActiveTouches[0].ProjectionParams; var dR = deltaRotation = 0; var dS = deltaScale = 1f; #if TOUCHSCRIPT_DEBUG var worldCenter = cachedTransform.position; var screenCenter = projectionParams.ProjectFrom(worldCenter); var newScreenPos = getPointScreenPosition(); drawDebug(screenCenter, newScreenPos); #endif if (touchesNumState != TouchesNumState.InRange) { return; } var rotationEnabled = (Type & TransformType.Rotation) == TransformType.Rotation; var scalingEnabled = (Type & TransformType.Scaling) == TransformType.Scaling; if (!rotationEnabled && !scalingEnabled) { return; } if (!relevantTouches(touches)) { return; } #if !TOUCHSCRIPT_DEBUG var theTouch = activeTouches[0]; var worldCenter = cachedTransform.position; var screenCenter = projectionParams.ProjectFrom(worldCenter); var newScreenPos = theTouch.Position; #endif // Here we can't reuse last frame screen positions because points 0 and 1 can change. // For example if the first of 3 fingers is lifted off. var oldScreenPos = getPointPreviousScreenPosition(); if (rotationEnabled) { if (isTransforming) { dR = doRotation(worldCenter, oldScreenPos, newScreenPos, projectionParams); } else { // Find how much we moved perpendicular to the line (center, oldScreenPos) screenPixelRotationBuffer += TwoD.PointToLineDistance(screenCenter, oldScreenPos, newScreenPos); angleBuffer += doRotation(worldCenter, oldScreenPos, newScreenPos, projectionParams); if (screenPixelRotationBuffer * screenPixelRotationBuffer >= screenTransformPixelThresholdSquared) { isTransforming = true; dR = angleBuffer; } } } if (scalingEnabled) { if (isTransforming) { dS *= doScaling(worldCenter, oldScreenPos, newScreenPos, projectionParams); } else { screenPixelScalingBuffer += (newScreenPos - screenCenter).magnitude - (oldScreenPos - screenCenter).magnitude; scaleBuffer *= doScaling(worldCenter, oldScreenPos, newScreenPos, projectionParams); if (screenPixelScalingBuffer * screenPixelScalingBuffer >= screenTransformPixelThresholdSquared) { isTransforming = true; dS = scaleBuffer; } } } if (dR != 0 || dS != 1) { if (State == GestureState.Possible) { setState(GestureState.Began); } switch (State) { case GestureState.Began: case GestureState.Changed: deltaRotation = dR; deltaScale = dS; setState(GestureState.Changed); break; } } }
private static void test037() //****************************************************************************80 // // Purpose: // // TEST037 plots a function with a derivative discontinuity. // // Discussion: // // This is example 3.1 in the reference. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 21 September 2014 // // Author: // // John Burkardt // // Reference: // // Rick Archibald, Anne Gelb, Jungho Yoon, // Determining the location of discontinuities in the derivatives // of functions, // Applied Numerical Mathematics, // Volume 58, 2008, pages 577-592. // { List <string> command_unit = new(); List <string> data_unit = new(); int i; Console.WriteLine(""); Console.WriteLine("TEST037:"); Console.WriteLine(" Plot 2D test function #5, the discontinuous medium wave, U(x,t)."); const string header = "fxy5"; const string title = "2D test function #5, the discontinuous medium wave, U(x,t)"; const int n = 101; const double x_min = -1.0; const double x_max = 0.0; double[] x = typeMethods.r8vec_linspace_new(n, x_min, x_max); const double y_min = 0.0; const double y_max = 0.1; double[] y = typeMethods.r8vec_linspace_new(n, y_min, y_max); const string data_filename = header + "_data.txt"; for (i = 0; i < n; i++) { int j; for (j = 0; j < n; j++) { double fxy = TwoD.fxy5(x[i], y[j]); data_unit.Add(x[i] + " " + y[j] + " " + fxy + ""); } data_unit.Add(""); } File.WriteAllLines(data_filename, data_unit); Console.WriteLine(" Created data file '" + data_filename + "'"); const string command_filename = header + "_commands.txt"; command_unit.Add("# " + command_filename + ""); command_unit.Add("#"); command_unit.Add("# Usage:"); command_unit.Add("# gnuplot < " + command_filename + ""); command_unit.Add("#"); command_unit.Add("set term png"); command_unit.Add("set output '" + header + ".png'"); command_unit.Add("set view 30, 45"); command_unit.Add("set hidden3d"); command_unit.Add("set timestamp"); command_unit.Add("set xlabel '<--- X --->'"); command_unit.Add("set ylabel '<--- Y --->'"); command_unit.Add("set zlabel '<--- Z --->'"); command_unit.Add("set title '" + title + "'"); command_unit.Add("set grid"); command_unit.Add("set style data lines"); command_unit.Add("splot '" + data_filename + "' with lines"); command_unit.Add("quit"); File.WriteAllLines(command_filename, command_unit); Console.WriteLine(" Created command file '" + command_filename + "'"); }
private static void test03() //****************************************************************************80 // // Purpose: // // TEST03 plots a function with a jump discontinuity along a circle. // // Discussion: // // This is example 4.2 in the reference. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 14 February 2014 // // Author: // // John Burkardt // // Reference: // // Rick Archibald, Anne Gelb, Jungho Yoon, // Polynomial fitting for edge detection in irregularly sampled signals // and images, // SIAM Journal on Numerical Analysis, // Volume 43, Number 1, 2006, pages 259-279. // { List <string> command_unit = new(); List <string> data_unit = new(); int i; Console.WriteLine(""); Console.WriteLine("TEST03:"); Console.WriteLine(" Plot 2D test function #2, the Shepp Logan phantom."); const string header = "fxy2"; const string title = "2D test function #2, the Shepp Logan phantom"; const int n = 101; const double x_min = -1.0; const double x_max = +1.0; double[] x = typeMethods.r8vec_linspace_new(n, x_min, x_max); const double y_min = -1.0; const double y_max = +1.0; double[] y = typeMethods.r8vec_linspace_new(n, y_min, y_max); const string data_filename = header + "_data.txt"; for (i = 0; i < n; i++) { int j; for (j = 0; j < n; j++) { double fxy = TwoD.fxy2(x[i], y[j]); data_unit.Add(x[i] + " " + y[j] + " " + fxy + ""); } data_unit.Add(""); } File.WriteAllLines(data_filename, data_unit); Console.WriteLine(" Created data file '" + data_filename + "'"); const string command_filename = header + "_commands.txt"; command_unit.Add("# " + command_filename + ""); command_unit.Add("#"); command_unit.Add("# Usage:"); command_unit.Add("# gnuplot < " + command_filename + ""); command_unit.Add("#"); command_unit.Add("set term png"); command_unit.Add("set output '" + header + ".png'"); command_unit.Add("set view 30, 75"); command_unit.Add("set hidden3d"); command_unit.Add("set timestamp"); command_unit.Add("set xlabel '<--- X --->'"); command_unit.Add("set ylabel '<--- Y --->'"); command_unit.Add("set zlabel '<--- Z --->'"); command_unit.Add("set title '" + title + "'"); command_unit.Add("set grid"); command_unit.Add("set style data lines"); command_unit.Add("splot '" + data_filename + "' with lines"); command_unit.Add("quit"); File.WriteAllLines(command_filename, command_unit); Console.WriteLine(" Created command file '" + command_filename + "'"); }
/// <inheritdoc /> protected override void touchesMoved(IList <ITouch> touches) { base.touchesMoved(touches); var dP = deltaPosition = Vector3.zero; var dR = deltaRotation = 0; var dS = deltaScale = 1f; #if DEBUG drawDebugDelayed(getNumPoints()); #endif if (touchesNumState != TouchesNumState.InRange) { return; } var translationEnabled = (Type & TransformType.Translation) == TransformType.Translation; var rotationEnabled = (Type & TransformType.Rotation) == TransformType.Rotation; var scalingEnabled = (Type & TransformType.Scaling) == TransformType.Scaling; // one touch or one cluster (points might be too close to each other for 2 clusters) if (getNumPoints() == 1 || (!rotationEnabled && !scalingEnabled)) { if (!translationEnabled) { return; // don't look for translates } if (!relevantTouches1(touches)) { return; } // translate using one point dP = doOnePointTranslation(getPointPreviousScreenPosition(0), getPointScreenPosition(0)); } else { // Make sure that we actually care about the touches moved. if (!relevantTouches2(touches)) { return; } var newScreenPos1 = getPointScreenPosition(0); var newScreenPos2 = getPointScreenPosition(1); // Here we can't reuse last frame screen positions because points 0 and 1 can change. // For example if the first of 3 fingers is lifted off. var oldScreenPos1 = getPointPreviousScreenPosition(0); var oldScreenPos2 = getPointPreviousScreenPosition(1); var newScreenDelta = newScreenPos2 - newScreenPos1; if (newScreenDelta.sqrMagnitude > minScreenPointsPixelDistanceSquared) { if (rotationEnabled) { if (isTransforming) { dR = doRotation(oldScreenPos1, oldScreenPos2, newScreenPos1, newScreenPos2); } else { float d1, d2; // Find how much we moved perpendicular to the line (oldScreenPos1, oldScreenPos2) TwoD.PointToLineDistance2(oldScreenPos1, oldScreenPos2, newScreenPos1, newScreenPos2, out d1, out d2); screenPixelRotationBuffer += (d1 - d2); angleBuffer += doRotation(oldScreenPos1, oldScreenPos2, newScreenPos1, newScreenPos2); if (screenPixelRotationBuffer * screenPixelRotationBuffer >= screenTransformPixelThresholdSquared) { isTransforming = true; dR = angleBuffer; } } } if (scalingEnabled) { if (isTransforming) { dS *= doScaling(oldScreenPos1, oldScreenPos2, newScreenPos1, newScreenPos2); } else { var oldScreenDelta = oldScreenPos2 - oldScreenPos1; var newDistance = newScreenDelta.magnitude; var oldDistance = oldScreenDelta.magnitude; screenPixelScalingBuffer += newDistance - oldDistance; scaleBuffer *= doScaling(oldScreenPos1, oldScreenPos2, newScreenPos1, newScreenPos2); if (screenPixelScalingBuffer * screenPixelScalingBuffer >= screenTransformPixelThresholdSquared) { isTransforming = true; dS = scaleBuffer; } } } if (translationEnabled) { if (dR == 0 && dS == 1) { dP = doOnePointTranslation(oldScreenPos1, newScreenPos1); } else { dP = doTwoPointTranslation(oldScreenPos1, oldScreenPos2, newScreenPos1, newScreenPos2, dR, dS); } } } else if (translationEnabled) { // points are too close, translate using one point dP = doOnePointTranslation(oldScreenPos1, newScreenPos1); } } if (dP != Vector3.zero || dR != 0 || dS != 1) { if (State == GestureState.Possible) { setState(GestureState.Began); } switch (State) { case GestureState.Began: case GestureState.Changed: deltaPosition = dP; deltaRotation = dR; deltaScale = dS; setState(GestureState.Changed); break; } } }