<commit_before>﻿using System.Collections.Generic;
using FarseerPhysics.Common;
using FarseerPhysics.DebugViews;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Joints;
using FarseerPhysics.Factories;
using Microsoft.Xna.Framework;

namespace FarseerPhysics.DemoBaseXNA.DemoShare
{
    public class Spiderweb
    {
        DebugMaterial _defaultMaterial = new DebugMaterial(MaterialType.Blank)
        {
            Color = Color.LightGray,
        };

        public Spiderweb(World world, Vector2 position, float boxSize, int rings, int sides)
        {
            Vertices box = PolygonTools.CreateRectangle(boxSize, boxSize);

            List<List<Fixture>> ringFixtures = new List<List<Fixture>>(rings);

            for (int i = 1; i < rings; i++)
            {
                Vertices vertices = PolygonTools.CreateCircle(i + i * 3, sides);
                List<Fixture> fixtures = new List<Fixture>(sides);

                //Create the first box
                Fixture prev = FixtureFactory.CreatePolygon(world, box, 1, vertices[0], _defaultMaterial);
                prev.Body.FixedRotation = true;
                prev.Body.Position += position;
                prev.Body.BodyType = BodyType.Dynamic;

                fixtures.Add(prev);

                //Connect the first box to the next
                for (int j = 1; j < vertices.Count; j++)
                {
                    Fixture fix = FixtureFactory.CreatePolygon(world, box, 1, vertices[j], _defaultMaterial);
                    fix.Body.FixedRotation = true;
                    fix.Body.BodyType = BodyType.Dynamic;
                    fix.Body.Position += position;

                    DistanceJoint dj = JointFactory.CreateDistanceJoint(world, prev.Body, fix.Body, Vector2.Zero, Vector2.Zero);
                    dj.Frequency = 4.0f;
                    dj.DampingRatio = 0.5f;

                    prev = fix;
                    fixtures.Add(fix);
                }

                //Connect the first and the last box
                DistanceJoint djEnd = JointFactory.CreateDistanceJoint(world, fixtures[0].Body, fixtures[fixtures.Count - 1].Body, Vector2.Zero, Vector2.Zero);
                djEnd.Frequency = 4.0f;
                djEnd.DampingRatio = 0.5f;

                ringFixtures.Add(fixtures);
            }

            //Create an outer ring
            Vertices lastRing = PolygonTools.CreateCircle(rings + rings * 3, sides);
            lastRing.Translate(ref position);

            List<Fixture> lastRingFixtures = ringFixtures[ringFixtures.Count - 1];

            //Fix each of the fixtures of the outer ring
            for (int j = 0; j < lastRingFixtures.Count; j++)
            {
                FixedDistanceJoint fdj = JointFactory.CreateFixedDistanceJoint(world, lastRingFixtures[j].Body, Vector2.Zero, lastRing[j]);
                fdj.Frequency = 4.0f;
                fdj.DampingRatio = 0.5f;
            }

            //Interconnect the rings
            for (int i = 1; i < ringFixtures.Count; i++)
            {
                List<Fixture> prev = ringFixtures[i - 1];
                List<Fixture> current = ringFixtures[i];
<commit_msg>The spiderweb is now breakable.<commit_after>﻿using System.Collections.Generic;
using FarseerPhysics.Common;
using FarseerPhysics.DebugViews;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Joints;
using FarseerPhysics.Factories;
using Microsoft.Xna.Framework;

namespace FarseerPhysics.DemoBaseXNA.DemoShare
{
    public class Spiderweb
    {
        DebugMaterial _defaultMaterial = new DebugMaterial(MaterialType.Blank)
        {
            Color = Color.LightGray,
        };

        public Spiderweb(World world, Vector2 position, float boxSize, int rings, int sides)
        {
            const float breakpoint = 100;
            Vertices box = PolygonTools.CreateRectangle(boxSize, boxSize);

            List<List<Fixture>> ringFixtures = new List<List<Fixture>>(rings);

            for (int i = 1; i < rings; i++)
            {
                Vertices vertices = PolygonTools.CreateCircle(i + i * 3, sides);
                List<Fixture> fixtures = new List<Fixture>(sides);

                //Create the first box
                Fixture prev = FixtureFactory.CreatePolygon(world, box, 1, vertices[0], _defaultMaterial);
                prev.Body.FixedRotation = true;
                prev.Body.Position += position;
                prev.Body.BodyType = BodyType.Dynamic;

                fixtures.Add(prev);

                //Connect the first box to the next
                for (int j = 1; j < vertices.Count; j++)
                {
                    Fixture fix = FixtureFactory.CreatePolygon(world, box, 1, vertices[j], _defaultMaterial);
                    fix.Body.FixedRotation = true;
                    fix.Body.BodyType = BodyType.Dynamic;
                    fix.Body.Position += position;

                    DistanceJoint dj = JointFactory.CreateDistanceJoint(world, prev.Body, fix.Body, Vector2.Zero, Vector2.Zero);
                    dj.Frequency = 4.0f;
                    dj.DampingRatio = 0.5f;
                    dj.Breakpoint = breakpoint;

                    prev = fix;
                    fixtures.Add(fix);
                }

                //Connect the first and the last box
                DistanceJoint djEnd = JointFactory.CreateDistanceJoint(world, fixtures[0].Body, fixtures[fixtures.Count - 1].Body, Vector2.Zero, Vector2.Zero);
                djEnd.Frequency = 4.0f;
                djEnd.DampingRatio = 0.5f;
                djEnd.Breakpoint = breakpoint;

                ringFixtures.Add(fixtures);
            }

            //Create an outer ring
            Vertices lastRing = PolygonTools.CreateCircle(rings + rings * 3, sides);
            lastRing.Translate(ref position);

            List<Fixture> lastRingFixtures = ringFixtures[ringFixtures.Count - 1];

            //Fix each of the fixtures of the outer ring
            for (int j = 0; j < lastRingFixtures.Count; j++)
            {
                FixedDistanceJoint fdj = JointFactory.CreateFixedDistanceJoint(world, lastRingFixtures[j].Body, Vector2.Zero, lastRing[j]);
                fdj.Frequency = 4.0f;
                fdj.DampingRatio = 0.5f;
                fdj.Breakpoint = breakpoint;
            }

            //Interconnect the rings
            for (int i = 1; i < ringFixtures.Count; i++)
            {
                List<Fixture> prev = ringFixtures[i - 1];
                List<Fixture> current = ringFixtures[i];

{'fraction_non_alphanumeric': 0.09246261824839792, 'fraction_numerical': 0.009917607567897467, 'mean_word_length': 1.7810776410691558, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 21, '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': '4429101', 'n_tokens_mistral': 1937, 'n_tokens_neox': 1727, 'n_words': 412}