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

namespace Circuit
{
    public enum EdgeType
    {
        Wire,
        Black,
        Gray,
        Red,
        Green,
        Blue,
        Yellow,
        Cyan,
        Magenta
    };

    public enum Alignment
    {
        Near,
        Center,
        Far,
    }
    
    /// <summary>
    /// 
    /// </summary>
    public class SymbolLayout
    {
        public SymbolLayout() { }
     
        protected Coord x1 = new Coord(int.MaxValue, int.MaxValue);
        protected Coord x2 = new Coord(int.MinValue, int.MinValue);
        public Coord LowerBound { get { return x1; } }
        public Coord UpperBound { get { return x2; } }

        public Coord Size { get { return UpperBound - LowerBound; } }
        public int Width { get { return x2.x - x1.x; } }
        public int Height { get { return x2.y - x1.y; } }

        // Include the points in x inside the bounds of this symbol.
        public void InBounds(IEnumerable<Coord> x)
        {
            foreach (Coord i in x)
            {
                x1.x = Math.Min(x1.x, i.x); x1.y = Math.Min(x1.y, i.y);
                x2.x = Math.Max(x2.x, i.x); x2.y = Math.Max(x2.y, i.y);
            }
        }
        public void InBounds(params Coord[] x) { InBounds(x.AsEnumerable()); }
        
        protected Dictionary<Terminal, Coord> terminals = new Dictionary<Terminal, Coord>();
        /// <summary>
        /// The terminals in this layout.
        /// </summary>
        public IEnumerable<Terminal> Terminals { get { return terminals.Keys; } }
        /// <summary>
        /// Get the position of the terminal in this symbol.
        /// </summary>
        /// <param name="T"></param>
        /// <returns></returns>
        public Coord MapTerminal(Terminal T) { return terminals[T]; }
        /// <summary>
        /// Add a terminal to the schematic.
        /// </summary>
        /// <param name="T"></param>
        /// <param name="x"></param>
        public void AddTerminal(Terminal T, Coord x) { terminals[T] = x; }
        
        // Add shapes to the schematic.
        public void AddRectangle(EdgeType Type, Coord x1, Coord x2) 
        {
            InBounds(x1, x2);
            DrawRectangle(Type, x1, x2); 
        }
        public void AddCircle(EdgeType Type, Coord x, int r)
        {
            InBounds(x - r, x + r);
            DrawEllipse(Type, x - r, x + r);
        }
        public void AddLine(EdgeType Type, Coord x1, Coord x2)
        {
            InBounds(x1, x2);
            DrawLine(Type, x1, x2);
        }
        public void AddCurve(EdgeType Type, IEnumerable<Coord> Points)
        {
            InBounds(Points);

            DrawCurve(Type, Points.Select(i => (Point)i));
        }
        public void AddCurve(EdgeType Type, params Coord[] Points) { AddCurve(Type, Points.AsEnumerable()); }
        public void AddLoop(EdgeType Type, IEnumerable<Coord> Points)
        {
            AddCurve(Type, Points);
            AddLine(Type, Points.First(), Points.Last());
        }
        public void AddLoop(EdgeType Type, params Coord[] Points) { AddLoop(Type, Points.AsEnumerable()); }
        

        // Add a wire to the schematic.
        public void AddWire(IEnumerable<Coord> Points) 
        {
            foreach (var i in Points.Zip(Points.Skip(1), (a, b) => new[] { a, b }))
                DrawLine(EdgeType.Wire, i[0], i[1]);
            InBounds(Points);
        }
        public void AddWire(params Coord[] Points) { AddWire(Points.AsEnumerable()); }
        public void AddWire(Terminal T, IEnumerable<Coord> x) { AddWire(x.Append(terminals[T])); }
        public void AddWire(Terminal T, params Coord[] x) { AddWire(T, x.AsEnumerable()); }

        public void AddWire(IEnumerable<Terminal> Terminals) { AddWire(Terminals.Select(i => terminals[i])); }
        public void AddWire(params Terminal[] Terminals) { AddWire(Terminals.Select(i => terminals[i])); }

        public class Shape
        {
            private EdgeType edge;
            private Point _x1, _x2;

            public EdgeType Edge { get { return edge; } }
            public Point x1 { get { return _x1; } }
            public Point x2 { get { return _x2; } }

