Esempio n. 1
0
 /// isomorphism is symmetric
 public static ISO <A, B> Symm <A, B>(ISO <B, A> iso)
 {
     return(new ISO <A, B>(iso.Bw, iso.Fw));
 }
Esempio n. 2
0
 /// isomorphism is transitive
 public static ISO <A, C> Trans <A, B, C>(ISO <A, B> ab, ISO <B, C> bc)
 {
     return(new ISO <A, C>(a => bc.Fw(ab.Fw(a)), c => ab.Bw(bc.Bw(c))));
 }
Esempio n. 3
0
 /// a = b => S a = S b
 public static ISO <Optional <A>, Optional <B> > IsoS <A, B>(ISO <A, B> iso)
 {
     return(IsoOptional(iso));
 }
Esempio n. 4
0
        /// <summary>
        /// Outputs an ISO file containing the specified root to the provided output path.
        /// </summary>
        /// <param name="root">Directory to output to ISO</param>
        /// <param name="outputPath">Path to output ISO to</param>
        public static void DumpToISO(VirtualFilesystemDirectory root, string outputPath)
        {
            ISO iso = new ISO();

            iso.WriteISO(root, outputPath);
        }
Esempio n. 5
0
    // where (), the empty tuple, has 1 value, and Void has 0 value
    // If we have isoUnEither,
    // We have ISO () Void by calling isoUnEither isoEU
    // That is impossible, since we can get a Void by
    // substL on ISO () Void
    // So it is impossible to have isoUnEither


    /// Going another way is hard (and is generally impossible)
    /// Remember, for all valid ISO, converting and converting back
    /// is the same as the original value.
    /// You need this to prove some case are impossible.
    public static ISO <A, B> IsoUnOptional <A, B>(ISO <Optional <A>, Optional <B> > iso)
    {
        return(new ISO <A, B>(
                   a => iso.Fw(Optional <A> .From(a)).OrElseGet(() => iso.Fw(Optional <A> .Empty()).Get()),
                   b => iso.Bw(Optional <B> .From(b)).OrElseGet(() => iso.Bw(Optional <B> .Empty()).Get())));
    }
Esempio n. 6
0
    ///  *** MENTION ***  ///
    ///  paste your code  ///
    /// from isomorphism  ///
    ///  *** MENTION ***  ///

    // C# specific notes:
    // Optional.fmap is renamed to Optional.FlatMap

    // Sometimes, we can treat a Type as a Number:
    /// if a Type t has n distinct value, it's Number is n.
    /// This is formally called cardinality.
    /// See https://en.wikipedia.org/wiki/Cardinality
    ///
    /// Void has cardinality of 0 (we will abbreviate it Void is 0).
    /// () is 1.
    /// Bool is 2.
    /// Maybe a is 1 + a.
    /// We will be using peano arithmetic so we will write it as S a.
    /// https://en.wikipedia.org/wiki/Peano_axioms
    /// Either a b is a + b.
    /// (a, b) is a * b.
    /// a => b is b ^ a. Try counting (() => Bool) and (Bool => ())
    ///
    /// Algebraic data type got the name because
    /// it satisfies a lot of algebraic rules under isomorphism
    /// a = b => c = d => a * c = b * d
    public static ISO <Tuple <A, C>, Tuple <B, D> > isoProd <A, B, C, D>(ISO <A, B> ab, ISO <C, D> cd)
    {
        return(IsoTuple(ab, cd));
    }
Esempio n. 7
0
 public Currency(string description, ISO iso, decimal amount)
 {
     Description = description;
     Iso         = iso;
     Amount      = amount;
 }
Esempio n. 8
0
 public static ISO <List <A>, List <B> > IsoList <A, B>(ISO <A, B> iso)
 {
     return(new ISO <List <A>, List <B> >(a => a.ConvertAll(i => iso.Fw(i)), b => b.ConvertAll(i => iso.Bw(i))));
 }
Esempio n. 9
0
 private static Func <A, A> lrl <A, B>(ISO <A, B> Iso) => it => Iso.Bw(Iso.Fw(it));
