gridprimitive2d.cxx (464702f4) gridprimitive2d.cxx (2a27d9ca)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 115 unchanged lines hidden (view full) ---

124 {
125 fViewSmallStepY *= 2.0;
126 fSmallStepY *= 2.0;
127 }
128
129 nSmallStepsY = (sal_uInt32)(fStepY / fSmallStepY);
130 }
131
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 115 unchanged lines hidden (view full) ---

124 {
125 fViewSmallStepY *= 2.0;
126 fSmallStepY *= 2.0;
127 }
128
129 nSmallStepsY = (sal_uInt32)(fStepY / fSmallStepY);
130 }
131
132 // prepare point vectors for point and cross markers
133 std::vector< basegfx::B2DPoint > aPositionsPoint;
134 std::vector< basegfx::B2DPoint > aPositionsCross;
132 // calculate extended viewport in which grid points may lie at all
133 basegfx::B2DRange aExtendedViewport;
135
134
136 for(double fX(0.0); fX < aScale.getX(); fX += fStepX)
137 {
138 const bool bXZero(basegfx::fTools::equalZero(fX));
135 if(rViewInformation.getDiscreteViewport().isEmpty())
136 {
137 // not set, use logic size to travel over all potentioal grid points
138 aExtendedViewport = basegfx::B2DRange(0.0, 0.0, aScale.getX(), aScale.getY());
139 }
140 else
141 {
142 // transform unit range to discrete view
143 aExtendedViewport = basegfx::B2DRange(0.0, 0.0, 1.0, 1.0);
144 basegfx::B2DHomMatrix aTrans(rViewInformation.getObjectToViewTransformation() * getTransform());
145 aExtendedViewport.transform(aTrans);
139
146
140 for(double fY(0.0); fY < aScale.getY(); fY += fStepY)
141 {
142 const bool bYZero(basegfx::fTools::equalZero(fY));
147 // intersect with visible part
148 aExtendedViewport.intersect(rViewInformation.getDiscreteViewport());
143
149
144 if(!bXZero && !bYZero)
145 {
146 // get discrete position and test against 3x3 area surrounding it
147 // since it's a cross
148 const double fHalfCrossSize(3.0 * 0.5);
149 const basegfx::B2DPoint aViewPos(aRST * basegfx::B2DPoint(fX, fY));
150 const basegfx::B2DRange aDiscreteRangeCross(
151 aViewPos.getX() - fHalfCrossSize, aViewPos.getY() - fHalfCrossSize,
152 aViewPos.getX() + fHalfCrossSize, aViewPos.getY() + fHalfCrossSize);
153
154 if(rViewInformation.getDiscreteViewport().overlaps(aDiscreteRangeCross))
150 if(!aExtendedViewport.isEmpty())
151 {
152 // convert back and apply scale
153 aTrans.invert();
154 aTrans.scale(aScale.getX(), aScale.getY());
155 aExtendedViewport.transform(aTrans);
156
157 // crop start/end in X/Y to multiples of logical step width
158 const double fHalfCrossSize((rViewInformation.getInverseObjectToViewTransformation() * basegfx::B2DVector(3.0, 0.0)).getLength());
159 const double fMinX(floor((aExtendedViewport.getMinX() - fHalfCrossSize) / fStepX) * fStepX);
160 const double fMaxX(ceil((aExtendedViewport.getMaxX() + fHalfCrossSize) / fStepX) * fStepX);
161 const double fMinY(floor((aExtendedViewport.getMinY() - fHalfCrossSize) / fStepY) * fStepY);
162 const double fMaxY(ceil((aExtendedViewport.getMaxY() + fHalfCrossSize) / fStepY) * fStepY);
163
164 // put to aExtendedViewport and crop on object logic size
165 aExtendedViewport = basegfx::B2DRange(
166 std::max(fMinX, 0.0),
167 std::max(fMinY, 0.0),
168 std::min(fMaxX, aScale.getX()),
169 std::min(fMaxY, aScale.getY()));
170 }
171 }
172
173 if(!aExtendedViewport.isEmpty())
174 {
175 // prepare point vectors for point and cross markers
176 std::vector< basegfx::B2DPoint > aPositionsPoint;
177 std::vector< basegfx::B2DPoint > aPositionsCross;
178
179 for(double fX(aExtendedViewport.getMinX()); fX < aExtendedViewport.getMaxX(); fX += fStepX)
180 {
181 const bool bXZero(basegfx::fTools::equalZero(fX));
182
183 for(double fY(aExtendedViewport.getMinY()); fY < aExtendedViewport.getMaxY(); fY += fStepY)
184 {
185 const bool bYZero(basegfx::fTools::equalZero(fY));
186
187 if(!bXZero && !bYZero)
155 {
188 {
156 const basegfx::B2DPoint aLogicPos(rViewInformation.getInverseObjectToViewTransformation() * aViewPos);
157 aPositionsCross.push_back(aLogicPos);
189 // get discrete position and test against 3x3 area surrounding it
190 // since it's a cross
191 const double fHalfCrossSize(3.0 * 0.5);
192 const basegfx::B2DPoint aViewPos(aRST * basegfx::B2DPoint(fX, fY));
193 const basegfx::B2DRange aDiscreteRangeCross(
194 aViewPos.getX() - fHalfCrossSize, aViewPos.getY() - fHalfCrossSize,
195 aViewPos.getX() + fHalfCrossSize, aViewPos.getY() + fHalfCrossSize);
196
197 if(rViewInformation.getDiscreteViewport().overlaps(aDiscreteRangeCross))
198 {
199 const basegfx::B2DPoint aLogicPos(rViewInformation.getInverseObjectToViewTransformation() * aViewPos);
200 aPositionsCross.push_back(aLogicPos);
201 }
158 }
202 }
159 }
160
203
161 if(getSubdivisionsX() && !bYZero)
162 {
163 double fF(fX + fSmallStepX);
204 if(getSubdivisionsX() && !bYZero)
205 {
206 double fF(fX + fSmallStepX);
164
207
165 for(sal_uInt32 a(1L); a < nSmallStepsX && fF < aScale.getX(); a++, fF += fSmallStepX)
166 {
167 const basegfx::B2DPoint aViewPos(aRST * basegfx::B2DPoint(fF, fY));
208 for(sal_uInt32 a(1); a < nSmallStepsX && fF < aExtendedViewport.getMaxX(); a++, fF += fSmallStepX)
209 {
210 const basegfx::B2DPoint aViewPos(aRST * basegfx::B2DPoint(fF, fY));
168
211
169 if(rViewInformation.getDiscreteViewport().isInside(aViewPos))
170 {
171 const basegfx::B2DPoint aLogicPos(rViewInformation.getInverseObjectToViewTransformation() * aViewPos);
172 aPositionsPoint.push_back(aLogicPos);
173 }
174 }
175 }
212 if(rViewInformation.getDiscreteViewport().isInside(aViewPos))
213 {
214 const basegfx::B2DPoint aLogicPos(rViewInformation.getInverseObjectToViewTransformation() * aViewPos);
215 aPositionsPoint.push_back(aLogicPos);
216 }
217 }
218 }
176
219
177 if(getSubdivisionsY() && !bXZero)
178 {
179 double fF(fY + fSmallStepY);
220 if(getSubdivisionsY() && !bXZero)
221 {
222 double fF(fY + fSmallStepY);
180
223
181 for(sal_uInt32 a(1L); a < nSmallStepsY && fF < aScale.getY(); a++, fF += fSmallStepY)
182 {
183 const basegfx::B2DPoint aViewPos(aRST * basegfx::B2DPoint(fX, fF));
224 for(sal_uInt32 a(1); a < nSmallStepsY && fF < aExtendedViewport.getMaxY(); a++, fF += fSmallStepY)
225 {
226 const basegfx::B2DPoint aViewPos(aRST * basegfx::B2DPoint(fX, fF));
184
227
185 if(rViewInformation.getDiscreteViewport().isInside(aViewPos))
186 {
187 const basegfx::B2DPoint aLogicPos(rViewInformation.getInverseObjectToViewTransformation() * aViewPos);
188 aPositionsPoint.push_back(aLogicPos);
189 }
190 }
191 }
192 }
193 }
228 if(rViewInformation.getDiscreteViewport().isInside(aViewPos))
229 {
230 const basegfx::B2DPoint aLogicPos(rViewInformation.getInverseObjectToViewTransformation() * aViewPos);
231 aPositionsPoint.push_back(aLogicPos);
232 }
233 }
234 }
235 }
236 }
194
237
195 // prepare return value
196 const sal_uInt32 nCountPoint(aPositionsPoint.size());
197 const sal_uInt32 nCountCross(aPositionsCross.size());
198 const sal_uInt32 nRetvalCount((nCountPoint ? 1 : 0) + (nCountCross ? 1 : 0));
199 sal_uInt32 nInsertCounter(0);
238 // prepare return value
239 const sal_uInt32 nCountPoint(aPositionsPoint.size());
240 const sal_uInt32 nCountCross(aPositionsCross.size());
241 const sal_uInt32 nRetvalCount((nCountPoint ? 1 : 0) + (nCountCross ? 1 : 0));
242 sal_uInt32 nInsertCounter(0);
200
243
201 aRetval.realloc(nRetvalCount);
244 aRetval.realloc(nRetvalCount);
202
245
203 // add PointArrayPrimitive2D if point markers were added
204 if(nCountPoint)
205 {
206 aRetval[nInsertCounter++] = Primitive2DReference(new PointArrayPrimitive2D(aPositionsPoint, getBColor()));
207 }
246 // add PointArrayPrimitive2D if point markers were added
247 if(nCountPoint)
248 {
249 aRetval[nInsertCounter++] = Primitive2DReference(new PointArrayPrimitive2D(aPositionsPoint, getBColor()));
250 }
208
251
209 // add MarkerArrayPrimitive2D if cross markers were added
210 if(nCountCross)
211 {
212 if(!getSubdivisionsX() && !getSubdivisionsY())
213 {
214 // no subdivisions, so fall back to points at grid positions, no need to
215 // visualize a difference between divisions and sub-divisions
216 aRetval[nInsertCounter++] = Primitive2DReference(new PointArrayPrimitive2D(aPositionsCross, getBColor()));
217 }
218 else
219 {
220 aRetval[nInsertCounter++] = Primitive2DReference(new MarkerArrayPrimitive2D(aPositionsCross, getCrossMarker()));
221 }
222 }
252 // add MarkerArrayPrimitive2D if cross markers were added
253 if(nCountCross)
254 {
255 if(!getSubdivisionsX() && !getSubdivisionsY())
256 {
257 // no subdivisions, so fall back to points at grid positions, no need to
258 // visualize a difference between divisions and sub-divisions
259 aRetval[nInsertCounter++] = Primitive2DReference(new PointArrayPrimitive2D(aPositionsCross, getBColor()));
260 }
261 else
262 {
263 aRetval[nInsertCounter++] = Primitive2DReference(new MarkerArrayPrimitive2D(aPositionsCross, getCrossMarker()));
264 }
265 }
266 }
223 }
224
225 return aRetval;
226 }
227
228 GridPrimitive2D::GridPrimitive2D(
229 const basegfx::B2DHomMatrix& rTransform,
230 double fWidth,

--- 86 unchanged lines hidden ---
267 }
268
269 return aRetval;
270 }
271
272 GridPrimitive2D::GridPrimitive2D(
273 const basegfx::B2DHomMatrix& rTransform,
274 double fWidth,

--- 86 unchanged lines hidden ---