Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-28 09:19:37

0001 // Copyright (c) 2026 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _BRepGraphInc_ParityOrientation_HeaderFile
0015 #define _BRepGraphInc_ParityOrientation_HeaderFile
0016 
0017 #include <Standard_ProgramError.hxx>
0018 #include <TopAbs_Orientation.hxx>
0019 
0020 namespace BRepGraphInc
0021 {
0022 
0023 //! @brief Persisted core-topology orientation stored as forward/reversed parity only.
0024 //!
0025 //! The wrapper keeps storage compact through one bool while remaining implicitly
0026 //! convertible to `TopAbs_Orientation` for existing orientation-facing codepaths.
0027 struct ParityOrientation
0028 {
0029   //! Stored parity bit: `false` for `TopAbs_FORWARD`, `true` for `TopAbs_REVERSED`.
0030   bool IsReversed = false;
0031 
0032   //! Constructs the parity wrapper from a core forward/reversed orientation.
0033   ParityOrientation() = default;
0034 
0035   //! Constructs the parity wrapper from a core forward/reversed orientation.
0036   ParityOrientation(const TopAbs_Orientation theOrientation)
0037       : IsReversed(toIsReversed(theOrientation))
0038   {
0039   }
0040 
0041   //! Assigns a core forward/reversed orientation.
0042   ParityOrientation& operator=(const TopAbs_Orientation theOrientation)
0043   {
0044     IsReversed = toIsReversed(theOrientation);
0045     return *this;
0046   }
0047 
0048   //! Converts stored parity back to `TopAbs_Orientation`.
0049   operator TopAbs_Orientation() const { return IsReversed ? TopAbs_REVERSED : TopAbs_FORWARD; }
0050 
0051 private:
0052   //! Converts a core forward/reversed orientation to the stored parity bit.
0053   static bool toIsReversed(const TopAbs_Orientation theOrientation)
0054   {
0055     Standard_ProgramError_Raise_if(theOrientation != TopAbs_FORWARD
0056                                      && theOrientation != TopAbs_REVERSED,
0057                                    "BRepGraphInc::ParityOrientation stores only FORWARD/REVERSED");
0058     return theOrientation == TopAbs_REVERSED;
0059   }
0060 };
0061 
0062 } // namespace BRepGraphInc
0063 
0064 #endif // _BRepGraphInc_ParityOrientation_HeaderFile