natural-pdf 0.2.15__py3-none-any.whl → 0.2.16__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -106,6 +106,7 @@ class FlowElement:
106
106
  cross_size_absolute: Optional[float] = None,
107
107
  cross_alignment: str = "center", # "start", "center", "end"
108
108
  until: Optional[str] = None,
109
+ include_source: bool = False,
109
110
  include_endpoint: bool = True,
110
111
  **kwargs,
111
112
  ) -> "FlowRegion":
@@ -178,13 +179,9 @@ class FlowElement:
178
179
  is_forward = False
179
180
  segment_iterator = range(start_segment_index, -1, -1)
180
181
  elif direction == "right":
181
- if is_primary_vertical:
182
- raise NotImplementedError("'right' is for horizontal flows.")
183
182
  is_forward = True
184
183
  segment_iterator = range(start_segment_index, len(self.flow.segments))
185
184
  elif direction == "left":
186
- if is_primary_vertical:
187
- raise NotImplementedError("'left' is for horizontal flows.")
188
185
  is_forward = False
189
186
  segment_iterator = range(start_segment_index, -1, -1)
190
187
  else:
@@ -206,28 +203,34 @@ class FlowElement:
206
203
  "direction": direction,
207
204
  "until": until,
208
205
  "include_endpoint": include_endpoint,
206
+ "include_source": include_source,
209
207
  **kwargs,
210
208
  }
211
209
 
212
- # --- Cross-size logic: Default to "full" if no specific ratio or absolute is given ---
210
+ # --- Cross-size logic: Default based on direction ---
213
211
  cross_size_for_op: Union[str, float]
214
212
  if cross_size_absolute is not None:
215
213
  cross_size_for_op = cross_size_absolute
216
214
  elif cross_size_ratio is not None: # User explicitly provided a ratio
215
+ # Cross dimension depends on direction, not flow arrangement
217
216
  base_cross_dim = (
218
217
  self.physical_object.width
219
- if is_primary_vertical
218
+ if direction in ["above", "below"]
220
219
  else self.physical_object.height
221
220
  )
222
221
  cross_size_for_op = base_cross_dim * cross_size_ratio
223
- else: # Default case: neither absolute nor ratio provided, so use "full"
224
- cross_size_for_op = "full"
222
+ else: # Default case: neither absolute nor ratio provided
223
+ # Default to element size for left/right, full for above/below
224
+ if direction in ["left", "right"]:
225
+ cross_size_for_op = self.physical_object.height
226
+ else:
227
+ cross_size_for_op = "full"
225
228
  op_direction_params["cross_size"] = cross_size_for_op
226
229
 
227
230
  if current_segment_idx == start_segment_index:
228
231
  op_source = self.physical_object
229
232
  op_direction_params["size"] = remaining_size if size is not None else None
230
- op_direction_params["include_source"] = False
233
+ op_direction_params["include_source"] = include_source
231
234
 
232
235
  source_for_op_call = op_source
233
236
  if not isinstance(source_for_op_call, PhysicalRegion_Class):
@@ -245,7 +248,7 @@ class FlowElement:
245
248
  "size": remaining_size if size is not None else None,
246
249
  "cross_size": cross_size_for_op,
247
250
  "cross_alignment": cross_alignment, # Pass alignment
248
- "include_source": False,
251
+ "include_source": include_source,
249
252
  # Pass other relevant kwargs if Region._direction uses them (e.g. strict_type)
250
253
  **{k: v for k, v in kwargs.items() if k in ["strict_type", "first_match_only"]},
251
254
  }
@@ -283,7 +286,7 @@ class FlowElement:
283
286
  if potential_hit:
284
287
  boundary_element_hit = potential_hit # Set the overall boundary flag
285
288
  # Adjust segment_contribution to stop at this boundary_element_hit.
286
- if is_primary_vertical:
289
+ if direction in ["below", "above"]:
287
290
  if direction == "below":
