< Summary

Information
Class: JeremyAnsel.Media.WavefrontObj.ObjFileReaderContext
Assembly: JeremyAnsel.Media.WavefrontObj
File(s): C:\projects\jeremyansel-media-wavefrontobj\JeremyAnsel.Media.WavefrontObj\JeremyAnsel.Media.WavefrontObj\ObjFileReaderContext.cs
Line coverage
100%
Covered lines: 43
Uncovered lines: 0
Coverable lines: 43
Total lines: 132
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetCurrentGroups()100%22100%
CreateGroups()100%88100%
GetGroupByName(...)100%11100%
ApplyAttributesToElement(...)100%11100%
ApplyAttributesToPolygonalElement(...)100%11100%
ApplyAttributesToFreeFormElement(...)100%11100%

File(s)

C:\projects\jeremyansel-media-wavefrontobj\JeremyAnsel.Media.WavefrontObj\JeremyAnsel.Media.WavefrontObj\ObjFileReaderContext.cs

#LineLine coverage
 1// <copyright file="ObjFileReaderContext.cs" company="Jérémy Ansel">
 2// Copyright (c) 2017, 2019 Jérémy Ansel
 3// </copyright>
 4// <license>
 5// Licensed under the MIT license. See LICENSE.txt
 6// </license>
 7
 8namespace JeremyAnsel.Media.WavefrontObj;
 9
 10internal class ObjFileReaderContext
 11{
 12    private readonly ObjFile _obj;
 13
 314    public ObjFileReaderContext(ObjFile obj, ObjFileReaderSettings settings)
 15    {
 316        _obj = obj;
 317        Settings = settings;
 18
 319        GroupNames = new List<string>();
 320    }
 21
 22    public ObjFileReaderSettings Settings { get; }
 23
 24    public string? ObjectName { get; set; }
 25
 26    public int LevelOfDetail { get; set; }
 27
 28    public string? MapName { get; set; }
 29
 30    public string? MaterialName { get; set; }
 31
 32    public long SmoothingGroupNumber { get; set; }
 33
 34    public bool IsBevelInterpolationEnabled { get; set; }
 35
 36    public bool IsColorInterpolationEnabled { get; set; }
 37
 38    public bool IsDissolveInterpolationEnabled { get; set; }
 39
 40    public int MergingGroupNumber { get; set; }
 41
 42    public ObjFreeFormType FreeFormType { get; set; }
 43
 44    public bool IsRationalForm { get; set; }
 45
 46    public int DegreeU { get; set; }
 47
 48    public int DegreeV { get; set; }
 49
 50    public float[]? BasicMatrixU { get; set; }
 51
 52    public float[]? BasicMatrixV { get; set; }
 53
 54    public float StepU { get; set; }
 55
 56    public float StepV { get; set; }
 57
 58    public ObjApproximationTechnique? CurveApproximationTechnique { get; set; }
 59
 60    public ObjApproximationTechnique? SurfaceApproximationTechnique { get; set; }
 61
 62    public ObjFreeFormElement? CurrentFreeFormElement { get; set; }
 63
 64    public List<string> GroupNames { get; private set; }
 65
 66    private List<ObjGroup>? _currentGroups;
 67
 68    public List<ObjGroup> GetCurrentGroups()
 69    {
 370        if (_currentGroups is not null) return _currentGroups;
 371        _currentGroups = [_obj.DefaultGroup];
 372        return _currentGroups;
 73    }
 74
 75    public void CreateGroups()
 76    {
 377        _currentGroups = new List<ObjGroup>();
 378        foreach (var name in this.GroupNames)
 79        {
 380            ObjGroup? group = null;
 381            if (!Settings.HandleEachGroupOccurrenceAsNewGroup)
 382                group = GetGroupByName(name);
 83
 384            if (group is null)
 85            {
 386                group = new ObjGroup(name);
 387                _obj.Groups.Add(group);
 88            }
 89
 390            _currentGroups.Add(group);
 91        }
 92
 393        if (_currentGroups.Count == 0)
 94        {
 395            _currentGroups.Add(_obj.DefaultGroup);
 96        }
 397    }
 98
 99    private ObjGroup? GetGroupByName(string name)
 3100        => _obj.Groups.Find(t => string.Equals(t.Name, name, StringComparison.Ordinal));
 101
 102    public void ApplyAttributesToElement(ObjElement element)
 103    {
 3104        element.ObjectName = this.ObjectName;
 3105        element.LevelOfDetail = this.LevelOfDetail;
 3106        element.MapName = this.MapName;
 3107        element.MaterialName = this.MaterialName;
 3108    }
 109
 110    public void ApplyAttributesToPolygonalElement(ObjPolygonalElement element)
 111    {
 3112        element.SmoothingGroupNumber = this.SmoothingGroupNumber;
 3113        element.IsBevelInterpolationEnabled = this.IsBevelInterpolationEnabled;
 3114        element.IsColorInterpolationEnabled = this.IsColorInterpolationEnabled;
 3115        element.IsDissolveInterpolationEnabled = this.IsDissolveInterpolationEnabled;
 3116    }
 117
 118    public void ApplyAttributesToFreeFormElement(ObjFreeFormElement element)
 119    {
 3120        element.MergingGroupNumber = this.MergingGroupNumber;
 3121        element.FreeFormType = this.FreeFormType;
 3122        element.IsRationalForm = this.IsRationalForm;
 3123        element.DegreeU = this.DegreeU;
 3124        element.DegreeV = this.DegreeV;
 3125        element.BasicMatrixU = this.BasicMatrixU;
 3126        element.BasicMatrixV = this.BasicMatrixV;
 3127        element.StepU = this.StepU;
 3128        element.StepV = this.StepV;
 3129        element.CurveApproximationTechnique = this.CurveApproximationTechnique;
 3130        element.SurfaceApproximationTechnique = this.SurfaceApproximationTechnique;
 3131    }
 132}