source: git/Singular/Cone.cc @ b7b65ee

fieker-DuValspielwiese
Last change on this file since b7b65ee was 86b2ec4, checked in by Hans Schoenemann <hannes@…>, 14 years ago
fix format git-svn-id: file:///usr/local/Singular/svn/trunk@13214 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.2 KB
Line 
1#include "mod2.h"
2#include <stdio.h>
3#include <string>
4#include <kernel/matpol.h>
5#include <kernel/intvec.h>
6#include <Singular/lists.h>
7#include <Fan.h>
8#include <Cone.h>
9
10#ifdef HAVE_FANS
11
12Cone* Cone::noFacet()
13{
14  Cone* c = new Cone();
15  c->setDim(1); /* abuse of dim member */
16  return c;
17}
18
19Cone* Cone::noAdjacency()
20{
21  Cone* c = new Cone();
22  c->setDim(2); /* abuse of dim member */
23  return c;
24}
25
26bool Cone::isNoFacet ()
27{
28  /* will return true iff this cone has been created using
29     Cone::noFacet() */
30  return ((m_facetNs == NULL) && (m_rays == NULL) &&
31          (m_dim == 1));
32}
33
34bool Cone::isNoAdj()
35{
36  /* will return true iff this cone has been created using
37     Cone::noAdjacency() */
38  return ((m_facetNs == NULL) && (m_rays == NULL) &&
39          (m_dim == 2));
40}
41
42int Cone::checkConeData(const Fan* pFan,
43                        const intvec* rays,
44                        const intvec* facetNs)
45{
46  int nMaxRays = 0;
47  if (pFan->getMaxRays() != NULL) nMaxRays = pFan->getMaxRays()->cols();
48  int nFacetNs = 0;
49  if (pFan->getFacetNs() != NULL) nFacetNs = pFan->getFacetNs()->cols();
50  int index;                       
51  if (rays != NULL)
52  {
53    for (int i = 0; i < rays->length(); i++)
54    {
55      index = (int)(long)((*rays)[i]);
56      if ((index < 1) || (index > nMaxRays)) return i + 1;
57    }
58  }
59  if (facetNs != NULL)
60  {
61    for (int i = 0; i < facetNs->length(); i++)
62    {
63      index = (int)(long)((*facetNs)[i]);
64      if ((index < 1) || (index > nFacetNs)) return -i - 1;
65    }
66  }
67  return 0;
68}
69
70Cone::Cone(Fan* pFan,
71           const intvec* rays,
72           const intvec* facetNs)
73{
74  m_pFan = NULL;
75  if (pFan != NULL) m_pFan = pFan;
76  m_rays = NULL;
77  if (rays != NULL) m_rays = ivCopy(rays);
78  m_facetNs = NULL;
79  if (facetNs != NULL) m_facetNs = ivCopy(facetNs);
80  m_dim = -1;
81}
82
83Fan*    Cone::getFan()      const { return m_pFan;     }
84intvec* Cone::getRays()     const { return m_rays;     }
85intvec* Cone::getFacetNs()  const { return m_facetNs;  }
86int     Cone::getDim()      const { return m_dim;      }
87
88Cone::Cone(const Cone& c)
89{ /* this is deep copy */
90  m_pFan = c.m_pFan;
91  m_rays = NULL;
92  if (c.getRays() != NULL) m_rays = ivCopy(c.getRays());
93  m_facetNs = NULL;
94  if (c.getFacetNs() != NULL) m_facetNs = ivCopy(c.getFacetNs());
95  m_dim = c.getDim();
96}
97
98Cone::Cone()
99{
100  m_pFan    = NULL;
101  m_rays    = NULL;
102  m_facetNs = NULL;
103  m_dim = -1;
104}
105
106Cone::~Cone()
107{
108  m_pFan = NULL;
109  if (m_rays    != NULL) delete m_rays;
110  if (m_facetNs != NULL) delete m_facetNs;
111}
112
113void Cone::setDim(const int dim)
114{
115  m_dim = dim;
116  if (m_dim < 0) m_dim = -1;
117}
118
119char* Cone::toString() const
120{
121  char h[50];
122  std::string s;
123  if (m_pFan == NULL)
124    s = "//   cone (no properties set)";
125  else
126  {
127    s = "//   cone:\n";
128    int i = 0; if (m_rays != NULL) i = m_rays->length();
129    sprintf(h, "//      %d rays\n", i); s += h;
130    i = 0; if (m_facetNs != NULL) i = m_facetNs->length();
131    sprintf(h, "//      %d facet normals\n", i); s += h;
132    s += "//      dimension: " ;
133    if (m_dim == -1) s += "?";
134    else { sprintf(h, "%d", m_dim); s += h; }
135  }
136  return omStrDup(s.c_str());
137}
138
139void Cone::print() const
140{
141  char* s = this->toString();
142  printf("%s", s);
143  omFree(s);
144}
145
146#endif
147/* HAVE_FANS */
Note: See TracBrowser for help on using the repository browser.