288
291
  edge = (
289
292
  boundary_element_hit.bottom
@@ -300,7 +303,7 @@ class FlowElement:
300
303
  bottom=edge if direction == "below" else None,
301
304
  top=edge if direction == "above" else None,
302
305
  )
303
- else:
306
+ else: # direction in ["right", "left"]
304
307
  if direction == "right":
305
308
  edge = (
306
309
  boundary_element_hit.x1
@@ -338,7 +341,7 @@ class FlowElement:
338
341
 
339
342
  if potential_hit:
340
343
  boundary_element_hit = potential_hit
341
- if is_primary_vertical:
344
+ if direction in ["below", "above"]:
342
345
  if direction == "below":
343
346
  edge = (
344
347
  boundary_element_hit.bottom
@@ -355,7 +358,7 @@ class FlowElement:
355
358
  bottom=edge if direction == "below" else None,
356
359
  top=edge if direction == "above" else None,
357
360
  )
358
- else:
361
+ else: # direction in ["right", "left"]
359
362
  if direction == "right":
360
363
  edge = (
361
364
  boundary_element_hit.x1
@@ -381,7 +384,7 @@ class FlowElement:
381
384
  and size is not None
382
385
  ):
383
386
  current_part_consumed_size = 0.0
384
- if is_primary_vertical:
387
+ if direction in ["below", "above"]:
385
388
  current_part_consumed_size = segment_contribution.height
386
389
  if current_part_consumed_size > remaining_size:
387
390
  new_edge = (
@@ -394,7 +397,7 @@ class FlowElement:
394
397
  top=new_edge if not is_forward else None,
395
398
  )
396
399
  current_part_consumed_size = remaining_size
397
- else:
400
+ else: # direction in ["left", "right"]
398
401
  current_part_consumed_size = segment_contribution.width
399
402
  if current_part_consumed_size > remaining_size:
400
403
  new_edge = (
@@ -451,6 +454,7 @@ class FlowElement:
451
454
  width_absolute: Optional[float] = None,
452
455
  width_alignment: str = "center",
453
456
  until: Optional[str] = None,
457
+ include_source: bool = False,
454
458
  include_endpoint: bool = True,
455
459
  **kwargs,
456
460
  ) -> "FlowRegion": # Stringized
@@ -462,6 +466,7 @@ class FlowElement:
462
466
  cross_size_absolute=width_absolute,
463
467
  cross_alignment=width_alignment,
464
468
  until=until,
469
+ include_source=include_source,
465
470
  include_endpoint=include_endpoint,
466
471
  **kwargs,
467
472
  )
@@ -477,6 +482,7 @@ class FlowElement:
477
482
  width_absolute: Optional[float] = None,
478
483
  width_alignment: str = "center",
479
484
  until: Optional[str] = None,
485
+ include_source: bool = False,
480
486
  include_endpoint: bool = True,
481
487
  **kwargs,
482
488
  ) -> "FlowRegion": # Stringized
@@ -488,6 +494,7 @@ class FlowElement:
488
494
  cross_size_absolute=width_absolute,
489
495
  cross_alignment=width_alignment,
490
496
  until=until,
497
+ include_source=include_source,
491
498
  include_endpoint=include_endpoint,
492
499
  **kwargs,
493
500
  )
@@ -503,24 +510,21 @@ class FlowElement:
503
510
  height_absolute: Optional[float] = None,
504
511
  height_alignment: str = "center",
505
512
  until: Optional[str] = None,
513
+ include_source: bool = False,
506
514
  include_endpoint: bool = True,
507
515
  **kwargs,
508
516
  ) -> "FlowRegion": # Stringized