Esempio n. 10
0
 private static Func <B, B> rlr <A, B>(ISO <A, B> Iso) => it => Iso.Fw(Iso.Bw(it));
Esempio n. 11
0
 public PokeSpotPokemon(int index, PokeSpotType pokeSpotType, ISO iso)
 {
     PokeSpot   = new PokeSpot(pokeSpotType, iso);
     this.index = index;
     this.iso   = iso;
 }
Esempio n. 12
0
 public PokeSpotPokemon(int index, PokeSpot pokeSpot, ISO iso)
 {
     PokeSpot   = pokeSpot;
     this.index = index;
     this.iso   = iso;
 }
Esempio n. 13
0
 public PokeSpot(PokeSpotType pokeSpot, ISO iso)
 {
     PokeSpotType = pokeSpot;
     this.iso     = iso;
 }
Esempio n. 14
0
 /// we can combine isomorphism
 public static ISO <Tuple <A, C>, Tuple <B, D> > IsoTuple <A, B, C, D>(ISO <A, B> ab, ISO <C, D> cd)
 {
     return(new ISO <Tuple <A, C>, Tuple <B, D> >(
                ac => Tuple.Create(ab.Fw(ac.Item1), cd.Fw(ac.Item2)),
                bd => Tuple.Create(ab.Bw(bd.Item1), cd.Bw(bd.Item2))));
 }
Esempio n. 15
0
        private void BtnCreateISO_OnClick(object sender, RoutedEventArgs e)
        {
            if (btnCreateISO.Label == Localization.GetString("FrmISOMaker", 6))
            {
                if (lblDirectory.Content.ToString().Equals(Localization.GetString("FrmISOMaker", 10)))
                {
                    MessageBox.Show(Localization.GetString("FrmISOMaker", 10), "");
                    return;
                }

                if (lblISO.Content.ToString().Equals(Localization.GetString("FrmISOMaker", 9)))
                {
                    MessageBox.Show(Localization.GetString("FrmISOMaker", 9), "");
                    return;
                }

                var directory = new DirectoryInfo(lblDirectory.Content.ToString());
                var files     = directory.GetFiles("*", SearchOption.AllDirectories);

                var filtered = files.Select(f => f)
                               .Where(f => (f.Attributes & FileAttributes.Directory) != FileAttributes.Directory);

                if (!filtered.Any())
                {
                    MessageBox.Show(Localization.GetString("FrmISOMaker", 21), Localization.GetString("Global", 68));
                    return;
                }

                var timer = new ElapsedTimer(ref txtTime);

                timer.Start();
                Enable(false);
                cancel         = false;
                lblStatus.Text = Localization.GetString("FrmISOMaker", 18) + "...";

                btnCreateISO.Label = Localization.GetString("Global", 66);
                var folder  = lblDirectory.Content.ToString();
                var isoPath = lblISO.Content.ToString();
                iso = new ISO(folder, isoPath, txtLabel.Text);
                iso.ProgressChanged += iso_ProgressChanged;
                try
                {
                    iso.CreateISO();

                    if (cancel)
                    {
                        pbProgress.Foreground = Brushes.Gold;
                        DeleteISO();
                        lblStatus.Text = Localization.GetString("FrmISOMaker", 20);
                    }
                    else
                    {
                        lblStatus.Text = Localization.GetString("FrmISOMaker", 19);
                    }
                }
                catch (Exception Ex)
                {
                    DeleteISO();
                    lblStatus.Text        = Localization.GetString("Global", 67) + ": " + Ex.Message;
                    pbProgress.Foreground = Brushes.Red;
                }
                timer.Stop();

                Enable(true);
                btnCreateISO.Label     = Localization.GetString("FrmISOMaker", 6);
                btnCreateISO.IsEnabled = true;
            }
            else
            {
                cancel = true;
                pbProgress.Foreground  = Brushes.Gold;
                btnCreateISO.IsEnabled = false;
                iso.Cancel();
            }
        }