            public Shape(EdgeType Edge, Point x1, Point x2) 
            { 
                edge = Edge; <commit_msg>Fixed broken rendering for some symbols<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SyMath;

namespace Circuit
{
    public enum EdgeType
    {
        Wire,
        Black,
        Gray,
        Red,
        Green,
        Blue,
        Yellow,
        Cyan,
        Magenta
    };

    public enum Alignment
    {
        Near,
        Center,
        Far,
    }
    
    /// <summary>
    /// 
    /// </summary>
    public class SymbolLayout
    {
        public SymbolLayout() { }
     
        protected Coord x1 = new Coord(int.MaxValue, int.MaxValue);
        protected Coord x2 = new Coord(int.MinValue, int.MinValue);
        public Coord LowerBound { get { return x1; } }
        public Coord UpperBound { get { return x2; } }

        public Coord Size { get { return UpperBound - LowerBound; } }
        public int Width { get { return x2.x - x1.x; } }
        public int Height { get { return x2.y - x1.y; } }

        // Include the points in x inside the bounds of this symbol.
        public void InBounds(IEnumerable<Coord> x)
        {
            foreach (Coord i in x)
            {
                x1.x = Math.Min(x1.x, i.x); x1.y = Math.Min(x1.y, i.y);
                x2.x = Math.Max(x2.x, i.x); x2.y = Math.Max(x2.y, i.y);
            }
        }
        public void InBounds(params Coord[] x) { InBounds(x.AsEnumerable()); }
        
        protected Dictionary<Terminal, Coord> terminals = new Dictionary<Terminal, Coord>();
        /// <summary>
        /// The terminals in this layout.
        /// </summary>
        public IEnumerable<Terminal> Terminals { get { return terminals.Keys; } }
        /// <summary>
        /// Get the position of the terminal in this symbol.
        /// </summary>
        /// <param name="T"></param>
        /// <returns></returns>
        public Coord MapTerminal(Terminal T) { return terminals[T]; }
        /// <summary>
        /// Add a terminal to the schematic.
        /// </summary>
        /// <param name="T"></param>
        /// <param name="x"></param>
        public void AddTerminal(Terminal T, Coord x) { terminals[T] = x; }
        
        // Add shapes to the schematic.
        public void AddRectangle(EdgeType Type, Coord x1, Coord x2) 
        {
            InBounds(x1, x2);
            DrawRectangle(Type, x1, x2); 
        }
        public void AddCircle(EdgeType Type, Coord x, int r)
        {
            InBounds(x - r, x + r);
            DrawEllipse(Type, x - r, x + r);
        }
        public void AddLine(EdgeType Type, Coord x1, Coord x2)
        {
            InBounds(x1, x2);
            DrawLine(Type, x1, x2);
        }
        public void AddCurve(EdgeType Type, IEnumerable<Coord> Points)
        {
            InBounds(Points);

            DrawCurve(Type, Points.Select(i => (Point)i));
        }
        public void AddCurve(EdgeType Type, params Coord[] Points) { AddCurve(Type, Points.AsEnumerable()); }
        public void AddLoop(EdgeType Type, IEnumerable<Coord> Points)
        {
            AddCurve(Type, Points);
            AddLine(Type, Points.First(), Points.Last());
        }
        public void AddLoop(EdgeType Type, params Coord[] Points) { AddLoop(Type, Points.AsEnumerable()); }
        

        // Add a wire to the schematic.
        public void AddWire(IEnumerable<Coord> Points) 
        {
            foreach (var i in Points.Zip(Points.Skip(1), (a, b) => new[] { a, b }))
                DrawLine(EdgeType.Wire, i[0], i[1]);
            InBounds(Points);
        }
        public void AddWire(params Coord[] Points) { AddWire(Points.AsEnumerable()); }
        public void AddWire(Terminal T, IEnumerable<Coord> x) { AddWire(new Coord[] { terminals[T] }.Concat(x)); }
        public void AddWire(Terminal T, params Coord[] x) { AddWire(T, x.AsEnumerable()); }

        public void AddWire(IEnumerable<Terminal> Terminals) { AddWire(Terminals.Select(i => terminals[i])); }
        public void AddWire(params Terminal[] Terminals) { AddWire(Terminals.Select(i => terminals[i])); }

        public class Shape
        {
            private EdgeType edge;
            private Point _x1, _x2;

            public EdgeType Edge { get { return edge; } }
            public Point x1 { get { return _x1; } }
            public Point x2 { get { return _x2; } }

            public Shape(EdgeType Edge, Point x1, Point x2) 
            { 
                edge = Edge; 
{'fraction_non_alphanumeric': 0.12201172755976544, 'fraction_numerical': 0.008795669824086604, 'mean_word_length': 1.7698313554028733, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 61, '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': '6502990', 'n_tokens_mistral': 2658, 'n_tokens_neox': 2572, 'n_words': 734}