<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Assets.Helpers;
using UnityEngine;

namespace Assets.Models.Factories
{
    public class WaterFactory : Factory
    {
        [SerializeField]
        private Water.Settings _settings;
        //using water center for key is quite wrong actually, but works for now
        private Dictionary<Vector3, Water> _waterDictionary { get; set; }

        public void Start()
        {
            _waterDictionary = new Dictionary<Vector3, Water>();
        }

        public override void Create(Vector2 tileMercPos, JSONObject geo, Transform parent = null)
        {
            parent = parent ?? transform;
            var waterCorners = new List<Vector3>();
            foreach (var bb in geo["geometry"]["coordinates"].list)
            {
                var jo = (bb.list[0].list[0].IsArray) ? bb.list[0] : bb;
                //var bb = geo["geometry"]["coordinates"].list[0]; //this is wrong but cant fix it now
                for (int i = 0; i < jo.list.Count - 1; i++)
                {
                    var c = jo.list[i];
                    var dotMerc = GM.LatLonToMeters(c[1].f, c[0].f);
                    var localMercPos = new Vector2(dotMerc.x - tileMercPos.x, dotMerc.y - tileMercPos.y);
                    waterCorners.Add(localMercPos.ToVector3xz());
                }

                //prevents duplicates coming from different tiles
                //it sucks yea but works for now, cant use propery/id in json for some reason
                var uniqPos = new Vector3(jo.list[0][1].f, 0, jo.list[0][0].f);
                if (_waterDictionary.ContainsKey(uniqPos))
                {
                    return;
                }

                try
                {
                    var waterCenter = waterCorners.Aggregate((acc, cur) => acc + cur) / waterCorners.Count;
                    if (!_waterDictionary.ContainsKey(waterCenter))
                    {
                        for (int i = 0; i < waterCorners.Count; i++)
                        {
                            //using corner position relative to water center
                            waterCorners[i] = waterCorners[i] - waterCenter;
                        }
                        var water = new GameObject().AddComponent<Water>();

                        water.Init(waterCorners, _settings);<commit_msg>Fix flipped polygons problem in water layer<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Assets.Helpers;
using UnityEngine;

namespace Assets.Models.Factories
{
    public class WaterFactory : Factory
    {
        [SerializeField]
        private Water.Settings _settings;
        //using water center for key is quite wrong actually, but works for now
        private Dictionary<Vector3, Water> _waterDictionary { get; set; }

        public void Start()
        {
            _waterDictionary = new Dictionary<Vector3, Water>();
        }

        public override void Create(Vector2 tileMercPos, JSONObject geo, Transform parent = null)
        {
            parent = parent ?? transform;
            foreach (var bb in geo["geometry"]["coordinates"].list)
            {
                var waterCorners = new List<Vector3>();
                var jo = (bb.list[0].list[0].IsArray) ? bb.list[0] : bb;
                //var bb = geo["geometry"]["coordinates"].list[0]; //this is wrong but cant fix it now
                for (int i = 0; i < jo.list.Count - 1; i++)
                {
                    var c = jo.list[i];
                    var dotMerc = GM.LatLonToMeters(c[1].f, c[0].f);
                    var localMercPos = new Vector2(dotMerc.x - tileMercPos.x, dotMerc.y - tileMercPos.y);
                    waterCorners.Add(localMercPos.ToVector3xz());
                }

                //prevents duplicates coming from different tiles
                //it sucks yea but works for now, cant use propery/id in json for some reason
                var uniqPos = new Vector3(jo.list[0][1].f, 0, jo.list[0][0].f);
                if (_waterDictionary.ContainsKey(uniqPos))
                {
                    return;
                }

                try
                {
                    var waterCenter = waterCorners.Aggregate((acc, cur) => acc + cur) / waterCorners.Count;
                    if (!_waterDictionary.ContainsKey(waterCenter))
                    {
                        for (int i = 0; i < waterCorners.Count; i++)
                        {
                            //using corner position relative to water center
                            waterCorners[i] = waterCorners[i] - waterCenter;
                        }
                        var water = new GameObject().AddComponent<Water>();

                        water.Init(waterCorners, _settings);
{'fraction_non_alphanumeric': 0.09873002867677182, 'fraction_numerical': 0.008603031544448997, 'mean_word_length': 1.528741584671155, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, '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': '4877679', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1247, 'n_words': 349}