Esempio n. 16
0
 public static ISO <Either <A, C>, Either <B, D> > IsoEither <A, B, C, D>(ISO <A, B> ab, ISO <C, D> cd)
 {
     return(new ISO <Either <A, C>, Either <B, D> >(
                l => l.Match(a => Either <B, D> .Left(ab.Fw(a)), c => Either <B, D> .Right(cd.Fw(c))),
                r => r.Match(b => Either <A, C> .Left(ab.Bw(b)), d => Either <A, C> .Right(cd.Bw(d)))));
 }
Esempio n. 17
0
 public static void SetISO(Device devnum, ISO value)
 {
     throw new NotImplementedException("なにこれ");
 }
Esempio n. 18
0
 public static ISO <Optional <A>, Optional <B> > IsoOptional <A, B>(ISO <A, B> iso)
 {
     return(new ISO <Optional <A>, Optional <B> >(a => a.Map(iso.Fw), b => b.Map(iso.Bw)));
 }
Esempio n. 19
0
        /// <summary>
        /// Views the did load.
        /// </summary>
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Hide no camera label
            NoCamera.Hidden = ThisApp.CameraAvailable;

            // Attach to camera view
            ThisApp.Recorder.DisplayView = CameraView;

            // Set min and max values
            Offset.MinValue = ThisApp.CaptureDevice.MinExposureTargetBias;
            Offset.MaxValue = ThisApp.CaptureDevice.MaxExposureTargetBias;

            Duration.MinValue = 0.001f;
            Duration.MaxValue = 1f;

            ISO.MinValue = ThisApp.CaptureDevice.ActiveFormat.MinISO;
            ISO.MaxValue = ThisApp.CaptureDevice.ActiveFormat.MaxISO;

            Bias.MinValue = ThisApp.CaptureDevice.MinExposureTargetBias;
            Bias.MaxValue = ThisApp.CaptureDevice.MaxExposureTargetBias;

            // Create a timer to monitor and update the UI
            SampleTimer          = new Timer(5000);
            SampleTimer.Elapsed += (sender, e) => {
                // Update position slider
                Offset.BeginInvokeOnMainThread(() => {
                    Offset.Value = ThisApp.Input.Device.ExposureTargetOffset;
                });

                Duration.BeginInvokeOnMainThread(() => {
                    var newDurationSeconds = CMTimeGetSeconds(ThisApp.Input.Device.ExposureDuration);
                    var minDurationSeconds = Math.Max(CMTimeGetSeconds(ThisApp.CaptureDevice.ActiveFormat.MinExposureDuration), ExposureMinimumDuration);
                    var maxDurationSeconds = CMTimeGetSeconds(ThisApp.CaptureDevice.ActiveFormat.MaxExposureDuration);
                    var p          = (newDurationSeconds - minDurationSeconds) / (maxDurationSeconds - minDurationSeconds);
                    Duration.Value = (float)Math.Pow(p, 1.0f / ExposureDurationPower);
                });

                ISO.BeginInvokeOnMainThread(() => {
                    ISO.Value = ThisApp.Input.Device.ISO;
                });

                Bias.BeginInvokeOnMainThread(() => {
                    Bias.Value = ThisApp.Input.Device.ExposureTargetBias;
                });
            };

            // Watch for value changes
            Segments.ValueChanged += (sender, e) => {
                NSError err;
                // Lock device for change
                if (ThisApp.CaptureDevice.LockForConfiguration(out err))
                {
                    // Take action based on the segment selected
                    switch (Segments.SelectedSegment)
                    {
                    case 0:
                        // Activate auto exposure and start monitoring position
                        Duration.Enabled = false;
                        ISO.Enabled      = false;
                        ThisApp.CaptureDevice.ExposureMode = AVCaptureExposureMode.ContinuousAutoExposure;
                        SampleTimer.Start();
                        Automatic = true;
                        break;

                    case 1:
                        // Lock exposure and allow the user to control the camera
                        SampleTimer.Stop();
                        ThisApp.CaptureDevice.ExposureMode = AVCaptureExposureMode.Locked;
                        Automatic        = false;
                        Duration.Enabled = false;
                        ISO.Enabled      = false;
                        break;

                    case 2:
                        // Custom exposure and allow the user to control the camera
                        SampleTimer.Stop();
                        ThisApp.CaptureDevice.ExposureMode = AVCaptureExposureMode.Custom;
                        Automatic        = false;
                        Duration.Enabled = true;
                        ISO.Enabled      = true;
                        break;
                    }

                    // Unlock device
                    ThisApp.CaptureDevice.UnlockForConfiguration();
                }
            };

            // Monitor position changes
            Duration.ValueChanged += (sender, e) => {
                // If we are in the automatic mode, ignore changes
                if (Automatic)
                {
                    return;
                }

                // Calculate value
                var p = Math.Pow(Duration.Value, ExposureDurationPower);
                var minDurationSeconds = Math.Max(ThisApp.CaptureDevice.ActiveFormat.MinExposureDuration.Seconds, ExposureMinimumDuration);
                var maxDurationSeconds = ThisApp.CaptureDevice.ActiveFormat.MaxExposureDuration.Seconds;
                var newDurationSeconds = p * (maxDurationSeconds - minDurationSeconds) + minDurationSeconds;

                NSError err;
                // Update Focus position
                if (ThisApp.CaptureDevice.LockForConfiguration(out err))
                {
                    ThisApp.CaptureDevice.LockExposure(CMTime.FromSeconds(newDurationSeconds, 1000 * 1000 * 1000), AVCaptureDevice.ISOCurrent, null);
                    ThisApp.CaptureDevice.UnlockForConfiguration();
                }
            };

            ISO.ValueChanged += (sender, e) => {
                // If we are in the automatic mode, ignore changes
                if (Automatic)
                {
                    return;
                }

                NSError err;
                // Update Focus position
                if (ThisApp.CaptureDevice.LockForConfiguration(out err))
                {
                    ThisApp.CaptureDevice.LockExposure(ThisApp.CaptureDevice.ExposureDuration, ISO.Value, null);
                    ThisApp.CaptureDevice.UnlockForConfiguration();
                }
            };

            Bias.ValueChanged += (sender, e) => {
                NSError err;
                // Update Focus position
                if (ThisApp.CaptureDevice.LockForConfiguration(out err))
                {
                    ThisApp.CaptureDevice.SetExposureTargetBias(Bias.Value, null);
                    ThisApp.CaptureDevice.UnlockForConfiguration();
                }
            };
        }
