forked from gradientspace/geometry3Sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ProgressCancel, use to allow cancellation of computation in Red…
…ucer and Remesher
- Loading branch information
Showing
5 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
|
||
namespace g3 | ||
{ | ||
/// <summary> | ||
/// interface that provides a cancel function | ||
/// </summary> | ||
public interface ICancelSource | ||
{ | ||
bool Cancelled(); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Just wraps a func<bool> as an ICancelSource | ||
/// </summary> | ||
public class CancelFunction : ICancelSource | ||
{ | ||
public Func<bool> CancelF; | ||
public CancelFunction(Func<bool> cancelF) { | ||
CancelF = cancelF; | ||
} | ||
public bool Cancelled() { return CancelF(); } | ||
} | ||
|
||
|
||
/// <summary> | ||
/// This class is intended to be passed to long-running computes to | ||
/// 1) provide progress info back to caller (not implemented yet) | ||
/// 2) allow caller to cancel the computation | ||
/// </summary> | ||
public class ProgressCancel | ||
{ | ||
public ICancelSource Source; | ||
|
||
bool WasCancelled = false; // will be set to true if CancelF() ever returns true | ||
|
||
public ProgressCancel(ICancelSource source) | ||
{ | ||
Source = source; | ||
} | ||
public ProgressCancel(Func<bool> cancelF) | ||
{ | ||
Source = new CancelFunction(cancelF); | ||
} | ||
|
||
/// <summary> | ||
/// Check if client would like to cancel | ||
/// </summary> | ||
public bool Cancelled() | ||
{ | ||
if (WasCancelled) | ||
return true; | ||
WasCancelled = Source.Cancelled(); | ||
return WasCancelled; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters