Started Layer objects.
This commit is contained in:
parent
c6f972110d
commit
876dd4dcc0
110
Manticore/Layer.pm
Normal file
110
Manticore/Layer.pm
Normal file
@ -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>|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;
|
||||
@ -4,6 +4,8 @@ use strict;
|
||||
use warnings;
|
||||
use Math::Trig;
|
||||
|
||||
use Manticore::Layer;
|
||||
|
||||
our %font;
|
||||
|
||||
my %curvefunctions = (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user