From 876dd4dcc0328aae2b121f25acc54d2b21c08f00 Mon Sep 17 00:00:00 2001 From: Stephan Barth Date: Fri, 22 Dec 2023 18:04:44 +0100 Subject: [PATCH] Started Layer objects. --- Manticore/Layer.pm | 110 ++++++++++++++++++++++++++++++++++++++++++++ Manticore/Mantis.pm | 2 + 2 files changed, 112 insertions(+) create mode 100644 Manticore/Layer.pm diff --git a/Manticore/Layer.pm b/Manticore/Layer.pm new file mode 100644 index 0000000..9575585 --- /dev/null +++ b/Manticore/Layer.pm @@ -0,0 +1,110 @@ +package Manticore::Layer; + +# A layer contains an internal representation of data +# It renders into a list of objects, which are one of +# * non-selfoverlapping polygons with abstract color +# * Named lines +# * Named points +# * Named float values + +use strict; +use warnings; + +# renderMode, each entry: +# convert -- return the polynomials from the data and sub-layers +# parse -- what we parse; either everything or blockwise +# parsemode -- do we parse blockwise (that is: whitespace free sequences thay may contain whitespace in (), but these may only contain matching ()s) or total +# desc -- description text +# children -- meant to have child layers + +my %renderMode = ( + traverse => { + convert => sub {}, + parse => sub { + my $block = shift; + }, + parsemode => "blockwise", + desc => 'A closed traverse line defining the object. That can be a polygon or contain additional interpolation primitives.', + children => 0, + }, + polynom => { + convert => sub {}, + parse => sub {}, + parsemode => "blockwise", + desc => 'A polynomial whichs positive set defines the object.', + children => 0, + }, + union => { + convert => sub {}, + parse => sub {}, + parsemode => "blockwise", + desc => 'Several layers atop of each other; the higher/earlier layers cover the layers below. It has the color if the color can be seen in the highest layer', + children => 1, + }, + intersect => { + convert => sub {}, + parse => sub {}, + parsemode => "blockwise", + desc => 'Several layers atop of each other; color is only there if it is there in every layer and the same.', + children => 1, + }, + difference => { + convert => sub {}, + parse => sub {}, + parsemode => "blockwise", + desc => 'Several layers atop of each other; color of the first layer unless any of the further layers has this color as well.', + children => 1, + }, + hull => { + convert => sub {}, + parse => sub {}, + parsemode => "blockwise", + desc => 'Convex hull of the object.', + children => 1, + }, + sum => { + convert => sub {}, + parse => sub {}, + parsemode => "blockwise", + desc => 'Minkowsky sum of the sub objects.', + children => 1, + }, + recol => { + convert => sub {}, + parse => sub {}, + parsemode => "blockwise", + desc => 'Recolorize the sub objects.', + children => 1, + }, + file => { + convert => sub {}, + parse => sub {}, + parsemode => "everything", + desc => 'Load the data from an external file.', + children => 0, + }, +); + +sub fromText { + my (undef, $head, $cont) = @_; + if(exists $renderMode{$head}) { + my $render = $renderMode{$head}; + my @all = ($cont); + if('blockwise' eq $render->{parsemode}) { + # split into blocks + # Note: regexes have sub-patterns + # "aababb"=~m#^(?|ab|a(?&AB)ba(?&AB)b|a(?&AB)b)$# + } + my $data = $render->{parse}->($cont); + return undef unless $data; + return bless { + data => $data, + mode => $head, + }; + } else { + return undef; + } +} + + +1; diff --git a/Manticore/Mantis.pm b/Manticore/Mantis.pm index e0375bf..f4a099d 100644 --- a/Manticore/Mantis.pm +++ b/Manticore/Mantis.pm @@ -4,6 +4,8 @@ use strict; use warnings; use Math::Trig; +use Manticore::Layer; + our %font; my %curvefunctions = (