# Changing object states and 3D transformations

Since Some more Direct X10, I noticed a few days ago that my tablet's charger stopped working, I ordered a replacement which arrived on Friday. I've grown quite attached to my little stupid tablet. It's really helpful to have two screens while computing(it has a nice dock that makes it slant like a laptop screen).

I decided to put windows 10 on it and that didn't work out - all sorts of problems with the media not being able to be read etc - I had Fedora 30 on it prior and was slightly regretting having removed it.

I ended up installed MxLinux which then it didn't want to work because it couldn't install the boot loader due to some UEFI/secure boot rubbish. I then decided to install OpenSuse Tumbleweed and now I'm quite pleased with it, particularly its performance, running KDE Neon. They've done great things here and now even my Gnome 3 experience under Fedora seemed so slow in comparison.

It was an early start to the gym this morning, up at 4:30 in at 05:00 out by 06:30 and then started the day. began with a little functional programming by adding a new project to my LanguageEXT tutorial which shows how you can change the state of an object over time. I illustrated this by using the Fold()/Aggregate() method and applying events as the source of changes.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using LanguageExt;
using LanguageExt.DataTypes.Serialisation;

namespace Tutorial37
{

// This tutorial shows how you can use the Fold() function in languageExt to change the state of an object over time
class Program
{
static void Main(string[] args)
{
List<int> years = new List<int>
{
1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014,
2015, 2016, 2017, 2018, 2019
};

List<Event<Person>> events = new List<Event<Person>>
{
new ChangeNameEvent("Stuart"),
new ChangeExpertiseEvent("Programming"),
new ChangeNameEvent("Stuart Mathews"),
new ChangeExpertiseEvent("Running"),
new ChangeAgeEvent(33),
};

Person person = new Person();

// A state (InitialResult) changes over time and it changes using results of the previous change. It uses an item from the array in changing the state each time.
// The state changes the number of elements in the IEnumerable
// For a Lst which has multiple items in it, the state will change that many times

// NB: years represent the state changes that will occur
var changedPerson = years.Fold(/*initial state*/ person, (previousResult, year) => ChangeState(year, previousResult));

// Apply some events to the person over time
changedPerson = events.Fold(person, (previousResult, evt) => evt.ApplyEventTo(previousResult));

// View the changed person
Console.WriteLine($$"{changedPerson}"); // local function Person ChangeState(int year, Person previousResult) { Person updatedPerson = new Person(previousResult); updatedPerson.History.Add($$"\nIn {year}, this person was {updatedPerson.Age} years old");
updatedPerson.Age++;
return updatedPerson;
}
}
}
}

It's pretty interesting and the whole source can be found here under tutorial 38, where you can find the code for Person. Event(s) and run it and see the results etc

Basically its a very simple demonstration of a way that you can apply changes to an object by encoding various changes that can occur to that object into events that house a particular kind of state change of an object. There is probably a software architecture pattern there but I can't remember what its called. That whole idea is pretty much embedded into the LanguageExt Fold() method or the .net aggregate method.

I also decided to make an entry on Immutability in tutorial 39 which shows you how to design your objects with immutability in mind.

I also decided to do some light reading on performing effective investigations, filling out 5x5x5 intelligence reports and various bits and pieces about case management and labratory processes. I've got to do some practicals around Android forensics which I've put off because its all a bit laborious as this stage having performed a pretty full-on investigation over the last month or so and having had to then write up a report on it following correct invesgitation principles, procedures etc. So that can wait until next week-end I thought and after making a few notes, I decided to turn my attention to 3D Math. In particular, vector and matrix algebra and transformations. I want to be ready for when I have to be tested on it!

I started learning about 3D perspective projection (which talks about foreshortening) and orthogonal projection and went through the math of translating, rotating and scaling vectors using Matrices to represent affine transformations and then started looking at plugging these operations into the pipeline.

That last part pretty much took me most of the day. A day well spent!