<commit_before>﻿namespace FSketch

module DrawingUtils =

    let measureText =    
        let i = new System.Drawing.Bitmap(1, 1)
        let g = System.Drawing.Graphics.FromImage(i)
        g.TextRenderingHint <- System.Drawing.Text.TextRenderingHint.AntiAlias

        fun text ->
            use font = new System.Drawing.Font("Arial", single text.Size)
            let size = g.MeasureString(text.Text, font)
            float size.Width, float size.Height

    let boundariesReducer b1 b2 =
        match b1, b2 with
        | Some (left1, top1, right1, bottom1), Some (left2, top2, right2, bottom2) ->
            Some (min left1 left2, min top1 top2, max right1 right2, max bottom1 bottom2)
        | Some b1, None -> Some b1
        | None, Some b2 -> Some b2
        | _ -> None

    let minMaxReducer (min1, max1) (min2, max2) = min min1 min2, max max1 max2

    let getPathPoints path =
        //TODO: get boundaries points, not only for lines (this means handle the Bezier case for real)
        let offset = ref Vector.Zero
        let toPoint (Vector(x, y)) = x, y
        let rec getPoints path = seq {
            for segment in path do
            match segment with
            | Line v ->
                offset := !offset + v
                yield !offset |> toPoint
            | Bezier (v, _, _) ->
                offset := !offset + v
                yield !offset |> toPoint
            | CompositePath (path) ->
                yield! getPoints path }

        [
            yield !offset |> toPoint<commit_msg>Now with unoptimized Bezier bounding box<commit_after>﻿namespace FSketch

module DrawingUtils =

    let measureText =    
        let i = new System.Drawing.Bitmap(1, 1)
        let g = System.Drawing.Graphics.FromImage(i)
        g.TextRenderingHint <- System.Drawing.Text.TextRenderingHint.AntiAlias

        fun text ->
            use font = new System.Drawing.Font("Arial", single text.Size)
            let size = g.MeasureString(text.Text, font)
            float size.Width, float size.Height

    let boundariesReducer b1 b2 =
        match b1, b2 with
        | Some (left1, top1, right1, bottom1), Some (left2, top2, right2, bottom2) ->
            Some (min left1 left2, min top1 top2, max right1 right2, max bottom1 bottom2)
        | Some b1, None -> Some b1
        | None, Some b2 -> Some b2
        | _ -> None

    let minMaxReducer (min1, max1) (min2, max2) = min min1 min2, max max1 max2

    let getPathPoints path =
        let offset = ref Vector.Zero
        let toPoint (Vector(x, y)) = x, y
        let rec getPoints path = seq {
            for segment in path do
            match segment with
            | Line v ->
                offset := !offset + v
                yield !offset |> toPoint
            | Bezier (v, cp1, cp2) ->
                //TODO: get tighter boundaries for Bezier curves
                yield !offset + cp1 |> toPoint
                offset := !offset + v
                yield !offset + cp2 |> toPoint
                yield !offset |> toPoint
            | CompositePath (path) ->
                yield! getPoints path }

        [
            yield !offset |> toPoint
{'fraction_non_alphanumeric': 0.08872750236817177, 'fraction_numerical': 0.022734449005367856, 'mean_word_length': 1.7100085543199315, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '5359336', 'n_tokens_mistral': 933, 'n_tokens_neox': 897, 'n_words': 309}