<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PBJJ.Core
{
    public class CutProgram
    {
        public CutProgram(List<JointProfileElement> elements, decimal kerfWidth)
        {
            GenerateFromProfileElements(elements, kerfWidth);
        }

        public List<decimal> CutPositions { get; set; }

        private void GenerateFromProfileElements(List<JointProfileElement> elements, decimal kerfWidth)
        {
            // work out the positions of each slot, and where they start and end
            var slotStartsAndEnds = new List<SlotCoordinate>();
            decimal pos = 0;
            foreach (var element in elements)
            {
                if (element.Type == JointProfileElement.JointProfileElementType.Finger)
                {
                    // ignore finger, advance to next
                    pos = (pos + element.Width);
                }
                else
                {
                    // slot...
                    var slot = new SlotCoordinate(pos, (pos + element.Width));
                    slotStartsAndEnds.Add(slot);
                    pos = (pos + element.Width);
                }
            }

            // now work out the cuts to make each slot
            var cuts = new List<decimal>();
            foreach (var slotCoord in slotStartsAndEnds)
            {
                decimal slotCutPos = slotCoord.Left + kerfWidth;
                cuts.Add(slotCutPos);
                while (slotCutPos < slotCoord.Right)
                {
                    // advance most of kerf
                    slotCutPos += (0.9M*kerfWidth);
                    // ensure we don't overshoot the end of the slot
                    slotCutPos = Math.Min(slotCutPos, slotCoord.Right);
                    // add the cut
                    cuts.Add(slotCutPos);
                }
            }


            CutPositions = cuts;
        }

        private class SlotCoordinate {
            public SlotCoordinate(decimal left, decimal right)
            {
                if (left > right) {
                    throw new ArgumentOutOfRangeException(nameof(left),
                        "SlotCoordinate left value cannot be greater than right value");
                }
                Left = left;
                Right = right;
            }
            public decimal Left { get; private set; }
            public decimal Right { get; private set; }
            public decimal Width => (Right-Left);
        }
    }
}
<commit_msg>Updated to make cut increments equal within a slot<commit_after>﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PBJJ.Core
{
    public class CutProgram
    {
        public CutProgram(List<JointProfileElement> elements, decimal kerfWidth)
        {
            GenerateFromProfileElements(elements, kerfWidth);
        }

        public List<decimal> CutPositions { get; set; }

        private void GenerateFromProfileElements(List<JointProfileElement> elements, decimal kerfWidth)
        {
            // work out the positions of each slot, and where they start and end
            var slotStartsAndEnds = new List<SlotCoordinate>();
            decimal pos = 0;
            foreach (var element in elements)
            {
                if (element.Type == JointProfileElement.JointProfileElementType.Finger)
                {
                    // ignore finger, advance to next
                    pos = (pos + element.Width);
                }
                else
                {
                    // slot...
                    var slot = new SlotCoordinate(pos, (pos + element.Width));
                    slotStartsAndEnds.Add(slot);
                    pos = (pos + element.Width);
                }
            }

            // now work out the cuts to make each slot
            var cuts = new List<decimal>();
            foreach (var slotCoord in slotStartsAndEnds)
            {
                var cutsForSlot = GetCutsForSlot(slotCoord, kerfWidth);
                cuts.AddRange(cutsForSlot);
            }
            
            CutPositions = cuts;
        }

        private List<decimal> GetCutsForSlot(SlotCoordinate slot, decimal kerfWidth)
        {
            var cuts = new List<decimal>();
            if (slot.Width == 0) { return cuts; }
            // first cut
            cuts.Add(slot.Left + kerfWidth);
            if (slot.Width <= kerfWidth) { return cuts; }
            // slot requires multiple cuts, space them out evenly
            decimal widthAfterFirstCut = (slot.Width - kerfWidth);
            var maxAdvance = (kerfWidth*0.9M);
            var remainingCutsRequired = (int)Math.Ceiling(widthAfterFirstCut/maxAdvance);
            for (int i = 1; i <= remainingCutsRequired; i++) {
                var cutPos = (slot.Left + kerfWidth) + (i*(widthAfterFirstCut/remainingCutsRequired));
                cuts.Add(cutPos);
            }
            return cuts;
        }

        private class SlotCoordinate {
            public SlotCoordinate(decimal left, decimal right)
            {
                if (left > right) {
                    throw new ArgumentOutOfRangeException(nameof(left),
                        "SlotCoordinate left value cannot be greater than right value");
                }
                Left = left;
                Right = right;
            }
            public decimal Left { get; private set; }
            public decimal Right { get; private set; }
            public decimal Width => (Right-Left);
        }
    }
}

{'fraction_non_alphanumeric': 0.07862020661880581, 'fraction_numerical': 0.0014008054631413063, 'mean_word_length': 1.4493996569468268, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '624869', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1365, 'n_words': 392}