From b1159572ba712b2a33a3b481927ecd3a6221a58f Mon Sep 17 00:00:00 2001
From: pregmodfan <pregmodfan@cock.li>
Date: Wed, 28 Nov 2018 17:49:31 +0200
Subject: [PATCH] fixes, tweaks, comments

---
 src/init/setupVars.tw |  8 +++++---
 src/js/wombJS.tw      | 13 +++++++++----
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/init/setupVars.tw b/src/init/setupVars.tw
index 6874fe9f264..d3c4c0ae7a3 100644
--- a/src/init/setupVars.tw
+++ b/src/init/setupVars.tw
@@ -6,13 +6,15 @@
 
 /*** pregmod exclusive start ***/
 
+/* Double 20 week point for human data - not a bug. Do not change! (It's transfer point in data source, from data without CTR to with CTR) */
 <<set setup.pregData = { 
 
-human: {type: "human", normalBirth: 40, minLiveBirth: 32, fetusWeek: [9, 20, 40, 52, 64, 80, 384, 99999], fetusSize: [3, 16, 51, 60, 67.5, 71.6, 129.5, 130], fetusCTR: [1, 1, 0.6513, 0.6459, 0.644, 0.6393, 0.58, 0.51], storedFat: 1},
+human: {type: "human", normalOvaMin:1, normalOvaMax: 1, normalBirth: 40, minLiveBirth: 32, fetusWeek: [9, 20, 20, 40, 52, 64, 80, 384, 99999], fetusSize: [3, 16, 25.6, 51, 60, 67.5, 71.6, 129.5, 130], fetusCTR: [1, 1, 0.64, 0.6513, 0.6459, 0.644, 0.6393, 0.58, 0.51]}, 
 
-canine: {type: "canine", normalBirth: 9, minLiveBirth: 8, fetusWeek: [4, 6, 9, 32, 99999], fetusSize: [1, 5, 17.7, 70, 70], fetusCTR: [1, 1, 1, 1], storedFat: 1} /*source data include CTR (not for head to toe), so CTR not apply.*/
+canine: {type: "canine", normalOvaMin:2, normalOvaMax: 8, normalBirth: 9, minLiveBirth: 8, fetusWeek: [4, 6, 9, 32, 99999], fetusSize: [1, 5, 17.7, 70, 70], fetusCTR: [1, 1, 1, 1, 1]}
+
+}>>  /* Source data for canine include CTR (not head to toe size), so CTR do not apply anywhere, always 1.*/
 
-}>>
 
 <<set setup.filterRaces = ["Amerindian", "Asian", "Black", "Indo-Aryan", "Latina", "Malay", "Middle Eastern", "Mixed Race", "Pacific Islander", "Semitic", "Southern European", "White"]>>
 <<set setup.filterRegions = ["Africa", "Asia", "Australia", "Europe", "Middle East", "North America", "South America"]>>
diff --git a/src/js/wombJS.tw b/src/js/wombJS.tw
index 3e37834abeb..e60f148c86c 100644
--- a/src/js/wombJS.tw
+++ b/src/js/wombJS.tw
@@ -190,7 +190,7 @@ window.WombBirthReady = function(actor, readyAge) {
 	return readyCnt;
 };
 
-window.WombGetVolume = function(actor) { //most code from pregJS.tw with minor adaptation.
+window.WombGetVolume = function(actor) { //most legacy code from pregJS.tw with minor adaptation.
 	var gestastionWeek;
 	var phi = 1.618;
 	var targetLen;
@@ -213,14 +213,14 @@ window.WombGetVolume = function(actor) { //most code from pregJS.tw with minor a
         cage = age - ageMin;
 
         one = (max - min) / (ageMax - ageMin);
-        ctrOne = (ctrMax - ctrMin) / (ageMax - ageMin); // CTR can have negative or positive progression, but we need absolute.
+        ctrOne = (ctrMax - ctrMin) / (ageMax - ageMin);
        
         ctr = ctrMin + (ctrOne * cage);
 
         csize = (min + (one * cage));
         console.log("min:"+min+"  max:"+max+"  ageMin:"+ageMin+"  ageMax:"+ageMax+"  one:"+one+"  ctrOne:"+ctrOne+"  cage:"+cage+"  ctr:"+ctr+"  csize:"+csize+"  final size:"+csize*ctr);
 
-        return csize*ctr; 
+        return csize * ctr; 
         //maybe not very effective code, but simple and easy to debug. May be optimized more in future.
     }
 
@@ -228,7 +228,7 @@ window.WombGetVolume = function(actor) { //most code from pregJS.tw with minor a
 		actor.womb.forEach(ft => {
 			gestastionWeek = ft.age;
 			
-            //for debug only
+            // legacy block for debug only
             let oldLen;
             let oldVol; 
             if (gestastionWeek <= 32) {
@@ -257,6 +257,10 @@ window.WombGetVolume = function(actor) { //most code from pregJS.tw with minor a
             oldVol = ((4 / 3) * (Math.PI) * (phi / 2) * (Math.pow((oldLen / 2), 3))); //for debug 
 
             console.log("fetus.age:" + ft.age + "  oldLen:"+oldLen+"  targetLen:"+targetLen+"  ft.volume:"+ft.volume+ "  old volume:"+oldVol );
+            /*
+                I found, that previous targetLen calculation not exactly accurate if compared to the actual medical data chart for fetal length. It's been rough aproximation based only on pregnancy week (giving smaller fetus size then it should in most cases). So I need all this debug code to compare data and verify calculations. After final tweaking I will remove or comment out legacy code. Please not touch this before it.
+                Pregmodfan.
+            */
 		});
 	} catch(err){
 		WombInit(actor);
@@ -264,6 +268,7 @@ window.WombGetVolume = function(actor) { //most code from pregJS.tw with minor a
 	}
 	if (wombSize < 0) //catch for strange cases, to avoid messing with outside code.
 		wombSize = 0;
+
 	return wombSize;
 };
 
-- 
GitLab