<commit_before>! Copyright (C) 2018 <NAME>
! See http://factorcode.org/license.txt for BSD license

USING: arrays combinators io io.binary.fast io.encodings.binary
io.files kernel math sequences ;

IN: shapefiles

<PRIVATE

: read-int ( -- n )
    4 read le> ;

: read-double ( -- n )
    8 read le> bits>double ;

: read-box ( -- box )
    4 [ read-double ] replicate ;

: read-ints ( n -- parts )
    [ read-int ] replicate ;

: read-range ( -- range )
    read-double read-double 2array ;

: read-doubles ( n -- array )
    [ read-double ] replicate ;

PRIVATE>

TUPLE: header file-code file-length version shape-type x-min
y-min x-max y-max z-min z-max m-min m-max ;

: read-header ( -- header )
    4 read be> dup 9994 assert=
    20 read drop ! unused
    4 read be>
    read-int dup 1000 assert=
    read-int
    read-double
    read-double
    read-double
    read-double
    read-double
    read-double
    read-double
    read-double
    header boa ;

TUPLE: point x y ;

: read-point ( -- point )
    read-double read-double point boa ;

: read-points ( n -- points )
    [ read-point ] replicate ;

TUPLE: multipoint box points ;

: read-multipoint ( -- multipoint )
    read-box read-int read-points multipoint boa ;

TUPLE: polyline box parts points ;

: read-polyline ( -- polyline )
    read-box read-int read-int [ read-ints ] dip
    read-points polyline boa ;

TUPLE: polygon box parts points ;

: read-polygon ( -- polygon )
    read-box read-int read-int [ read-ints ] dip
    read-points polygon boa ;

TUPLE: point-m x y m ;

: read-point-m ( -- point-m )
    read-double read-double read-double point-m boa ;

TUPLE: multipoint-m box points m-range m-array ;

: read-multipoint-m ( -- multipoint-m )
    read-box read-int
    [ read-points read-range ] [ read-doubles ] bi
    multipoint-m boa ;

TUPLE: polyline-m box parts points m-range m-array ;

: read-polyline-m ( -- polyline-m )
    read-box read-int read-int [ read-ints ] dip
    [ read-points read-range ] [ read-doubles ] bi
    polyline-m boa ;

TUPLE: polygon-m box parts points m-range m-array ;

: read-polygon-m ( -- polyline-m )
    read-box read-int read-int [ read-ints ] dip
    [ read-points read-range ] [ read-doubles ] bi
    polygon-m boa ;

TUPLE: point-z x y z m ;

: read-point-z ( -- point-z )
    read-double read-double read-double read-double point-z boa ;

TUPLE: multipoint-z box points z-range z-array m-range m-array ;

: read-multipoint-z ( -- multipoint-z )
    read-box read-int
    [ read-points read-range ]
    [ read-doubles read-range ]
    [ read-doubles ] tri multipoint-z boa ;

TUPLE: polyline-z box parts points z-range z-array m-range
m-array ;

: read-polyline-z ( -- polyline-z )
    read-box read-int read-int [ read-ints ] dip
    [ read-points read-range ]
    [ read-doubles read-range ]
    [ read-doubles ] tri polyline-z boa ;

TUPLE: polygon-z box parts points z-range z-array m-range
m-array ;

: read-polygon-z ( -- polyline-z )
    read-box read-int read-int [ read-ints ] dip
    [ read-points read-range ]
    [ read-doubles read-range ]
    [ read-doubles ] tri polygon-z boa ;

TUPLE: multipatch box parts points part-types z-range z-array<commit_msg>shapefiles: more cleanup.<commit_after>! Copyright (C) 2018 <NAME>
! See http://factorcode.org/license.txt for BSD license

USING: arrays combinators io io.binary.fast io.encodings.binary
io.files kernel math sequences ;

IN: shapefiles

<PRIVATE

: read-int ( -- n )
    4 read le> ;

: read-ints ( n -- parts )
    [ read-int ] replicate ;

: read-double ( -- n )
    8 read le> bits>double ;

: read-doubles ( n -- array )
    [ read-double ] replicate ;

: read-box ( -- box )
    4 read-doubles ;

: read-range ( -- range )
    2 read-doubles ;

PRIVATE>

TUPLE: header file-code file-length version shape-type x-min
y-min x-max y-max z-min z-max m-min m-max ;

: read-header ( -- header )
    4 read be> dup 9994 assert=
    20 read drop ! unused
    4 read be>
    read-int dup 1000 assert=
    read-int
    read-double
    read-double
    read-double
    read-double
    read-double
    read-double
    read-double
    read-double
    header boa ;

TUPLE: point x y ;

: read-point ( -- point )
    read-double read-double point boa ;

: read-points ( n -- points )
    [ read-point ] replicate ;

TUPLE: multipoint box points ;

: read-multipoint ( -- multipoint )
    read-box read-int read-points multipoint boa ;

TUPLE: polyline box parts points ;

: read-polyline ( -- polyline )
    read-box read-int read-int [ read-ints ] dip
    read-points polyline boa ;

TUPLE: polygon box parts points ;

: read-polygon ( -- polygon )
    read-box read-int read-int [ read-ints ] dip
    read-points polygon boa ;

TUPLE: point-m x y m ;

: read-point-m ( -- point-m )
    read-double read-double read-double point-m boa ;

TUPLE: multipoint-m box points m-range m-array ;

: read-multipoint-m ( -- multipoint-m )
    read-box read-int
    [ read-points read-range ] [ read-doubles ] bi
    multipoint-m boa ;

TUPLE: polyline-m box parts points m-range m-array ;

: read-polyline-m ( -- polyline-m )
    read-box read-int read-int [ read-ints ] dip
    [ read-points read-range ] [ read-doubles ] bi
    polyline-m boa ;

TUPLE: polygon-m box parts points m-range m-array ;

: read-polygon-m ( -- polygon-m )
    read-box read-int read-int [ read-ints ] dip
    [ read-points read-range ] [ read-doubles ] bi
    polygon-m boa ;

TUPLE: point-z x y z m ;

: read-point-z ( -- point-z )
    read-double read-double read-double read-double point-z boa ;

TUPLE: multipoint-z box points z-range z-array m-range m-array ;

: read-multipoint-z ( -- multipoint-z )
    read-box read-int
    [ read-points read-range ]
    [ read-doubles read-range ]
    [ read-doubles ] tri multipoint-z boa ;

TUPLE: polyline-z box parts points z-range z-array m-range
m-array ;

: read-polyline-z ( -- polyline-z )
    read-box read-int read-int [ read-ints ] dip
    [ read-points read-range ]
    [ read-doubles read-range ]
    [ read-doubles ] tri polyline-z boa ;

TUPLE: polygon-z box parts points z-range z-array m-range
m-array ;

: read-polygon-z ( -- polygon-z )
    read-box read-int read-int [ read-ints ] dip
    [ read-points read-range ]
    [ read-doubles read-range ]
    [ read-doubles ] tri polygon-z boa ;

TUPLE: multipatch box parts points part-types z-range z-array
{'fraction_non_alphanumeric': 0.12423433328098005, 'fraction_numerical': 0.006282393591958536, 'mean_word_length': 2.418142780461621, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '1864303', 'n_tokens_mistral': 2368, 'n_tokens_neox': 2287, 'n_words': 625}