Esempio n. 20
0
 public static ISO <Func <A, C>, Func <B, D> > IsoFunc <A, B, C, D>(ISO <A, B> ab, ISO <C, D> cd)
 {
     return(new ISO <Func <A, C>, Func <B, D> >(ac => a => cd.Fw(ac(ab.Bw(a))), bd => b => cd.Bw(bd(ab.Fw(b)))));
 }
Esempio n. 21
0
 /// given ISO a b, we can go from a to b
 public static Func <A, B> SubStL <A, B>(ISO <A, B> iso)
 {
     return(iso.Fw);
 }
Esempio n. 22
0
 /// a = b => c = d => a + c = b + d
 public static ISO <Either <A, C>, Either <B, D> > IsoPlus <A, B, C, D>(ISO <A, B> ab, ISO <C, D> cd)
 {
     return(IsoEither(ab, cd));
 }
Esempio n. 23
0
 /// and vise versa
 public static Func <B, A> SubStR <A, B>(ISO <A, B> iso)
 {
     return(iso.Bw);
 }
Esempio n. 24
0
 public static ISO CreateISO(global::System.Guid ID, global::System.Guid stampId)
 {
     ISO iSO = new ISO();
     iSO.ID = ID;
     iSO.StampId = stampId;
     return iSO;
 }
Esempio n. 25
0
        /// <summary>
        /// Dumps an ISO's contents from the specified root to the provided output path.
        /// </summary>
        /// <param name="root">ISO to dump</param>
        /// <param name="outputPath">Path to dump to</param>
        public static void DumpISOContents(VirtualFilesystemDirectory root, string outputPath)
        {
            ISO iso = new ISO();

            iso.DumpToDisk(root, outputPath);
        }