509
- if self.flow.arrangement == "horizontal":
510
- return self._flow_direction(
511
- direction="left",
512
- size=width,
513
- cross_size_ratio=height_ratio,
514
- cross_size_absolute=height_absolute,
515
- cross_alignment=height_alignment,
516
- until=until,
517
- include_endpoint=include_endpoint,
518
- **kwargs,
519
- )
520
- else:
521
- raise NotImplementedError(
522
- "'left' in a vertical flow is ambiguous with current 1D flow logic and not yet implemented."
523
- )
517
+ return self._flow_direction(
518
+ direction="left",
519
+ size=width,
520
+ cross_size_ratio=height_ratio,
521
+ cross_size_absolute=height_absolute,
522
+ cross_alignment=height_alignment,
523
+ until=until,
524
+ include_source=include_source,
525
+ include_endpoint=include_endpoint,
526
+ **kwargs,
527
+ )
524
528
 
525
529
  def right(
526
530
  self,
@@ -529,24 +533,21 @@ class FlowElement:
529
533
  height_absolute: Optional[float] = None,
530
534
  height_alignment: str = "center",
531
535
  until: Optional[str] = None,
536
+ include_source: bool = False,
532
537
  include_endpoint: bool = True,
533
538
  **kwargs,
534
539
  ) -> "FlowRegion": # Stringized
535
- if self.flow.arrangement == "horizontal":
536
- return self._flow_direction(
537
- direction="right",
538
- size=width,
539
- cross_size_ratio=height_ratio,
540
- cross_size_absolute=height_absolute,
541
- cross_alignment=height_alignment,
542
- until=until,
543
- include_endpoint=include_endpoint,
544
- **kwargs,
545
- )
546
- else:
547
- raise NotImplementedError(
548
- "'right' in a vertical flow is ambiguous with current 1D flow logic and not yet implemented."
549
- )
540
+ return self._flow_direction(
541
+ direction="right",
542
+ size=width,
543
+ cross_size_ratio=height_ratio,
544
+ cross_size_absolute=height_absolute,
545
+ cross_alignment=height_alignment,
546
+ until=until,
547
+ include_source=include_source,
548
+ include_endpoint=include_endpoint,
549
+ **kwargs,
550
+ )
550
551
 
551
552
  def __repr__(self) -> str:
552
553
  return f"<FlowElement for {self.physical_object.__class__.__name__} {self.bbox} in {self.flow}>"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: natural-pdf
3
- Version: 0.2.15
3
+ Version: 0.2.16
4
4
  Summary: A more intuitive interface for working with PDFs
5
5
  Author-email: Jonathan Soma <jonathan.soma@gmail.com>
6
6
  License-Expression: MIT
@@ -62,7 +62,7 @@ natural_pdf/extraction/mixin.py,sha256=dBcp96R8zMQqaRHiB8vpyad8GR89gv5RPXlr8Mt0a
62
62
  natural_pdf/extraction/result.py,sha256=PDaCCN2LQBbHsZy0_lrQ0ROeMsnmH1WRoXWOjk9M2o4,1825
63
63
  natural_pdf/flows/__init__.py,sha256=cUN4A8hTDLZSRr4PO2W_lR4z6hWpbNG8Seox-IIcrLU,277
64
64
  natural_pdf/flows/collections.py,sha256=ErkHWdX6W_y1SjkcA_bGM0uUYRGPWWpRkHip6LHpej0,25740
65
- natural_pdf/flows/element.py,sha256=T-9uXsIBe7mIim-mQQMep6Ja5dRfWaYIj8g1ak_Bv8c,24892
65
+ natural_pdf/flows/element.py,sha256=AWXGfAo0yhHTA5h0u4teXhRaV_z3McSPGOMFQaSdkJQ,24973
66
66
  natural_pdf/flows/flow.py,sha256=BuT3DBqNvLEqYle66-nZFO91i_1s98CAat28Dg-JjGU,86149
67
67
  natural_pdf/flows/region.py,sha256=r_cFtBlmPi7ADN3k8oYA1s_vyz8GeQLCnYcv58Zt5eM,52263
