<commit_before>package nz.gen.geek_central.GLUseful;
/*
    Basic reader for .obj 3D model files.

    Copyright 2011 by <NAME> <<EMAIL>>.

    Licensed under the Apache License, Version 2.0 (the "License"); you may not
    use this file except in compliance with the License. You may obtain a copy of
    the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    License for the specific language governing permissions and limitations under
    the License.
*/

import java.util.ArrayList;

public class ObjReader
  {

    public static class DataFormatException extends RuntimeException
      /* indicates a problem parsing a .obj file. */
      {

        public DataFormatException
          (
            String Message
          )
          {
            super(Message);
          } /*DataFormatException*/

      } /*DataFormatException*/

    private static class ObjTokenizer
      {
        private final java.io.InputStream Input;
        public boolean EOL, EOF;
        private boolean LastWasCR;
        public int LineNr, ColNr;

        public void Fail
          (
            String Msg
          )
          {
            throw new DataFormatException
              (
                String.format
                  (
                    "ObjReader error at line %d, col %d: %s",
                    LineNr, ColNr,
                    Msg
                  )
              );
          } /*Fail*/

        public ObjTokenizer
          (
            java.io.InputStream Input
          )
          {
            this.Input = Input;
            EOL = false;
            EOF = false;
            LastWasCR = false;
            LineNr = 1;
            ColNr = 0;
          } /*ObjTokenizer*/

        private boolean IsSeparator
          (
            char Ch
          )
          {
            return
                Ch <= ' ';
          } /*IsSeparator*/

        private boolean IsEOL
          (
            char Ch
          )
          {
            return
                Ch == '\015' || Ch == '\012';
          } /*IsEOL*/

        private char NextCh()
          {
            if (EOF)
              {
                Fail("read past EOF");
              } /*if*/
            if (EOL)
              {
                ++LineNr;
                ColNr = 0;
              } /*if*/
            ++ColNr;
            /*final*/ char Result
                = (char)-1; /*sigh*/
            try
              {
                for (;;)
                  {
                    final int ich = Input.read();
                    if (ich < 0)
                      {
                        EOF = true;
                        Result = '\n';
                        break;
                      }
                    else if (LastWasCR && (char)ich == '\012')
                      {
                      /* skip LF following CR */
                        LastWasCR = false;
                      }
                    else
                      {
                        Result = (char)ich;
                        break;
                      } /*if*/
                  } /*for*/
              }
            catch (java.io.IOException IOError)
              {
                Fail("input error: " + IOError.toString());
              } /*try*/
            EOL = EOF || IsEOL(Result);
            LastWasCR = Result == '\015';
            return
                Result;
          } /*NextCh*/

        public String NextSym
          (
            boolean Required
          )
          /* fetches next symbol from current line, or null if none. */
          {
            final StringBuilder CurSym = new StringBuilder();
            String Result = null;
            for (;;)
              {
                if (EOL)
                  {
                    if (CurSym.length() != 0)
                      {
                        Result = CurSym.toString();
                      }
                    else
                      {
                        if (Required)
                          {
                            Fail("missing required symbol");
                          } /*if*/
                      } /*if*/
                    break;
                  } /*if*/
                final char Ch = NextCh();
                if (IsSeparator(Ch))
                  {
                    if (CurSym.length() != 0)
                        break;
                  }
                else
                  {
                    CurSym.appendCodePoint((int)Ch);
                  } /*if*/
              } /*for*/
            return
                Result;
          } /*NextSym*/

        public void EndLine()
          /* skips rest of current line (must be nothing more than whitespace left). */
          {
            for (;;)
              {
                if (EOL)
                    break;
                final char Ch = NextCh();
                if (IsEOL(Ch))
                    break;
                if (!IsSeparator(Ch))
                  {
                    Fail("unexpected stuff at end of line");
                  } /*if*/
              } /*for*/
            EOL = false;
          } /*EndLine*/

        public GeomBuilder.Vec3f GetVec()
          {
            final String XStr = NextSym(true);
            final String YStr = NextSym(true);
            final String ZStr = NextSym(true);
            /*final*/ GeomBuilder.Vec3f Result
                = null; /*sigh*/
            try
              {
                Result = new GeomBuilder.Vec3f
                  (
                    Float.parseFloat(XStr),
                    Float.parseFloat(YStr),
                    Float.parseFloat(ZStr)
                  );
              }
            catch (NumberFormatException BadNum)
              {
                Fail("bad vector coordinate");
              } /*catch*/
            return
                Result;
          } /*GetVec*/

        public void SkipRest()
          {
            while (!EOL)
              {
                NextCh();
              } /*while*/
          } /*SkipRest*/

      } /*ObjTokenizer*/

    private static class FaceVert
      {
        public final Integer VertIndex, TexCoordIndex, NormalIndex;

        public FaceVert
          (
            Integer VertIndex, /* mandatory */
            Integer TexCoordIndex, /* optional */
            Integer NormalIndex /* optional */
          )
          {
            this.VertIndex = VertIndex;
            this.TexCoordIndex = TexCoordIndex;
            this.NormalIndex = NormalIndex;
          } /*FaceVert*/

      } /*FaceVert*/

    public static GeomBuilder.Obj Read
      (
        java.io.InputStream From
      )
    throws DataFormatException
      {
        final ObjTokenizer Parse = new ObjTokenizer(From);
        ArrayList<GeomBuilder.Vec3f>
            Vertices = null,
            TexCoords = null,
            Normals = null;
        ArrayList<FaceVert[]> Faces = null;
        for (;;)
          {
            final String OpStr = Parse.NextSym(false);
            if (OpStr != null)
              {
                final String Op = OpStr.intern();
                if (Op == "v")
                  {
                    final GeomBuilder.Vec3f Vec = Parse.GetVec();
                    if (Vertices == null)
                      {
                        Vertices = new ArrayList<GeomBuilder.Vec3f>();
                      } /*if*/
                    Vertices.add(Vec);
                  }
                else if (Op == "vt")
                  {
                    final GeomBuilder.Vec3f Vec = Parse.GetVec();
                    if (TexCoords == null)
                      {
                        TexCoords = new ArrayList<GeomBuilder.Vec3f>();
                      } /*if*/
                    TexCoords.add(Vec);
                  }
                else if (Op == "vn")
                  {
                    final GeomBuilder.Vec3f Vec = Parse.GetVec();
                    if (Normals == null)
                      {
                        Normals = new ArrayList<GeomBuilder.Vec3f>();
                      } /*if*/
                    Normals.add(Vec);
                  }
                else if (Op == "f")
                  {
                    if (Faces == null)
                      {
                        Faces = new ArrayList<FaceVert[]>();
                      } /*if*/
                    ArrayList<FaceVert> FaceVerts = new ArrayList<FaceVert>();
                    for (;;)
                      {
                        final String VertStr = Parse.NextSym(false);
                        if (VertStr == null)
                            break;
                        Integer VertIndex = null, TexCoordIndex = null, NormalIndex = null;
                        int Which = 0, ThisPos = 0, LastPos;
                        for (;;)
                          {
                            LastPos = ThisPos;
                            for (;;)
                              {
                                if (ThisPos == VertStr.length())
                                    break;
                                if (VertStr.charAt(ThisPos) == '/')
                                    break;
                                ++ThisPos;
                              } /*for*/
                            if (ThisPos > LastPos + 1)
                              {
                                int ThisComponent
                                    = -1; /*sigh*/
                                try
                                  {
                                    ThisComponent = Integer.parseInt
                                      (
                                        VertStr.substring(LastPos, ThisPos)
                                      );
                                  }
                                catch (NumberFormatException BadNum)
                                  {
                                    Parse.Fail("bad vertex index");<commit_msg>parsing completes without errors, at least<commit_after>package nz.gen.geek_central.GLUseful;
/*
    Basic reader for .obj 3D model files.

    Copyright 2011 by <NAME> <<EMAIL>>.

    Licensed under the Apache License, Version 2.0 (the "License"); you may not
    use this file except in compliance with the License. You may obtain a copy of
    the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    License for the specific language governing permissions and limitations under
    the License.
*/

import java.util.ArrayList;

public class ObjReader
  {

    public static class DataFormatException extends RuntimeException
      /* indicates a problem parsing a .obj file. */
      {

        public DataFormatException
          (
            String Message
          )
          {
            super(Message);
          } /*DataFormatException*/

      } /*DataFormatException*/

    private static class ObjTokenizer
      {
        private final java.io.InputStream Input;
        public boolean EOL, EOF;
        private boolean LastWasCR, InComment;
        public int LineNr, ColNr;

        public void Fail
          (
            String Msg
          )
          {
            throw new DataFormatException
              (
                String.format
                  (
                    "ObjReader error at line %d, col %d: %s",
                    LineNr, ColNr,
                    Msg
                  )
              );
          } /*Fail*/

        public ObjTokenizer
          (
            java.io.InputStream Input
          )
          {
            this.Input = Input;
            EOL = false;
            EOF = false;
            LastWasCR = false;
            InComment = false;
            LineNr = 1;
            ColNr = 0;
          } /*ObjTokenizer*/

        private boolean IsSeparator
          (
            char Ch
          )
          {
            return
                Ch <= ' ';
          } /*IsSeparator*/

        private boolean IsEOL
          (
            char Ch
          )
          {
            return
                Ch == '\015' || Ch == '\012';
          } /*IsEOL*/

        private char NextCh()
          {
            if (EOF)
              {
                Fail("read past EOF");
              } /*if*/
            ++ColNr;
            /*final*/ char Result
                = (char)-1; /*sigh*/
            try
              {
                for (;;)
                  {
                    final int ich = Input.read();
                    if (ich < 0)
                      {
                        EOF = true;
                        Result = '\n';
                        break;
                      }
                    else if (LastWasCR && (char)ich == '\012')
                      {
                      /* skip LF following CR */
                        LastWasCR = false;
                      }
                    else
                      {
                        Result = (char)ich;
                        break;
                      } /*if*/
                  } /*for*/
              }
            catch (java.io.IOException IOError)
              {
                Fail("input error: " + IOError.toString());
              } /*try*/
            EOL = EOF || IsEOL(Result);
            LastWasCR = Result == '\015';
            return
                Result;
          } /*NextCh*/

        public String NextSym
          (
            boolean Required
          )
          /* fetches next symbol from current line, or null if none. */
          {
            final StringBuilder CurSym = new StringBuilder();
            for (;;)
              {
                if (EOL)
                    break;
                final char Ch = NextCh();
                if (!InComment)
                  {
                    if (IsSeparator(Ch))
                      {
                        if (CurSym.length() != 0)
                            break;
                      }
                    else if (Ch == '#')
                      {
                        InComment = true;
                      }
                    else
                      {
                        CurSym.appendCodePoint((int)Ch);
                      } /*if*/
                  } /*if*/
              } /*for*/
            final String Result =
                CurSym.length() != 0 ?
                    CurSym.toString()
                :
                    null;
            if (Result == null && Required)
              {
                Fail("missing required symbol");
              } /*if*/
            return
                Result;
          } /*NextSym*/

        public void EndLine()
          /* skips rest of current line (must be nothing more than whitespace left). */
          {
            for (;;)
              {
                if (EOL)
                    break;
                final char Ch = NextCh();
                if (IsEOL(Ch))
                    break;
                if (!InComment && !IsSeparator(Ch))
                  {
                    Fail("unexpected stuff at end of line");
                  } /*if*/
              } /*for*/
            EOL = false;
            if (!EOF)
              {
                ++LineNr;
                ColNr = 0;
              } /*if*/
            InComment = false;
          } /*EndLine*/

        public GeomBuilder.Vec3f GetVec()
          {
            final String XStr = NextSym(true);
            final String YStr = NextSym(true);
            final String ZStr = NextSym(true);
            /*final*/ GeomBuilder.Vec3f Result
                = null; /*sigh*/
            try
              {
                Result = new GeomBuilder.Vec3f
                  (
                    Float.parseFloat(XStr),
                    Float.parseFloat(YStr),
                    Float.parseFloat(ZStr)
                  );
              }
            catch (NumberFormatException BadNum)
              {
                Fail("bad vector coordinate");
              } /*catch*/
            return
                Result;
          } /*GetVec*/

        public void SkipRest()
          {
            while (!EOL)
              {
                NextCh();
              } /*while*/
          } /*SkipRest*/

      } /*ObjTokenizer*/

    private static class FaceVert
      {
        public final Integer VertIndex, TexCoordIndex, NormalIndex;

        public FaceVert
          (
            Integer VertIndex, /* mandatory */
            Integer TexCoordIndex, /* optional */
            Integer NormalIndex /* optional */
          )
          {
            this.VertIndex = VertIndex;
            this.TexCoordIndex = TexCoordIndex;
            this.NormalIndex = NormalIndex;
          } /*FaceVert*/

      } /*FaceVert*/

    public static GeomBuilder.Obj Read
      (
        java.io.InputStream From
      )
    throws DataFormatException
      {
        final ObjTokenizer Parse = new ObjTokenizer(From);
        ArrayList<GeomBuilder.Vec3f>
            Vertices = null,
            TexCoords = null,
            Normals = null;
        ArrayList<FaceVert[]> Faces = null;
        for (;;)
          {
            final String OpStr = Parse.NextSym(false);
            if (OpStr != null)
              {
                final String Op = OpStr.intern();
                if (Op == "v")
                  {
                    final GeomBuilder.Vec3f Vec = Parse.GetVec();
                    if (Vertices == null)
                      {
                        Vertices = new ArrayList<GeomBuilder.Vec3f>();
                      } /*if*/
                    Vertices.add(Vec);
                  }
                else if (Op == "vt")
                  {
                    final GeomBuilder.Vec3f Vec = Parse.GetVec();
                    if (TexCoords == null)
                      {
                        TexCoords = new ArrayList<GeomBuilder.Vec3f>();
                      } /*if*/
                    TexCoords.add(Vec);
                  }
                else if (Op == "vn")
                  {
                    final GeomBuilder.Vec3f Vec = Parse.GetVec();
                    if (Normals == null)
                      {
                        Normals = new ArrayList<GeomBuilder.Vec3f>();
                      } /*if*/
                    Normals.add(Vec);
                  }
                else if (Op == "f")
                  {
                    if (Faces == null)
                      {
                        Faces = new ArrayList<FaceVert[]>();
                      } /*if*/
                    final ArrayList<FaceVert> FaceVerts = new ArrayList<FaceVert>();
                    for (;;)
                      {
                        final String VertStr = Parse.NextSym(false);
                        if (VertStr == null)
                            break;
                        Integer VertIndex = null, TexCoordIndex = null, NormalIndex = null;
                        int Which = 0, ThisPos = 0, LastPos;
                        for (;;)
                          {
                            LastPos = ThisPos;
                            for (;;)
                              {
                                if (ThisPos == VertStr.length())
                                    break;
                                if (VertStr.charAt(ThisPos) == '/')
                                    break;
                                ++ThisPos;
                              } /*for*/
                            if (ThisPos > LastPos)
                              {
                                int ThisComponent
                                    = -1; /*sigh*/
                                try
                                  {
                                    ThisComponent = Integer.parseInt
                                      (
                                        VertStr.substring(LastPos, ThisPos)
                                      );
                                  }
                                catch (NumberFormatException BadNum)
                                  {
                                    Parse.Fail("bad vertex index");
{'fraction_non_alphanumeric': 0.08539423916205993, 'fraction_numerical': 0.004024827853748424, 'mean_word_length': 0.7711267605633803, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1025003', 'n_tokens_mistral': 4857, 'n_tokens_neox': 4501, 'n_words': 1184}