68
68
  natural_pdf/ocr/__init__.py,sha256=VY8hhvDPf7Gh2lB-d2QRmghLLyTy6ydxlgo1cS4dOSk,2482
@@ -108,7 +108,7 @@ natural_pdf/vision/similarity.py,sha256=HWmXDBNLSOlRWH-_1K3FVR7tSsRuMFqXZwrVhhg2
108
108
  natural_pdf/vision/template_matching.py,sha256=91XQt5tp-vmcMX_4b2Bz-YwIAlb-hc8E5ih_qAHQuCk,7145
109
109
  natural_pdf/widgets/__init__.py,sha256=QTVaUmsw__FCweFYZebwPssQxxUFUMd0wpm_cUbGZJY,181
110
110
  natural_pdf/widgets/viewer.py,sha256=KW3JogdR2TMg2ECUMYp8hwd060hfg8EsYBWxb5IEzBY,24942
111
- natural_pdf-0.2.15.dist-info/licenses/LICENSE,sha256=9zfwINwJlarbDmdh6iJV4QUG54QSJlSAUcnC1YiC_Ns,1074
111
+ natural_pdf-0.2.16.dist-info/licenses/LICENSE,sha256=9zfwINwJlarbDmdh6iJV4QUG54QSJlSAUcnC1YiC_Ns,1074
112
112
  optimization/memory_comparison.py,sha256=0i_foFSRmppj-fY069qjwH36s_zkx-1L2ASAAlepWzA,6541
113
113
  optimization/pdf_analyzer.py,sha256=HjrmTgu2qchxPeDckc5kjgxppGwd40UESrYS9Myj7pY,19352
114
114
  optimization/performance_analysis.py,sha256=JBXnR9hc7Ix7YCnt3EJPSpsyqIUgKsc7GEffQ_TDCBk,13033
@@ -145,8 +145,8 @@ tools/bad_pdf_eval/llm_enrich.py,sha256=mCh4KGi1HmIkzGjj5rrHz1Osd7sEX1IZ_FW08H1t
145
145
  tools/bad_pdf_eval/llm_enrich_with_retry.py,sha256=XUtPF1hUvqd3frDXT0wDTXoonuAivhjM5vgFdZ-tm0A,9373
146
146
  tools/bad_pdf_eval/reporter.py,sha256=e1g__mkSB4q02p3mGWOwMhvFs7F2HJosNBxup0-LkyU,400
147
147
  tools/bad_pdf_eval/utils.py,sha256=hR95XQ7qf7Cu6BdyX0L7ggGVx-ah5sK0jHWblTJUUic,4896
148
- natural_pdf-0.2.15.dist-info/METADATA,sha256=TfUHRd_THs6bk7Iwl8UdBjZfnWEXKg_tBiVn_Q9tv28,6960
149
- natural_pdf-0.2.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
150
- natural_pdf-0.2.15.dist-info/entry_points.txt,sha256=1R_KMv7g60UBBpRqGfw7bppsMNGdayR-iJlb9ohEk_8,81
151
- natural_pdf-0.2.15.dist-info/top_level.txt,sha256=ZDKhxE_tg508o9BpagsjCGcI8GY4cF_8bg0e0IaLsPI,41
152
- natural_pdf-0.2.15.dist-info/RECORD,,
148
+ natural_pdf-0.2.16.dist-info/METADATA,sha256=o2x-_hFHY64xJCCZM7CwEHo96vAU8XzFejobi1neE2g,6960
149
+ natural_pdf-0.2.16.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
150
+ natural_pdf-0.2.16.dist-info/entry_points.txt,sha256=1R_KMv7g60UBBpRqGfw7bppsMNGdayR-iJlb9ohEk_8,81
151
+ natural_pdf-0.2.16.dist-info/top_level.txt,sha256=ZDKhxE_tg508o9BpagsjCGcI8GY4cF_8bg0e0IaLsPI,41
152
+ natural_pdf-0.2.16.dist-info/RECORD,,